Author: rhauch
Date: 2009-03-10 12:37:29 -0400 (Tue, 10 Mar 2009)
New Revision: 767
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSystemViewExporter.java
Log:
DNA-295 TCK Tests for Session.export* Methods Fail
Applied the "cache" patch that streamlined the conversion of DNA Name objects to
strings containing the prefixed form of the Name.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java 2009-03-10
16:19:07 UTC (rev 766)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java 2009-03-10
16:37:29 UTC (rev 767)
@@ -74,6 +74,11 @@
private final Collection<String> restrictedPrefixes;
/**
+ * Cache from {@link Name}s to their rewritten version based on session uri
mappings.
+ */
+ private final Map<Name, String> prefixedNames;
+
+ /**
* Creates the exporter
*
* @param session the session in which the exporter is created
@@ -83,9 +88,37 @@
Collection<String> restrictedPrefixes ) {
this.session = session;
this.restrictedPrefixes = restrictedPrefixes;
+ this.prefixedNames = new HashMap<Name, String>();
}
/**
+ * Returns the "prefixed" or rewritten version of
<code>baseName</code> based on the URI mappings in the current
+ * session. For example:</p> If the namespace
"http://www.example.com/JCR/example/1.0" is mapped to the prefix
+ * "foo" in the current session (or as a persistent mapping that
has not been re-mapped in the current session),
+ * this method will return the string "foo:bar" when passed a
{@link Name} with uri
+ * "http://www.example.com/JCR/example/1.0" and local name
"bar".</p> This method does manage and utilize
+ * a {@link Name} to {@link String} cache at the instance scope.
+ *
+ * @param baseName the name to be re-mapped into its prefixed version
+ * @return the prefixed version of <code>baseName</code> based on the
current session URI mappings (which include all
+ * persistent URI mappings by default).
+ * @see #prefixedNames
+ * @see javax.jcr.Session#setNamespacePrefix(String, String)
+ * @see javax.jcr.Session#getNamespacePrefix(String)
+ */
+ protected String getPrefixedName( Name baseName ) {
+ String prefixedName = prefixedNames.get(baseName);
+
+ if (prefixedName == null) {
+ prefixedName =
baseName.getString(session.getExecutionContext().getNamespaceRegistry());
+
+ prefixedNames.put(baseName, prefixedName);
+ }
+
+ return prefixedName;
+ }
+
+ /**
* Exports <code>node</code> (or the subtree rooted at
<code>node</code>) into an XML document by invoking SAX events on
* <code>contentHandler</code>.
*
@@ -188,7 +221,7 @@
Attributes atts ) throws SAXException {
contentHandler.startElement(name.getNamespaceUri(),
NAME_ENCODER.encode(name.getLocalName()),
-
NAME_ENCODER.encode(name.getString(session.getExecutionContext().getNamespaceRegistry())),
+ NAME_ENCODER.encode(getPrefixedName(name)),
atts);
}
@@ -204,7 +237,7 @@
Name name ) throws SAXException {
contentHandler.endElement(name.getNamespaceUri(),
NAME_ENCODER.encode(name.getLocalName()),
-
NAME_ENCODER.encode(name.getString(session.getExecutionContext().getNamespaceRegistry())));
+ NAME_ENCODER.encode(getPrefixedName(name)));
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java 2009-03-10
16:19:07 UTC (rev 766)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java 2009-03-10
16:37:29 UTC (rev 767)
@@ -139,7 +139,7 @@
/* Name of node type that holds xmltext from document view import (see JCR 1.0
spec section 7.3.2) */
JcrNodeType xmlText = new JcrNodeType(
session,
- DnaLexicon.XML_TEXT_TYPE,
+ DnaLexicon.XML_TEXT,
Arrays.asList(new NodeType[] {base}),
NO_PRIMARY_ITEM_NAME,
NO_CHILD_NODES,
@@ -166,13 +166,13 @@
Arrays.asList(new JcrNodeDefinition[]
{new JcrNodeDefinition(
session,
null,
-
DnaLexicon.XML_TEXT,
+
JcrLexicon.XMLTEXT,
OnParentVersionBehavior.VERSION.getJcrValue(),
false,
true,
false,
false,
-
DnaLexicon.XML_TEXT_TYPE,
+
DnaLexicon.XML_TEXT,
new NodeType[] {xmlText})}),
NO_PROPERTIES, IS_A_MIXIN,
UNORDERABLE_CHILD_NODES);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-03-10 16:19:07 UTC
(rev 766)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-03-10 16:37:29 UTC
(rev 767)
@@ -40,8 +40,8 @@
/**
* Mixin type that indicates the node contains an xmltext node which holds xmltext
from document view import (see JCR 1.0
- * specification section 7.3.2). This node has a child node named {@link
DnaLexicon#XML_TEXT} of type
- * {@link DnaLexicon#XML_TEXT_TYPE}.
+ * specification section 7.3.2). This node has a child node named {@link
JcrLexicon#XMLTEXT} of type
+ * {@link DnaLexicon#XML_TEXT}.
*/
public static final Name XML_CONTENT = new BasicName(Namespace.URI,
"xmlContent");
@@ -49,12 +49,6 @@
* Name of node type that holds xmltext from document view import (see JCR 1.0
specification section 7.3.2). It is defined in
* the node type named {@link DnaLexicon#XML_CONTENT}.
*/
- public static final Name XML_TEXT_TYPE = new BasicName(Namespace.URI,
"xmlText");
+ public static final Name XML_TEXT = new BasicName(Namespace.URI,
"xmlText");
- /**
- * Name of the child node that holds xmltext from document view import (see JCR 1.0
specification section 7.3.2). This is the
- * name of the child node of the {@link DnaLexicon#XML_CONTENT} mixin type. By
definition, this node has a required primary
- * type of {@link DnaLexicon#XML_TEXT_TYPE}.
- */
- public static final Name XML_TEXT = new BasicName(Namespace.URI,
"xmltext");
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java 2009-03-10
16:19:07 UTC (rev 766)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java 2009-03-10
16:37:29 UTC (rev 767)
@@ -97,7 +97,7 @@
Name propName = ((AbstractJcrProperty)prop).getDnaProperty().getName();
- String localPropName =
propName.getString(executionContext.getNamespaceRegistry());
+ String localPropName = getPrefixedName(propName);
Value value;
if (prop instanceof JcrSingleValueProperty) {
@@ -151,8 +151,7 @@
private boolean isXmlTextNode( Node node ) throws RepositoryException {
// ./xmltext/xmlcharacters exception (see JSR-170 Spec 6.4.2.3)
- ExecutionContext executionContext = session.getExecutionContext();
- if
(JcrLexicon.XMLTEXT.getString(executionContext.getNamespaceRegistry()).equals(node.getName()))
{
+ if (getPrefixedName(JcrLexicon.XMLTEXT).equals(node.getName())) {
if (node.getNodes().getSize() == 0) {
PropertyIterator properties = node.getProperties();
@@ -161,11 +160,11 @@
while (properties.hasNext()) {
Property property = properties.nextProperty();
- if
(JcrLexicon.PRIMARY_TYPE.getString(executionContext.getNamespaceRegistry()).equals(property.getName()))
{
+ if
(getPrefixedName(JcrLexicon.PRIMARY_TYPE).equals(property.getName())) {
continue;
}
- if
(JcrLexicon.XMLCHARACTERS.getString(executionContext.getNamespaceRegistry()).equals(property.getName()))
{
+ if
(getPrefixedName(JcrLexicon.XMLCHARACTERS).equals(property.getName())) {
xmlCharactersFound = true;
continue;
}
@@ -195,8 +194,7 @@
assert isXmlTextNode(node);
- ExecutionContext executionContext = session.getExecutionContext();
- Property xmlCharacters =
node.getProperty(JcrLexicon.XMLCHARACTERS.getString(executionContext.getNamespaceRegistry()));
+ Property xmlCharacters =
node.getProperty(getPrefixedName(JcrLexicon.XMLCHARACTERS));
assert xmlCharacters != null;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSystemViewExporter.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSystemViewExporter.java 2009-03-10
16:19:07 UTC (rev 766)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSystemViewExporter.java 2009-03-10
16:37:29 UTC (rev 767)
@@ -15,7 +15,6 @@
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.Base64;
import org.jboss.dna.common.xml.XmlCharacters;
-import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.property.Name;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -65,13 +64,12 @@
ContentHandler contentHandler,
boolean skipBinary,
boolean noRecurse ) throws RepositoryException, SAXException
{
- ExecutionContext executionContext = session.getExecutionContext();
// start the sv:node element for this JCR node
AttributesImpl atts = new AttributesImpl();
atts.addAttribute(JcrSvLexicon.NAME.getNamespaceUri(),
JcrSvLexicon.NAME.getLocalName(),
-
JcrSvLexicon.NAME.getString(executionContext.getNamespaceRegistry()),
+ getPrefixedName(JcrSvLexicon.NAME),
PropertyType.nameFromValue(PropertyType.STRING),
node.getName());
@@ -141,21 +139,20 @@
assert property instanceof AbstractJcrProperty : "Illegal attempt to use
" + getClass().getName()
+ " on non-DNA
property";
- ExecutionContext executionContext = session.getExecutionContext();
AbstractJcrProperty prop = (AbstractJcrProperty)property;
// first set the property sv:name attribute
AttributesImpl propAtts = new AttributesImpl();
propAtts.addAttribute(JcrSvLexicon.NAME.getNamespaceUri(),
JcrSvLexicon.NAME.getLocalName(),
-
JcrSvLexicon.NAME.getString(executionContext.getNamespaceRegistry()),
+ getPrefixedName(JcrSvLexicon.NAME),
PropertyType.nameFromValue(PropertyType.STRING),
prop.getName());
// and it's sv:type attribute
propAtts.addAttribute(JcrSvLexicon.TYPE.getNamespaceUri(),
JcrSvLexicon.TYPE.getLocalName(),
-
JcrSvLexicon.TYPE.getString(executionContext.getNamespaceRegistry()),
+ getPrefixedName(JcrSvLexicon.TYPE),
PropertyType.nameFromValue(PropertyType.STRING),
PropertyType.nameFromValue(prop.getType()));
@@ -224,7 +221,7 @@
}
if (allCharsAreValidXml) {
-
+
startElement(contentHandler, JcrSvLexicon.VALUE, null);
contentHandler.characters(chars, 0, chars.length);
endElement(contentHandler, JcrSvLexicon.VALUE);