View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.common;
20  
21  import java.lang.reflect.Field;
22  import java.util.Collection;
23  import java.util.HashMap;
24  
25  import org.apache.logging.log4j.LogManager;
26  import org.jdom2.Namespace;
27  import org.jdom2.xpath.XPathFactory;
28  import org.mycore.common.config.MCRConfiguration2;
29  
30  /**
31   * This class replaces the deprecated MCRDefaults interface and provides some
32   * final static fields of common use.
33   * 
34   * @author Jens Kupferschmidt
35   * @author Thomas Scheffler (yagee)
36   * @author Stefan Freitag (sasf)
37   * @author Frank Lützenkirchen
38   * @version $Revision$ $Date: 2011-06-22 12:50:42 +0200 (Wed, 22 Jun
39   *          2011) $
40   */
41  public final class MCRConstants {
42  
43      /** MCR.Metadata.DefaultLang */
44      public static final String DEFAULT_LANG = "de";
45  
46      /** The default encoding */
47      public static final String DEFAULT_ENCODING = "UTF-8";
48  
49      public static final Namespace XML_NAMESPACE = Namespace.getNamespace("xml", "http://www.w3.org/XML/1998/namespace");
50  
51      public static final Namespace XLINK_NAMESPACE = Namespace.getNamespace("xlink", "http://www.w3.org/1999/xlink");
52  
53      /** the MARC 21 namespace */
54      public static final Namespace MARC21_NAMESPACE = Namespace.getNamespace("marc21", "http://www.loc.gov/MARC21/slim");
55  
56      /** MARC 21 namespace schema location */
57      public static final String MARC21_SCHEMA_LOCATION = "http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd";
58  
59      public static final XPathFactory XPATH_FACTORY = XPathFactory.instance();
60  
61      /** The URL of the XSI */
62      private static final String XSI_URL = "http://www.w3.org/2001/XMLSchema-instance";
63  
64      public static final Namespace XSI_NAMESPACE = Namespace.getNamespace("xsi", XSI_URL);
65  
66      /** The URL of the XSL */
67      private static final String XSL_URL = "http://www.w3.org/1999/XSL/Transform";
68  
69      public static final Namespace XSL_NAMESPACE = Namespace.getNamespace("xsl", XSL_URL);
70  
71      /** The URL of the METS */
72      private static final String METS_URL = "http://www.loc.gov/METS/";
73  
74      public static final Namespace METS_NAMESPACE = Namespace.getNamespace("mets", METS_URL);
75  
76      /** The URL of the DV */
77      private static final String DV_URL = "http://dfg-viewer.de/";
78  
79      public static final Namespace DV_NAMESPACE = Namespace.getNamespace("dv", DV_URL);
80  
81      /** The URL of the LIDO */
82      private static final String LIDO_URL = "http://www.lido-schema.org";
83  
84      public static final Namespace LIDO_NAMESPACE = Namespace.getNamespace("lido", LIDO_URL);
85  
86      /** The URL of the MODS */
87      private static final String MODS_URL = "http://www.loc.gov/mods/v3";
88  
89      public static final Namespace MODS_NAMESPACE = Namespace.getNamespace("mods", MODS_URL);
90  
91      public static final Namespace ZS_NAMESPACE = Namespace.getNamespace("zs", "http://www.loc.gov/zing/srw/");
92  
93      public static final Namespace ZR_NAMESPACE = Namespace.getNamespace("zr", "http://explain.z3950.org/dtd/2.0/");
94  
95      public static final Namespace SRW_NAMESPACE = Namespace.getNamespace("srw", "http://www.loc.gov/zing/srw/");
96  
97      public static final Namespace INFO_SRW_NAMESPACE = Namespace.getNamespace("info", "info:srw/schema/5/picaXML-v1.0");
98  
99      public static final Namespace PIDEF_NAMESPACE = Namespace.getNamespace("pidef", "http://nbn-resolving.org/pidef");
100 
101     public static final Namespace CROSSREF_NAMESPACE = Namespace.getNamespace("cr",
102         "http://www.crossref.org/schema/4.4.1");
103 
104     public static final Namespace DIAG_NAMESPACE = Namespace.getNamespace("diag",
105         "http://www.loc.gov/zing/srw/diagnostic");
106 
107     public static final Namespace EPICURLITE_NAMESPACE = Namespace.getNamespace("epicurlite",
108         "http://nbn-resolving.org/epicurlite");
109     
110     public static final Namespace ALTO_NAMESPACE = Namespace
111         .getNamespace("alto", "http://www.loc.gov/standards/alto/ns-v2#");
112     
113     public static final Namespace SKOS_NAMESPACE = Namespace
114         .getNamespace("skos", "http://www.w3.org/2004/02/skos/core#");
115     
116     public static final Namespace RDF_NAMESPACE = Namespace
117         .getNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
118 
119     /** The URL of the MCR */
120     private static final String MCR_URL = "http://www.mycore.org/";
121 
122     public static final Namespace MCR_NAMESPACE = Namespace.getNamespace("mcr", MCR_URL);
123 
124     private static final HashMap<String, Namespace> NAMESPACES_BY_PREFIX;
125 
126     static {
127         NAMESPACES_BY_PREFIX = new HashMap<>();
128 
129         Field[] fields = MCRConstants.class.getFields();
130         for (Field f : fields) {
131             if (f.getType() == Namespace.class) {
132                 try {
133                     Namespace namespace = (Namespace) f.get(null);
134                     registerNamespace(namespace);
135                 } catch (Exception e) {
136                     LogManager.getLogger(MCRConstants.class).error(
137                         "Error while initialising Namespace list and HashMap",
138                         e);
139                 }
140             }
141         }
142         MCRConfiguration2.getSubPropertiesMap("MCR.Namespace.")
143             .forEach(MCRConstants::registerNamespace);
144     }
145 
146     private static void registerNamespace(String prefix, String uri) {
147         registerNamespace(Namespace.getNamespace(prefix, uri));
148     }
149 
150     /**
151      * Adds and registers a standard namespace with prefix.
152      * Note that a default namespace without prefix will be ignored here!
153      */
154     public static void registerNamespace(Namespace namespace) {
155         String prefix = namespace.getPrefix();
156 
157         if ((prefix != null) && !prefix.isEmpty()) {
158             NAMESPACES_BY_PREFIX.put(prefix, namespace);
159         }
160     }
161 
162     /**
163      * Returns a list of standard namespaces used in MyCoRe. Additional
164      * namespaces can be configured using properties like
165      * MCR.Namespace.&lt;prefix&gt;=&lt;uri&gt;
166      */
167     public static Collection<Namespace> getStandardNamespaces() {
168         return NAMESPACES_BY_PREFIX.values();
169     }
170 
171     /**
172      * Returns the namespace with the given standard prefix. Additional
173      * namespaces can be configured using properties like
174      * MCR.Namespace.&lt;prefix&gt;=&lt;uri&gt;
175      */
176     public static Namespace getStandardNamespace(String prefix) {
177         return NAMESPACES_BY_PREFIX.get(prefix);
178     }
179 
180 }