DTDCatalog.java :  » Content-Management-System » contelligent » de » finix » contelligent » xml » Java Open Source

Java Open Source » Content Management System » contelligent 
contelligent » de » finix » contelligent » xml » DTDCatalog.java
/*
 * Copyright 2001-2006 C:1 Financial Services GmbH
 *
 * This software is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License Version 2.1, as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
 */

package de.finix.contelligent.xml;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.digester.Digester;

/**
 * Singleton which encapsulates the mapping between the public id of a DTD and
 * the URL to that DTD. The URL must be requested via an additional unique short
 * name which is set when {@link #addDTD adding} a new mapping. <BR>
 * For most DTDs used within the Contelligent system their exist string
 * constants containing the short name. For example to get the DTD for the XML
 * description of a component use
 * 
 * <PRE>
 * 
 * DTDCatalog.getInstance().getFileURL(DTDCatalog.COMPONENT);
 * 
 * </PRE>
 */
public class DTDCatalog {
    public static final String PUBLICID_URLPREFIX = "http://www.c1-fse.de/contelligent/dtds/";

    public static final String CONTELLIGENT_CONFIGURATION = "Contell Conf";

    public static final String CATEGORY_DEFINITION = "category-definition";// must

    // match
    // element
    // name!

    public static final String PACKAGE_DESCRIPTOR = "package"; // must match

    // element name!

    public static final String COMPONENT_LIST = "component-list"; // must

    // match
    // element
    // name!

    public static final String COMPONENT = "component";

    public static final String TYPE = "type"; // must match element name!

    public static final String TYPE_LIST = "type-list"; // must match element

    // name!

    public static final String ACL = "ACL";

    public static final String RESOURCE = "Resource";

    public static final String TYPE_METAINFO = "meta-info"; // must match

    // element name!

    public static final String DESCRIPTION = "description";

    public static final String PRINCIPAL_DATA = "principal-list"; // must

    // match
    // element
    // name!

    public static final String WORKFLOW_DEFINITION = "workflow";

    public static final String SEARCH_ENGINE = "search-engine";

    public static final String ERROR_MAPPING = "error-mapping";

    public static final String PROJECT_CONFIG = "project";

    final private static DTDCatalog instance = new DTDCatalog();

    final private Map publicIDs = new HashMap();

    final private Map dtds = new HashMap();

    final private Map realFileNames = new HashMap();

    final private Map pubIdToFileNames = new HashMap();

    public static DTDCatalog getInstance() {
        return instance;
    }

    /**
     * Creates new DTDCatalog
     * 
     * Note that {@link de.finix.contelligent.core.ContelligentImpl#copyDTDs}
     * overwrites the real file-URLs of all registered DTDs so they point to the
     * local copies of the DTDs.
     */
    private DTDCatalog() {

        addDTD(PACKAGE_DESCRIPTOR, "-//finix AG/contelligent/Package Import File V9.1/EN", "package-import_9_1.dtd");
        addDTD(TYPE, "-//finix AG/contelligent/Type Definition V1.0/EN", "type_1_0.dtd");
        addDTD(TYPE_LIST, "-//finix AG/contelligent/Type List V1.0/EN", "type-list_1_0.dtd");
        addDTD(COMPONENT, "-//finix AG/contelligent/Component Definition V9.1/EN", "component_9_1.dtd");
        addDTD(COMPONENT_LIST, "-//Finix AG/Contelligent/DTD component-list V9.1/EN", "component-list_9_1.dtd");
        addDTD(COMPONENT_LIST + "-1.0", "-//Finix AG/Contelligent/DTD component-list V1.0/EN", "component-list_9_1.dtd"); // Yes,
        // this
        // is
        // intentional
        // since
        // many pre-9.1 packages use the
        // wrong version number
        addDTD(CATEGORY_DEFINITION, "-//finix AG/contelligent/Category Definition V1.0/EN",
                "category-definition_1_0.dtd");
        addDTD(CONTELLIGENT_CONFIGURATION, "-//finix AG/contelligent/Contelligent Configuration V9.1/EN",
                "contelligent-configuration_9_1.dtd");
        addDTD(ACL, "-//finix AG/contelligent/Access Control List V9.1/EN", "acl_9_1.dtd");
        addDTD(RESOURCE, "-//finix AG/contelligent/Resource V1.0/EN", "resource_1_0.dtd");
        addDTD(TYPE_METAINFO, "-//finix AG/contelligent/Type Meta-Information V1.0/EN", "type-metainfo_1_0.dtd");
        addDTD(DESCRIPTION, "-//finix AG/contelligent/Description V1.0/EN", "description_1_0.dtd");
        addDTD(PRINCIPAL_DATA, "-//finix AG/contelligent/Principal Data V1.0/EN", "principaldata_1_0.dtd");
        addDTD(WORKFLOW_DEFINITION, "-//finix AG/contelligent/Workflow Definition V1.0/EN",
                "workflow-definition_1_0.dtd");
        addDTD(SEARCH_ENGINE, "-//finix AG/contelligent/Search Engine Configuration V1.1/EN", "searchengine_1_1.dtd");
        addDTD(ERROR_MAPPING, "-//finix AG/contelligent/Error-Mapping V1.0/EN", "error-mapping_1_0.dtd");
        addDTD(PROJECT_CONFIG, "-//finix AG/contelligent/Project Configuration V1.2/EN", "project_1_2.dtd");
        addDeprecatedDTDs();
    }

    private void addDeprecatedDTDs() {
        addDTD(PACKAGE_DESCRIPTOR + "-1.0", "-//finix AG/contelligent/Package Import File V1.0/EN",
                "package-import_1_0.dtd");
        addDTD(PACKAGE_DESCRIPTOR + "-1.1", "-//finix AG/contelligent/Package Import File V1.1/EN",
                "package-import_1_1.dtd");
        addDTD(PACKAGE_DESCRIPTOR + "-depr", "-//finix AG/contelligent/Package Import File/EN",
                "package-import_1_0.dtd");
        addDTD(TYPE + "-depr", "-//finix AG/contelligent/Type Definition/EN", "type.dtd");
        addDTD(TYPE_LIST + "-depr", "-//finix AG/contelligent/Type List/EN", "type-list.dtd");
        addDTD(COMPONENT + "-depr", "-//finix AG/contelligent/Component Definition/EN", "component.dtd");
        addDTD(COMPONENT_LIST + "-depr", "-//Finix AG/Contelligent/DTD component-list 1.0/EN", "component-list.dtd");
        addDTD(CATEGORY_DEFINITION + "-depr", "-//finix AG/contelligent/Category Definition/EN",
                "category-definition.dtd");
        addDTD(CONTELLIGENT_CONFIGURATION + "-depr", "-//finix AG/contelligent/Contelligent Configuration/EN",
                "contelligent-configuration.dtd");
        addDTD(ACL + "-1.0", "-//finix AG/contelligent/Access Control List V1.0/EN", "acl_1_0.dtd");
        addDTD(ACL + "-depr", "-//finix AG/contelligent/Access Control List/EN", "acl.dtd");
        addDTD(RESOURCE + "-depr", "-//finix AG/contelligent/Resource/EN", "resource.dtd");
        addDTD(TYPE_METAINFO + "-depr", "-//finix AG/contelligent/Type Meta-Information/EN", "type-metainfo.dtd");
        addDTD(DESCRIPTION + "-depr", "-//finix AG/contelligent/Description/EN", "description.dtd");
        addDTD(PRINCIPAL_DATA + "-depr", "-//finix AG/contelligent/Principal Data/EN", "principaldata.dtd");
        addDTD(WORKFLOW_DEFINITION + "-depr", "-//finix AG/contelligent/Workflow Definition/EN",
                "workflow-definition.dtd");
        addDTD(SEARCH_ENGINE + "-depr", "-//finix AG/contelligent/Search Engine Configuration V1.0/EN",
                "searchengine_1_0.dtd");
        addDTD(SEARCH_ENGINE + "-1.0", "-//finix AG/contelligent/Search Engine Configuration/EN", "searchengine.dtd");
        addDTD(ERROR_MAPPING + "-depr", "-//finix AG/contelligent/Error-Mapping/EN", "error-mapping.dtd");
        addDTD(PROJECT_CONFIG + "-1.1", "-//finix AG/contelligent/Project Configuration V1.1/EN", "project_1_1.dtd");
        addDTD(PROJECT_CONFIG + "-1.0", "-//finix AG/contelligent/Project Configuration V1.0/EN", "project_1_0.dtd");
        addDTD(PROJECT_CONFIG + "-depr", "-//finix AG/contelligent/Project Configuration/EN", "project.dtd");
    }

    public void registerAllDTDsWithDigester(Digester digester) {
        Iterator i = pubIdToFileNames.entrySet().iterator();

        while (i.hasNext()) {
            Map.Entry entry = (Map.Entry) i.next();
            digester.register((String) entry.getKey(), (String) entry.getValue());
        }

    }

    public String getPublicId(String name) {
        return (String) publicIDs.get(name);
    }

    public String getFileName(String name) {
        return (String) dtds.get(name);
    }

    public String getFileURL(String name) {
        return (String) realFileNames.get(name);
    }

    public void setFileURL(String name, String fileName) {
        realFileNames.put(name, fileName);
        Object pubId = publicIDs.get(name);
        pubIdToFileNames.put(pubId, fileName);
    }

    public Map getFileNameMap() {
        return new HashMap(dtds);
    }

    public Map getPublicIdFileNames() {
        return new HashMap(pubIdToFileNames);
    }

    public void addDTD(String name, String publicId, String dtd) {
        addDTD(name, publicId, dtd, dtd);
    }

    public void addDTD(String name, String publicId, String dtd, String realFileName) {
        publicIDs.put(name, publicId);
        dtds.put(name, dtd);
        realFileNames.put(name, realFileName);
        pubIdToFileNames.put(publicId, realFileName);
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.