All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ORG.oclc.oai.server.verb.Identify Maven / Gradle / Ivy

/**
 * Copyright 2006 OCLC Online Computer Library Center Licensed under the Apache
 * License, Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
 * agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ORG.oclc.oai.server.verb;

import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpUtils;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;

import ORG.oclc.oai.server.catalog.AbstractCatalog;
//import org.xml.sax.SAXException;

/**
 * This class represents an Identify response on either the server or
 * on the client
 *
 * @author Jeffrey A. Young, OCLC Online Computer Library Center
 */
public class Identify extends ServerVerb {
    private static ArrayList validParamNames = new ArrayList();
    static {
        validParamNames.add("verb");
    }
    
    /**
     * Construct the xml response on the server side.
     *
     * @param context the servlet context
     * @param request the servlet request
     * @return a String containing the xml response
     */
    public static String construct(HashMap context,
            HttpServletRequest request,
            HttpServletResponse response,
            Transformer serverTransformer)
    throws TransformerException {
        String version = (String)context.get("OAIHandler.version");
        AbstractCatalog abstractCatalog =
            (AbstractCatalog)context.get("OAIHandler.catalog");
        Properties properties =
            (Properties)context.get("OAIHandler.properties");
        String baseURL = properties.getProperty("OAIHandler.baseURL");
        if (baseURL == null) {
            try {
                baseURL = request.getRequestURL().toString();
            } catch (java.lang.NoSuchMethodError f) {
                baseURL = HttpUtils.getRequestURL(request).toString();
            }
        }
        StringBuffer sb = new StringBuffer();
        sb.append("");
        String styleSheet = properties.getProperty("OAIHandler.styleSheet");
        if (styleSheet != null) {
            sb.append("");
        }
        sb.append("");
        sb.append("");
        sb.append(createResponseDate(new Date()));
        sb.append("");
//      sb.append("");
//      sb.append(getRequestURL(request));
//      sb.append("");
        sb.append(getRequestElement(request, validParamNames, baseURL));
        if (hasBadArguments(request, validParamNames.iterator(), validParamNames)) {
            sb.append(new BadArgumentException().getMessage());
        } else {
            sb.append("");
            sb.append("");
            sb.append(properties.getProperty("Identify.repositoryName",
            "undefined"));
            sb.append("");
            sb.append("");
            sb.append(baseURL);
            sb.append("");
            sb.append("2.0");
            sb.append("");
            sb.append(properties.getProperty("Identify.adminEmail", "undefined"));
            sb.append("");
            sb.append("");
            sb.append(properties.getProperty("Identify.earliestDatestamp", "undefined"));
            sb.append("");
            sb.append("");
            sb.append(properties.getProperty("Identify.deletedRecord", "undefined"));
            sb.append("");
            String granularity = properties.getProperty("AbstractCatalog.granularity");
            if (granularity != null) {
                sb.append("");
                sb.append(granularity);
                sb.append("");
            }
            // 	String compression = properties.getProperty("Identify.compression");
            // 	if (compression != null) {
            sb.append("gzip");
//          sb.append("compress");
            sb.append("deflate");
            // 	}
            String repositoryIdentifier = properties.getProperty("Identify.repositoryIdentifier");
            String sampleIdentifier = properties.getProperty("Identify.sampleIdentifier");
            if (repositoryIdentifier != null && sampleIdentifier != null) {
                sb.append("");
                sb.append("");
                sb.append("oai");
                sb.append("");
                sb.append(repositoryIdentifier);
                sb.append("");
                sb.append(":");
                sb.append("");
                sb.append(sampleIdentifier);
                sb.append("");
                sb.append("");
                sb.append("");
            }
            String propertyPrefix = "Identify.description";
            Enumeration propNames = properties.propertyNames();
            while (propNames.hasMoreElements()) {
                String propertyName = (String)propNames.nextElement();
                if (propertyName.startsWith(propertyPrefix)) {
                    sb.append((String)properties.get(propertyName));
                    sb.append("\n");
                }
            }
            sb.append("OCLC's OAICat Repository FrameworkJeffrey A. Young[email protected]OCLC");
            sb.append(version);
            sb.append("http://alcme.oclc.org/oaicat/oaicat_icon.gifhttp://www.oclc.org/research/software/oai/cat.shtm");
            String descriptions = abstractCatalog.getDescriptions();
            if (descriptions != null) {
                sb.append(descriptions);
            }
            sb.append("");
        }
        sb.append("");
        return render(response, "text/xml; charset=UTF-8", sb.toString(), serverTransformer);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy