You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2012/10/15 11:16:21 UTC
svn commit: r1398227 - in
/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml: ./
Namespaces.java package-info.java
Author: desruisseaux
Date: Mon Oct 15 09:16:21 2012
New Revision: 1398227
URL: http://svn.apache.org/viewvc?rev=1398227&view=rev
Log:
Initial commit of XML package. For now, contains only the declaration of XML namespaces.
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java (with props)
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/package-info.java (with props)
Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java?rev=1398227&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java Mon Oct 15 09:16:21 2012
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.sis.xml;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Locale;
+import javax.xml.XMLConstants;
+
+import org.apache.sis.util.Static;
+
+
+/**
+ * List some name spaces URLs used by JAXB when (un)marshalling.
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @author Quentin Boileau (Geomatys)
+ * @since 0.3 (derived from geotk-3.00)
+ * @version 0.3
+ * @module
+ */
+public final class Namespaces extends Static {
+ /**
+ * Do not allow instantiation of this class.
+ */
+ private Namespaces() {
+ }
+
+ /**
+ * The <code>{@value}</code> URL.
+ *
+ * @category ISO
+ */
+ public static final String GCO = "http://www.isotc211.org/2005/gco";
+
+ /**
+ * The <code>{@value}</code> URL.
+ *
+ * @category ISO
+ */
+ public static final String GFC = "http://www.isotc211.org/2005/gfc";
+
+ /**
+ * The <code>{@value}</code> URL.
+ *
+ * @category ISO
+ */
+ public static final String GMD = "http://www.isotc211.org/2005/gmd";
+
+ /**
+ * The <code>{@value}</code> URL.
+ *
+ * @category ISO
+ */
+ public static final String GMI = "http://www.isotc211.org/2005/gmi";
+
+ /**
+ * The <code>{@value}</code> URL.
+ *
+ * @category ISO
+ */
+ public static final String GMX = "http://www.isotc211.org/2005/gmx";
+
+ /**
+ * The <code>{@value}</code> URL.
+ *
+ * @category OGC
+ */
+ public static final String GML = "http://www.opengis.net/gml";
+
+ /**
+ * The <code>{@value}</code> URL.
+ *
+ * @category OGC
+ */
+ public static final String CSW_202 = "http://www.opengis.net/cat/csw/2.0.2";
+
+ /**
+ * The <code>{@value}</code> URL.
+ * This is also defined by {@link XMLConstants#W3C_XML_SCHEMA_INSTANCE_NS_URI}.
+ *
+ * @category W3C
+ * @see XMLConstants#W3C_XML_SCHEMA_INSTANCE_NS_URI
+ */
+ public static final String XSI = XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
+
+ /**
+ * The <code>{@value}</code> URL.
+ *
+ * @category W3C
+ */
+ public static final String XLINK = "http://www.w3.org/1999/xlink";
+
+ /**
+ * The <code>{@value}</code> URL.
+ *
+ * @category Profiles
+ */
+ public static final String FRA = "http://www.cnig.gouv.fr/2005/fra";
+
+ /**
+ * URLs for which the prefix to use directly follows them.
+ */
+ private static final String[] GENERIC_URLS = {
+ "http://www.isotc211.org/2005/",
+ "http://www.opengis.net/",
+ "http://www.w3.org/1999/",
+ "http://www.cnig.gouv.fr/2005/",
+ "http://purl.org/"
+ };
+
+ /**
+ * A map of (<var>URLs</var>, <var>prefix</var>). Stores URLs for which
+ * the prefix to use can not be easily inferred from the URL itself.
+ */
+ private static final Map<String,String> SPECIFIC_URLS;
+ static {
+ final Map<String,String> p = new HashMap<>(40);
+ p.put(XMLConstants.W3C_XML_SCHEMA_NS_URI, "xsd");
+ p.put(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi");
+ p.put("http://www.w3.org/2004/02/skos/core#", "skos");
+ p.put("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
+ p.put("http://www.w3.org/1998/Math/MathML", "mml");
+ p.put("http://www.opengis.net/sensorML/1.0", "sml1");
+ p.put("http://www.opengis.net/sensorML/1.0.1", "sml");
+ p.put("http://www.opengis.net/swe/1.0", "swe1");
+ p.put("http://www.opengis.net/cat/csw/2.0.2", "csw");
+ p.put("http://www.opengis.net/cat/wrs/1.0", "wrs");
+ p.put("http://www.opengis.net/cat/wrs", "wrs09");
+ p.put("http://www.opengis.net/ows-6/utds/0.3", "utds");
+ p.put("http://www.opengis.net/citygml/1.0", "core");
+ p.put("http://www.opengis.net/citygml/building/1.0", "build");
+ p.put("http://www.opengis.net/citygml/cityfurniture/1.0", "furniture");
+ p.put("http://www.opengis.net/citygml/transportation/1.0", "tr");
+ p.put("http://www.purl.org/dc/elements/1.1/", "dc2");
+ p.put("http://www.purl.org/dc/terms/", "dct2");
+ p.put("http://purl.org/dc/terms/", "dct");
+ p.put("http://www.inspire.org", "ins");
+ p.put("http://inspira.europa.eu/networkservice/view/1.0", "inspire_vs");
+ p.put("urn:oasis:names:tc:ciq:xsdschema:xAL:2.0", "xal");
+ p.put("urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", "rim");
+ p.put("urn:oasis:names:tc:ebxml-regrep:rim:xsd:2.5", "rim25");
+ p.put("urn:oasis:names:tc:xacml:2.0:context:schema:os", "xacml-context");
+ p.put("urn:oasis:names:tc:xacml:2.0:policy:schema:os", "xacml-policy");
+ p.put("urn:us:gov:ic:ism:v2", "icism");
+ SPECIFIC_URLS = p;
+ }
+
+ /**
+ * Returns the preferred prefix for the given name space URI.
+ *
+ * @param namespace The name space URI for which the prefix needs to be found. Can not be {@code null}.
+ * @param suggestion The suggested prefix, returned if the given name space is not recognized.
+ * @return The prefix inferred from the name space URI.
+ */
+ public static String getPreferredPrefix(String namespace, final String suggestion) {
+ String prefix = SPECIFIC_URLS.get(namespace);
+ if (prefix != null) {
+ return prefix;
+ }
+ namespace = namespace.toLowerCase(Locale.US);
+ for (final String baseURL : GENERIC_URLS) {
+ if (namespace.startsWith(baseURL)) {
+ final int startAt = baseURL.length();
+ final int endAt = namespace.indexOf('/', startAt);
+ if (endAt >= 0) {
+ prefix = namespace.substring(startAt, endAt);
+ } else {
+ prefix = namespace.substring(startAt);
+ }
+ return prefix;
+ }
+ }
+ return suggestion;
+ }
+}
Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/package-info.java?rev=1398227&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/package-info.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/package-info.java Mon Oct 15 09:16:21 2012
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+/**
+ * Provides methods for marshalling and unmarshalling SIS objects in XML.
+ * The XML format is compliant with ISO 19139 specification for metadata, and
+ * compliant with GML for referencing objects.
+ *
+ * <p>The main class in this package is {@link org.apache.sis.xml.XML}, which provides
+ * property keys that can be used for configuring (un)marshallers and convenience
+ * static methods. For example the following code:</p>
+ *
+ * {@preformat java
+ * XML.marshal(Citations.OGC, System.out);
+ * }
+ *
+ * will produce a string like below:
+ *
+ * {@preformat xml
+ * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+ * <gmd:CI_Citation xmlns:gmd="http://www.isotc211.org/2005/gmd"
+ * xmlns:gco="http://www.isotc211.org/2005/gco">
+ * <gmd:title>
+ * <gco:CharacterString>Open Geospatial Consortium</gco:CharacterString>
+ * </gmd:title>
+ * ... much more XML below this point ...
+ * </gmd:CI_Citation>
+ * }
+ *
+ * {@section Customizing the XML}
+ * In order to parse and format ISO 19139 compliant documents, SIS needs its own
+ * {@link javax.xml.bind.Marshaller}Â and {@link javax.xml.bind.Unmarshaller} instances
+ * (which are actually wrappers around standard instances). Those instances are created
+ * and cached by {@link org.apache.sis.xml.MarshallerPool}, which is used internally by
+ * the above-cited {@code XML} class. However developers can instantiate their own
+ * {@code MarshallerPool} in order to get more control on the marshalling and unmarshalling
+ * processes, including the namespace URLs and the errors handling.
+ *
+ * <p>The most common namespace URLs are defined in the {@link org.apache.sis.xml.Namespaces} class.
+ * The parsing of some objects like {@link java.net.URL} and {@link java.util.UUID},
+ * together with the behavior in case of parsing error, can be specified by the
+ * {@link org.apache.sis.xml.ObjectConverters} class.</p>
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @author Guilhem Legal (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-3.00)
+ * @version 0.3
+ * @module
+ */
+package org.apache.sis.xml;
Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/xml/package-info.java
------------------------------------------------------------------------------
svn:mime-type = text/plain