jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r418750 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml: AbstractSAXEventGenerator.java DocViewSAXEventGenerator.java SysViewSAXEventGenerator.java
Date Mon, 03 Jul 2006 11:57:44 GMT
Author: jukka
Date: Mon Jul  3 04:57:40 2006
New Revision: 418750

URL: http://svn.apache.org/viewvc?rev=418750&view=rev
Log:
JCR-367: Explicit xmlns:prefix="namespace" attributes in XML exports.

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/DocViewSAXEventGenerator.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java?rev=418750&r1=418749&r2=418750&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
Mon Jul  3 04:57:40 2006
@@ -24,6 +24,7 @@
 import org.slf4j.LoggerFactory;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
 
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
@@ -189,6 +190,34 @@
                 continue;
             }
             contentHandler.endPrefixMapping(prefix);
+        }
+    }
+
+    /**
+     * Adds explicit <code>xmlns:prefix="uri"</code> attributes to the
+     * XML top-level element. The effect is the same as setting the
+     * "<code>http://xml.org/sax/features/namespace-prefixes</code>"
+     * property on an SAX parser.
+     *
+     * @param level level of the current XML element
+     * @param attributes attributes of the current XML element
+     * @throws RepositoryException on a repository error
+     */
+    protected void addNamespacePrefixes(int level, AttributesImpl attributes)
+            throws RepositoryException {
+        if (level == 0) {
+            String[] prefixes = session.getNamespacePrefixes();
+            for (int i = 0; i < prefixes.length; i++) {
+                if (prefixes[i].length() > 0
+                        && !QName.NS_XML_PREFIX.equals(prefixes[i])) {
+                    attributes.addAttribute(
+                            QName.NS_XMLNS_URI,
+                            prefixes[i],
+                            QName.NS_XMLNS_PREFIX + ":" + prefixes[i],
+                            "CDATA",
+                            session.getNamespaceURI(prefixes[i]));
+                }
+            }
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/DocViewSAXEventGenerator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/DocViewSAXEventGenerator.java?rev=418750&r1=418749&r2=418750&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/DocViewSAXEventGenerator.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/DocViewSAXEventGenerator.java
Mon Jul  3 04:57:40 2006
@@ -132,6 +132,7 @@
 
             // attributes (properties)
             AttributesImpl attrs = new AttributesImpl();
+            addNamespacePrefixes(level, attrs);
             Iterator iter = props.iterator();
             while (iter.hasNext()) {
                 Property prop = (Property) iter.next();
@@ -168,6 +169,7 @@
                             attrValue.toString());
                 }
             }
+
             // start element (node)
             QName qName = getQName(elemName);
             contentHandler.startElement(qName.getNamespaceURI(),

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java?rev=418750&r1=418749&r2=418750&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java
Mon Jul  3 04:57:40 2006
@@ -86,6 +86,7 @@
     protected void entering(Node node, int level)
             throws RepositoryException, SAXException {
         AttributesImpl attrs = new AttributesImpl();
+        addNamespacePrefixes(level, attrs);
         // name attribute
         String nodeName;
         if (node.getDepth() == 0) {



Mime
View raw message