You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2004/10/15 18:57:13 UTC
svn commit: rev 54856 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: . xml
Author: stefan
Date: Fri Oct 15 09:57:12 2004
New Revision: 54856
Modified:
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/ImportHandler.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
Log:
fixed problem with 'xml:space', 'xml:lang' etc. attributes when importing xml document
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java Fri Oct 15 09:57:12 2004
@@ -197,6 +197,25 @@
}
}
+ /**
+ * Returns a prefix that is unique among the already registered prefixes.
+ * @param uriHint namespace uri that serves as hint for the prefix generation
+ * @return a unique prefix
+ */
+ public String getUniquePrefix(String uriHint) {
+ // @todo smarter prefix generation
+/*
+ int number;
+ if (uriHint == null || uriHint.length() == 0) {
+ number = prefixToURI.size() + 1;
+ } else {
+ number = uriHint.hashCode();
+ }
+ return "_pre" + number;
+*/
+ return "_pre" + (prefixToURI.size() + 1);
+ }
+
//----------------------------------------------------< NamespaceRegistry >
/**
* @see NamespaceRegistry#registerNamespace
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java Fri Oct 15 09:57:12 2004
@@ -51,7 +51,7 @@
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
try {
QName nodeName;
- if (qName == null || "".equals(qName)) {
+ if (namespaceURI != null && !"".equals(namespaceURI)) {
nodeName = new QName(namespaceURI, localName);
} else {
try {
@@ -70,8 +70,13 @@
// properties
for (int i = 0; i < atts.getLength(); i++) {
+ if (atts.getQName(i).startsWith("xml:")) {
+ // skipping xml:space, xml:lang, etc.
+ log.debug("skipping reserved/system attribute " + atts.getQName(i));
+ continue;
+ }
QName propName;
- if (atts.getQName(i) == null || "".equals(atts.getQName(i))) {
+ if (atts.getURI(i) != null && !"".equals(atts.getURI(i))) {
propName = new QName(atts.getURI(i), atts.getLocalName(i));
} else {
try {
@@ -94,9 +99,13 @@
* @see ContentHandler#characters(char[], int, int)
*/
public void characters(char[] ch, int start, int length) throws SAXException {
- // character data in document view:
- // store as jcr:xmlcharacters property of jcr:xmltext node
- // (need to store as node in order to maintain ordering)
+ /**
+ * character data in document view:
+ * store as jcr:xmlcharacters property of jcr:xmltext node
+ * (need to store as node in order to maintain ordering)
+ *
+ * todo merge contiguous character data into one jcr:xmltext node
+ */
try {
NodeImpl currentParent = (NodeImpl) parents.peek();
NodeImpl txtNode = (NodeImpl) currentParent.addNode(DocViewSAXEventGenerator.NODENAME_XMLTEXT);
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/ImportHandler.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/ImportHandler.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/ImportHandler.java Fri Oct 15 09:57:12 2004
@@ -1,6 +1,6 @@
/*
* Copyright 2004 The Apache Software Foundation.
- *
+ *
* 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
@@ -99,9 +99,11 @@
try {
String oldPrefix = session.getNamespacePrefix(uri);
// namespace is already registered; check prefix
- if (!oldPrefix.equals(prefix)) {
- // namespace is mapped to different prefix;
- // try to remap it to given prefix
+ if (!"".equals(prefix) && !oldPrefix.equals(prefix)) {
+ /**
+ * namespace is mapped to different prefix;
+ * try to remap it to given prefix
+ */
try {
session.setNamespacePrefix(prefix, uri);
} catch (RepositoryException re) {
@@ -110,6 +112,14 @@
}
} catch (NamespaceException nse) {
// namespace is not yet registered, try to register it
+ if ("".equals(prefix)) {
+ /**
+ * the xml document specifies a default namespace (i.e. an empty prefix);
+ * we need to create a random prefix as the empty prefix is reserved
+ * according to the JCR spec.
+ */
+ prefix = nsReg.getUniquePrefix(uri);
+ }
try {
nsReg.registerNamespace(prefix, uri);
} catch (RepositoryException re) {
@@ -126,7 +136,7 @@
// the namespace of the first element determines the type of XML
// (system view/document view)
String nsURI;
- if (qName == null || "".equals(qName)) {
+ if (namespaceURI != null && !"".equals(namespaceURI)) {
nsURI = namespaceURI;
} else {
try {
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java Fri Oct 15 09:57:12 2004
@@ -73,7 +73,7 @@
try {
String elemName;
String nsURI;
- if (qName == null || "".equals(qName)) {
+ if (namespaceURI != null && !"".equals(namespaceURI)) {
nsURI = namespaceURI;
elemName = localName;
} else {
@@ -183,7 +183,7 @@
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
try {
String elemName;
- if (qName == null || "".equals(qName)) {
+ if (localName != null && !"".equals(localName)) {
elemName = localName;
} else {
try {