Author: rhauch
Date: 2008-09-10 11:19:33 -0400 (Wed, 10 Sep 2008)
New Revision: 513
Added:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryImporter.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/DnaDtdLexicon.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/DnaXmlLexicon.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryImporterTest.java
trunk/dna-repository/src/test/resources/repositoryImporterTestData1.xml
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java
trunk/dna-repository/src/test/resources/CurrencyFormatterExample.mxml
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
Log:
Added RepositoryImporter that is capable of importing content from an XML document into a
RepositorySource. This will be used in the example and is an easy way to populate an
InMemoryRepositorySource. Also added several lexicon classes rather than miscellaneous
constants.
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java 2008-09-09
18:56:21 UTC (rev 512)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java 2008-09-10
15:19:33 UTC (rev 513)
@@ -122,8 +122,9 @@
public static I18n canceledSequencingXmlDocument;
public static I18n warningSequencingXmlDocument;
- // Federation
+ // Repository
public static I18n errorStartingRepositoryService;
+ public static I18n errorImportingContent;
static {
try {
Added:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryImporter.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryImporter.java
(rev 0)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryImporter.java 2008-09-10
15:19:33 UTC (rev 513)
@@ -0,0 +1,440 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.repository;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.SimpleProgressMonitor;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.util.Logger;
+import org.jboss.dna.repository.sequencers.xml.XmlSequencer;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.RepositorySource;
+import org.jboss.dna.spi.connector.RepositorySourceException;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.PropertyFactory;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+import org.jboss.dna.spi.graph.commands.CompositeCommand;
+import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.jboss.dna.spi.graph.commands.NodeConflictBehavior;
+import org.jboss.dna.spi.graph.commands.impl.BasicCreateNodeCommand;
+import org.jboss.dna.spi.graph.commands.impl.BasicGraphCommand;
+import org.jboss.dna.spi.sequencers.SequencerContext;
+import org.jboss.dna.spi.sequencers.SequencerOutput;
+import org.jboss.dna.spi.sequencers.StreamSequencer;
+
+/**
+ * @author Randall Hauch
+ */
+public class RepositoryImporter {
+
+ private final RepositoryConnectionFactory sources;
+ private final String sourceName;
+ private final ExecutionContext context;
+
+ public RepositoryImporter( RepositorySource source,
+ ExecutionContext context ) {
+ ArgCheck.isNotNull(source, "source");
+ ArgCheck.isNotNull(context, "context");
+ this.sources = new SingleRepositorySourceConnectionFactory(source);
+ this.sourceName = source.getName();
+ this.context = context;
+ }
+
+ public RepositoryImporter( RepositoryConnectionFactory sources,
+ String sourceName,
+ ExecutionContext context ) {
+ ArgCheck.isNotNull(sources, "sources");
+ ArgCheck.isNotEmpty(sourceName, "sourceName");
+ ArgCheck.isNotNull(context, "context");
+ this.sources = sources;
+ this.sourceName = sourceName;
+ this.context = context;
+ }
+
+ /**
+ * Get the context in which the importer will be executed.
+ *
+ * @return the execution context; never null
+ */
+ public ExecutionContext getContext() {
+ return this.context;
+ }
+
+ /**
+ * Read the content from the supplied URI and import into the repository at the
supplied location.
+ *
+ * @param uri the URI where the importer can read the content that is to be imported
+ * @param destinationPathInSource
+ * @throws IllegalArgumentException if the <code>uri</code> or
destination path are null
+ * @throws IOException if there is a problem reading the content
+ * @throws RepositorySourceException if there is a problem while writing the content
to the {@link RepositorySource repository
+ * source}
+ */
+ public void importXml( URI uri,
+ Path destinationPathInSource ) throws IOException,
RepositorySourceException {
+ ArgCheck.isNotNull(uri, "uri");
+ ArgCheck.isNotNull(destinationPathInSource,
"destinationPathInSource");
+
+ // Create the sequencer ...
+ StreamSequencer sequencer = new XmlSequencer();
+ importWithSequencer(sequencer, uri, "text/xml",
destinationPathInSource, NodeConflictBehavior.UPDATE);
+ }
+
+ /**
+ * Use the supplied sequencer to read the content at the given URI (with the
specified MIME type) and write that content to
+ * the {@link RepositorySource repository source} into the specified location.
+ *
+ * @param sequencer the sequencer that should be used; may not be null
+ * @param contentUri the URI where the content can be found; may not be null
+ * @param mimeType the MIME type for the content; may not be null
+ * @param destinationPathInSource the path in the {@link RepositorySource repository
source} where the content is to be
+ * written; may not be null
+ * @param conflictBehavior the behavior when a node is to be created when an existing
node already exists; defaults to
+ * {@link NodeConflictBehavior#UPDATE} if null
+ * @throws IOException if there is a problem reading the content
+ * @throws RepositorySourceException if there is a problem while writing the content
to the {@link RepositorySource repository
+ * source}
+ */
+ protected void importWithSequencer( StreamSequencer sequencer,
+ URI contentUri,
+ String mimeType,
+ Path destinationPathInSource,
+ NodeConflictBehavior conflictBehavior ) throws
IOException, RepositorySourceException {
+ assert sequencer != null;
+ assert contentUri != null;
+ assert mimeType != null;
+ assert destinationPathInSource != null;
+ conflictBehavior = conflictBehavior != null ? conflictBehavior :
NodeConflictBehavior.UPDATE;
+
+ // Get the input path by creating from the URI, in case the URI is a valid path
...
+ Path inputPath = extractInputPathFrom(contentUri);
+ assert inputPath != null;
+
+ // Now create the importer context ...
+ PropertyFactory propertyFactory = getContext().getPropertyFactory();
+ NameFactory nameFactory = getContext().getValueFactories().getNameFactory();
+ Set<Property> inputProperties = new HashSet<Property>();
+
inputProperties.add(propertyFactory.create(nameFactory.create("jcr:mimeType"),
mimeType));
+ ImporterContext importerContext = new ImporterContext(inputPath, inputProperties,
"text/xml");
+
+ // Now run the sequencer ...
+ String activity =
RepositoryI18n.errorImportingContent.text(destinationPathInSource, contentUri);
+ ProgressMonitor progressMonitor = new SimpleProgressMonitor(activity);
+ ImporterCommands commands = new ImporterCommands(destinationPathInSource,
conflictBehavior);
+ InputStream stream = null;
+ try {
+ stream = contentUri.toURL().openStream();
+ sequencer.sequence(stream, commands, importerContext, progressMonitor);
+ } catch (MalformedURLException err) {
+ throw new IOException(err.getMessage());
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ I18n msg = RepositoryI18n.errorImportingContent;
+ context.getLogger(getClass()).error(e, msg, mimeType, contentUri);
+ }
+ }
+ }
+
+ // Now execute the commands against the repository ...
+ RepositoryConnection connection = null;
+ try {
+ connection = sources.createConnection(this.sourceName);
+ connection.execute(context, commands);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (RepositorySourceException e) {
+ I18n msg = RepositoryI18n.errorImportingContent;
+ context.getLogger(getClass()).error(e, msg, mimeType, contentUri);
+ }
+ }
+ }
+ }
+
+ /**
+ * @param contentUri
+ * @return the input path
+ */
+ protected Path extractInputPathFrom( URI contentUri ) {
+ try {
+ return getContext().getValueFactories().getPathFactory().create(contentUri);
+ } catch (ValueFormatException e) {
+ // Get the last component of the URI, and use it to create the input path
...
+ String path = contentUri.getPath();
+ return getContext().getValueFactories().getPathFactory().create(path);
+ }
+ }
+
+ protected class SingleRepositorySourceConnectionFactory implements
RepositoryConnectionFactory {
+ private final RepositorySource source;
+
+ protected SingleRepositorySourceConnectionFactory( RepositorySource source ) {
+ ArgCheck.isNotNull(source, "source");
+ this.source = source;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.connector.RepositoryConnectionFactory#createConnection(java.lang.String)
+ */
+ public RepositoryConnection createConnection( String sourceName ) throws
RepositorySourceException {
+ if (source.getName().equals(sourceName)) {
+ return source.getConnection();
+ }
+ return null;
+ }
+ }
+
+ protected class ImporterCommands extends BasicGraphCommand implements
SequencerOutput, CompositeCommand {
+ private final List<GraphCommand> commands = new
ArrayList<GraphCommand>();
+ private final Map<Path, BasicCreateNodeCommand> createNodeCommands = new
HashMap<Path, BasicCreateNodeCommand>();
+ private final NodeConflictBehavior conflictBehavior;
+ private final Path destinationPath;
+
+ protected ImporterCommands( Path destinationPath,
+ NodeConflictBehavior conflictBehavior ) {
+ ArgCheck.isNotNull(destinationPath, "destinationPath");
+ ArgCheck.isNotNull(conflictBehavior, "conflictBehavior");
+ this.conflictBehavior = conflictBehavior;
+ this.destinationPath = destinationPath;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerOutput#getFactories()
+ */
+ public ValueFactories getFactories() {
+ return getContext().getValueFactories();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerOutput#getNamespaceRegistry()
+ */
+ public NamespaceRegistry getNamespaceRegistry() {
+ return getContext().getNamespaceRegistry();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.sequencers.SequencerOutput#setProperty(java.lang.String,
java.lang.String, java.lang.Object[])
+ */
+ public void setProperty( String nodePath,
+ String propertyName,
+ Object... values ) {
+ // Create a command that sets the property ...
+ Path path = getFactories().getPathFactory().create(nodePath);
+ Name name = getFactories().getNameFactory().create(propertyName);
+ setProperty(path, name, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.sequencers.SequencerOutput#setProperty(org.jboss.dna.spi.graph.Path,
+ * org.jboss.dna.spi.graph.Name, java.lang.Object[])
+ */
+ public void setProperty( Path nodePath,
+ Name propertyName,
+ Object... values ) {
+ PathFactory pathFactory = getFactories().getPathFactory();
+ if (nodePath.isAbsolute())
nodePath.relativeTo(pathFactory.createRootPath());
+ nodePath = pathFactory.create(destinationPath,
nodePath).getNormalizedPath();
+ Property property = getContext().getPropertyFactory().create(propertyName,
values);
+ BasicCreateNodeCommand command = createNodeCommands.get(nodePath);
+ if (command != null) {
+ // We've already created the node, so find that command and add to
it.
+ Collection<Property> properties = command.getProperties();
+ // See if the property was already added and remove it if so
+ Iterator<Property> iter = properties.iterator();
+ while (iter.hasNext()) {
+ Property existingProperty = iter.next();
+ if (existingProperty.getName().equals(propertyName)) {
+ iter.remove();
+ break;
+ }
+ }
+ command.getProperties().add(property);
+ } else {
+ // We haven't created the node yet (and we're assuming that we
need to), so create the node
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(property);
+ command = new BasicCreateNodeCommand(nodePath, properties,
conflictBehavior);
+ createNodeCommands.put(nodePath, command);
+ commands.add(command);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.sequencers.SequencerOutput#setReference(java.lang.String,
java.lang.String, java.lang.String[])
+ */
+ public void setReference( String nodePath,
+ String propertyName,
+ String... paths ) {
+ Path path = getFactories().getPathFactory().create(nodePath);
+ Name name = getFactories().getNameFactory().create(propertyName);
+ // Create an array of reference values ...
+ ValueFactory<Reference> factory =
getFactories().getReferenceFactory();
+ Object[] values = new Object[paths.length];
+ int i = 0;
+ for (String referencedPath : paths) {
+ values[i++] = factory.create(referencedPath);
+ }
+ setProperty(path, name, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<GraphCommand> iterator() {
+ return this.commands.iterator();
+ }
+
+ }
+
+ protected class ImporterContext implements SequencerContext {
+
+ private final Path inputPath;
+ private final Set<Property> inputProperties;
+ private final String mimeType;
+
+ protected ImporterContext( Path inputPath,
+ Set<Property> inputProperties,
+ String mimeType ) {
+ this.inputPath = inputPath;
+ this.inputProperties = inputProperties;
+ this.mimeType = mimeType;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getFactories()
+ */
+ public ValueFactories getFactories() {
+ return getContext().getValueFactories();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getInputPath()
+ */
+ public Path getInputPath() {
+ return inputPath;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getInputProperties()
+ */
+ public Set<Property> getInputProperties() {
+ return inputProperties;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.sequencers.SequencerContext#getInputProperty(org.jboss.dna.spi.graph.Name)
+ */
+ public Property getInputProperty( Name name ) {
+ for (Property property : inputProperties) {
+ if (property.getName().equals(name)) return property;
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getLogger(java.lang.Class)
+ */
+ public Logger getLogger( Class<?> clazz ) {
+ return getContext().getLogger(clazz);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.sequencers.SequencerContext#getLogger(java.lang.String)
+ */
+ public Logger getLogger( String name ) {
+ return getContext().getLogger(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getMimeType()
+ */
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getNamespaceRegistry()
+ */
+ public NamespaceRegistry getNamespaceRegistry() {
+ return getContext().getNamespaceRegistry();
+ }
+
+ }
+
+}
Property changes on:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryImporter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/DnaDtdLexicon.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/DnaDtdLexicon.java
(rev 0)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/DnaDtdLexicon.java 2008-09-10
15:19:33 UTC (rev 513)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.repository.sequencers.xml;
+
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.impl.BasicName;
+
+/**
+ * @author Randall Hauch
+ */
+public class DnaDtdLexicon {
+
+ public static class Namespace {
+ public static final String URI = "http://www.jboss.org/dna/dtd/1.0";
+ public static final String PREFIX = "dnadtd";
+ }
+
+ public static final Name NAME = new BasicName(Namespace.URI, "name");
+ public static final Name PUBLIC_ID = new BasicName(Namespace.URI,
"publicId");
+ public static final Name SYSTEM_ID = new BasicName(Namespace.URI,
"systemId");
+ public static final Name VALUE = new BasicName(Namespace.URI, "value");
+ public static final Name ENTITY = new BasicName(Namespace.URI, "entity");
+}
Property changes on:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/DnaDtdLexicon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/DnaXmlLexicon.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/DnaXmlLexicon.java
(rev 0)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/DnaXmlLexicon.java 2008-09-10
15:19:33 UTC (rev 513)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.repository.sequencers.xml;
+
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.impl.BasicName;
+
+/**
+ * @author Randall Hauch
+ */
+public class DnaXmlLexicon {
+
+ public static class Namespace {
+ public static final String URI = "http://www.jboss.org/dna/xml/1.0";
+ public static final String PREFIX = "dnaxml";
+ }
+
+ public static final Name CDATA = new BasicName(Namespace.URI, "cData");
+ public static final Name CDATA_CONTENT = new BasicName(Namespace.URI,
"cDataContent");
+ public static final Name COMMENT = new BasicName(Namespace.URI,
"comment");
+ public static final Name COMMENT_CONTENT = new BasicName(Namespace.URI,
"commentContent");
+ public static final Name DOCUMENT = new BasicName(Namespace.URI,
"document");
+ public static final Name ELEMENT_CONTENT = new BasicName(Namespace.URI,
"elementContent");
+ public static final Name PROCESSING_INSTRUCTION = new BasicName(Namespace.URI,
"processingInstruction");
+ public static final Name PROCESSING_INSTRUCTION_CONTENT = new
BasicName(Namespace.URI, "processingInstructionContent");
+ public static final Name TARGET = new BasicName(Namespace.URI, "target");
+}
Property changes on:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/DnaXmlLexicon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java 2008-09-09
18:56:21 UTC (rev 512)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java 2008-09-10
15:19:33 UTC (rev 513)
@@ -28,7 +28,6 @@
import java.util.List;
import java.util.Map;
import org.jboss.dna.common.monitor.ProgressMonitor;
-import org.jboss.dna.common.util.Logger;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.repository.RepositoryI18n;
import org.jboss.dna.spi.graph.Name;
@@ -52,23 +51,7 @@
*/
public class XmlSequencer implements StreamSequencer {
- static final Logger LOGGER = Logger.getLogger(XmlSequencer.class);
-
- static final String CDATA = "dnaxml:cData";
- static final String CDATA_CONTENT = "dnaxml:cDataContent";
- static final String COMMENT = "dnaxml:comment";
- static final String COMMENT_CONTENT = "dnaxml:commentContent";
- static final String DOCUMENT = "dnaxml:document";
- static final String DTD_NAME = "dnadtd:name";
- static final String DTD_PUBLIC_ID = "dnadtd:publicId";
- static final String DTD_SYSTEM_ID = "dnadtd:systemId";
- static final String DTD_VALUE = "dnadtd:value";
- static final String ELEMENT_CONTENT = "dnaxml:elementContent";
- static final String ENTITY = "dnadtd:entity";
- static final String PI = "dnaxml:processingInstruction";
- static final String PI_CONTENT = "dnaxml:processingInstructionContent";
- static final String TARGET = "dnaxml:target";
-
+ private static final String DEFAULT_PRIMARY_TYPE = "nt:unstructured";
private static final String DECL_HANDLER_FEATURE =
"http://xml.org/sax/properties/declaration-handler";
private static final String ENTITY_RESOLVER_2_FEATURE =
"http://xml.org/sax/features/use-entity-resolver2";
private static final String LEXICAL_HANDLER_FEATURE =
"http://xml.org/sax/properties/lexical-handler";
@@ -124,11 +107,8 @@
// Cached instances of the name factory and commonly referenced names
private final NameFactory nameFactory;
- private Name commentContentName;
- private Name commentName;
- private Name elementContentName;
private Name primaryTypeName;
- private Name targetName;
+ private Name defaultPrimaryType;
// Recursive map used to track the number of occurrences of names for elements
under a particular path
private Map<Name, List<IndexedName>> nameToIndexedNamesMap = new
HashMap<Name, List<IndexedName>>();
@@ -231,9 +211,9 @@
int length ) throws SAXException {
stopIfCancelled();
// Output separate nodes for each comment since multiple are allowed
- startElement(getCommentName());
- output.setProperty(path, getPrimaryTypeName(), getCommentName());
- output.setProperty(path, getCommentContentName(), String.valueOf(ch, start,
length));
+ startElement(DnaXmlLexicon.COMMENT);
+ output.setProperty(path, getPrimaryTypeName(), DnaXmlLexicon.COMMENT);
+ output.setProperty(path, DnaXmlLexicon.COMMENT_CONTENT, String.valueOf(ch,
start, length));
endElement();
updateProgress();
}
@@ -262,7 +242,7 @@
public void endCDATA() throws SAXException {
stopIfCancelled();
// Output CDATA built in characters() method
- output.setProperty(path, nameFactory.create(CDATA_CONTENT),
cDataBuilder.toString());
+ output.setProperty(path, DnaXmlLexicon.CDATA_CONTENT,
cDataBuilder.toString());
endElement();
// Null-out builder to free memory
cDataBuilder = null;
@@ -279,9 +259,9 @@
// Skip if nothing in content but whitespace
if (content.length() > 0) {
// Create separate node for each content entry since entries can be
interspersed amongst child elements
- startElement(getElementContentName());
- output.setProperty(path, getPrimaryTypeName(),
getElementContentName());
- output.setProperty(path, getElementContentName(), content);
+ startElement(DnaXmlLexicon.ELEMENT_CONTENT);
+ output.setProperty(path, getPrimaryTypeName(),
DnaXmlLexicon.ELEMENT_CONTENT);
+ output.setProperty(path, DnaXmlLexicon.ELEMENT_CONTENT, content);
endElement();
}
}
@@ -360,7 +340,7 @@
*/
@Override
public void error( SAXParseException error ) {
- LOGGER.error(error, RepositoryI18n.errorSequencingXmlDocument, error);
+ context.getLogger(XmlSequencer.class).error(error,
RepositoryI18n.errorSequencingXmlDocument, error);
monitor.getProblems().addError(error,
RepositoryI18n.errorSequencingXmlDocument, error);
}
@@ -377,12 +357,12 @@
String systemId ) throws SAXException {
stopIfCancelled();
// Add "synthetic" entity container to path to help prevent name
collisions with XML elements
- Name entityName = nameFactory.create(ENTITY);
+ Name entityName = DnaDtdLexicon.ENTITY;
startElement(entityName);
output.setProperty(path, getPrimaryTypeName(), entityName);
- output.setProperty(path, nameFactory.create(DTD_NAME), name);
- output.setProperty(path, nameFactory.create(DTD_PUBLIC_ID), publicId);
- output.setProperty(path, nameFactory.create(DTD_SYSTEM_ID), systemId);
+ output.setProperty(path, nameFactory.create(DnaDtdLexicon.NAME), name);
+ output.setProperty(path, nameFactory.create(DnaDtdLexicon.PUBLIC_ID),
publicId);
+ output.setProperty(path, nameFactory.create(DnaDtdLexicon.SYSTEM_ID),
systemId);
endElement();
updateProgress();
}
@@ -396,31 +376,10 @@
*/
@Override
public void fatalError( SAXParseException error ) {
- LOGGER.error(error, RepositoryI18n.fatalErrorSequencingXmlDocument);
+ context.getLogger(XmlSequencer.class).error(error,
RepositoryI18n.fatalErrorSequencingXmlDocument, error);
monitor.getProblems().addError(error,
RepositoryI18n.fatalErrorSequencingXmlDocument, error);
}
- private Name getCommentContentName() {
- if (commentContentName == null) {
- commentContentName = nameFactory.create(COMMENT_CONTENT);
- }
- return commentContentName;
- }
-
- private Name getCommentName() {
- if (commentName == null) {
- commentName = nameFactory.create(COMMENT);
- }
- return commentName;
- }
-
- private Name getElementContentName() {
- if (elementContentName == null) {
- elementContentName = nameFactory.create(ELEMENT_CONTENT);
- }
- return elementContentName;
- }
-
private Name getPrimaryTypeName() {
if (primaryTypeName == null) {
primaryTypeName = nameFactory.create(NameFactory.JCR_PRIMARY_TYPE);
@@ -428,11 +387,11 @@
return primaryTypeName;
}
- private Name getTargetName() {
- if (targetName == null) {
- targetName = nameFactory.create(TARGET);
+ private Name getDefaultPrimaryType() {
+ if (defaultPrimaryType == null) {
+ defaultPrimaryType = nameFactory.create(DEFAULT_PRIMARY_TYPE);
}
- return targetName;
+ return defaultPrimaryType;
}
/**
@@ -461,11 +420,11 @@
String value ) throws SAXException {
stopIfCancelled();
// Add "synthetic" entity container to path to help prevent name
collisions with XML elements
- Name entityName = nameFactory.create(ENTITY);
+ Name entityName = DnaDtdLexicon.ENTITY;
startElement(entityName);
output.setProperty(path, getPrimaryTypeName(), entityName);
- output.setProperty(path, nameFactory.create(DTD_NAME), name);
- output.setProperty(path, nameFactory.create(DTD_VALUE), value);
+ output.setProperty(path, DnaDtdLexicon.NAME, name);
+ output.setProperty(path, DnaDtdLexicon.VALUE, value);
endElement();
updateProgress();
}
@@ -496,11 +455,11 @@
String data ) throws SAXException {
stopIfCancelled();
// Output separate nodes for each instruction since multiple are allowed
- Name name = nameFactory.create(PI);
+ Name name = DnaXmlLexicon.PROCESSING_INSTRUCTION;
startElement(name);
output.setProperty(path, getPrimaryTypeName(), name);
- output.setProperty(path, getTargetName(), target);
- output.setProperty(path, nameFactory.create(PI_CONTENT), data);
+ output.setProperty(path, DnaXmlLexicon.TARGET, target);
+ output.setProperty(path, DnaXmlLexicon.PROCESSING_INSTRUCTION_CONTENT,
data);
endElement();
updateProgress();
}
@@ -528,7 +487,7 @@
public void startCDATA() throws SAXException {
stopIfCancelled();
// Output separate nodes for each CDATA since multiple are allowed
- startElement(nameFactory.create(CDATA));
+ startElement(DnaXmlLexicon.CDATA);
// Prepare builder for concatenating consecutive lines of CDATA
cDataBuilder = new StringBuilder();
updateProgress();
@@ -544,7 +503,7 @@
@Override
public void startDocument() throws SAXException {
stopIfCancelled();
- output.setProperty(path, getPrimaryTypeName(),
nameFactory.create(DOCUMENT));
+ output.setProperty(path, getPrimaryTypeName(), DnaXmlLexicon.DOCUMENT);
updateProgress();
}
@@ -560,9 +519,9 @@
String publicId,
String systemId ) throws SAXException {
stopIfCancelled();
- output.setProperty(path, nameFactory.create(DTD_NAME), name);
- output.setProperty(path, nameFactory.create(DTD_PUBLIC_ID), publicId);
- output.setProperty(path, nameFactory.create(DTD_SYSTEM_ID), systemId);
+ output.setProperty(path, DnaDtdLexicon.NAME, name);
+ output.setProperty(path, DnaDtdLexicon.PUBLIC_ID, publicId);
+ output.setProperty(path, DnaDtdLexicon.SYSTEM_ID, systemId);
updateProgress();
}
@@ -581,6 +540,7 @@
// Add element name and the appropriate index to the path.
// Per the JCR spec, the index must be relative to same-name sibling nodes
path = context.getFactories().getPathFactory().create(path, name,
indexedNames.size());
+ path = path.getNormalizedPath();
// Add the indexed name map to the stack and set the current map to the new
element's map
nameToIndexedNamesMapStack.addFirst(nameToIndexedNamesMap);
nameToIndexedNamesMap = indexedName.nameToIndexedNamesMap;
@@ -609,14 +569,18 @@
Attributes attributes ) throws SAXException {
stopIfCancelled();
startElement(nameFactory.create(name));
- output.setProperty(path, getPrimaryTypeName(), nameFactory.create(uri,
localName));
+ output.setProperty(path, getPrimaryTypeName(), getDefaultPrimaryType());
// Output this element's attributes using the attribute's namespace,
if supplied, or the current namespace in scope.
String inheritedNs = nsStack.getFirst();
for (int ndx = 0, len = attributes.getLength(); ndx < len; ++ndx) {
String ns = attributes.getURI(ndx);
- output.setProperty(path,
- nameFactory.create(ns.length() == 0 ? inheritedNs :
ns, attributes.getLocalName(ndx)),
- attributes.getValue(ndx));
+ String attrLocalName = attributes.getLocalName(ndx);
+ Object value = attributes.getValue(ndx);
+ String jcrNsUri =
context.getNamespaceRegistry().getNamespaceForPrefix("jcr");
+ if (jcrNsUri != null && jcrNsUri.equals(ns) &&
attrLocalName.equals("primaryType")) {
+ value = nameFactory.create(value);
+ }
+ output.setProperty(path, nameFactory.create(ns.length() == 0 ?
inheritedNs : ns, attrLocalName), value);
}
updateProgress();
}
@@ -694,7 +658,7 @@
*/
@Override
public void warning( SAXParseException warning ) {
- LOGGER.warn(warning, RepositoryI18n.warningSequencingXmlDocument);
+ context.getLogger(XmlSequencer.class).warn(warning,
RepositoryI18n.warningSequencingXmlDocument);
monitor.getProblems().addWarning(warning,
RepositoryI18n.warningSequencingXmlDocument, warning);
}
}
Modified:
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties
===================================================================
---
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties 2008-09-09
18:56:21 UTC (rev 512)
+++
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties 2008-09-10
15:19:33 UTC (rev 513)
@@ -103,3 +103,4 @@
warningSequencingXmlDocument = A warning was received while sequencing XML: {0}
errorStartingRepositoryService = Error while starting repository service
+errorImportingContent = Error importing {0} content from {1}
Added:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryImporterTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryImporterTest.java
(rev 0)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryImporterTest.java 2008-09-10
15:19:33 UTC (rev 513)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.repository;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
+import java.io.File;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.transaction.xa.XAResource;
+import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.repository.sequencers.xml.DnaDtdLexicon;
+import org.jboss.dna.repository.sequencers.xml.DnaXmlLexicon;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.RepositorySourceException;
+import org.jboss.dna.spi.connector.RepositorySourceListener;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.commands.CompositeCommand;
+import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
+import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author Randall Hauch
+ */
+public class RepositoryImporterTest {
+
+ private RepositoryImporter importer;
+ private String sourceName;
+ private ExecutionContext context;
+ private URI xmlContent;
+ private MockRepositoryConnection connection;
+ private GraphCommand lastExecutedCommand;
+ private Path destinationPath;
+ @Mock
+ private RepositoryConnectionFactory sources;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ xmlContent = new
File("src/test/resources/repositoryImporterTestData1.xml").toURI();
+ context = new BasicExecutionContext();
+ context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
+ context.getNamespaceRegistry().register(DnaXmlLexicon.Namespace.PREFIX,
DnaXmlLexicon.Namespace.URI);
+ context.getNamespaceRegistry().register(DnaDtdLexicon.Namespace.PREFIX,
DnaDtdLexicon.Namespace.URI);
+ context.getNamespaceRegistry().register("jcr",
"http://www.jcp.org/jcr/1.0");
+ context.getNamespaceRegistry().register("nt",
"http://www.jcp.org/jcr/nt/1.0");
+ sourceName = "sourceA";
+ destinationPath =
context.getValueFactories().getPathFactory().create("/a/b");
+ importer = new RepositoryImporter(sources, sourceName, context);
+ connection = new MockRepositoryConnection();
+ stub(sources.createConnection(sourceName)).toReturn(connection);
+ }
+
+ @Test
+ public void shouldImportXmlContentAndGenerateTheCorrectCommands() throws Exception {
+ System.out.println(xmlContent);
+ importer.importXml(xmlContent, destinationPath); // writes commands as
CompositeCommand to 'lastExecutedCommand'
+ assertThat(lastExecutedCommand, is(instanceOf(CompositeCommand.class)));
+ Iterator<GraphCommand> iter =
((CompositeCommand)lastExecutedCommand).iterator();
+ assertCreateNode(iter, "/a/b/",
"jcr:primaryType={http://www.jboss.org/dna/xml/1.0}document");
+ assertCreateNode(iter, "/a/b/dnaxml:comment[1]", "any
properties"); // jcr:primaryType and dnaxml:commentContent
+ assertCreateNode(iter, "/a/b/dna:system[1]",
"jcr:primaryType={http://www.jcp.org/jcr/nt/1.0}unstructured");
+ assertCreateNode(iter, "/a/b/dna:system[1]/dnaxml:comment[1]",
"any properties");
+ assertCreateNode(iter, "/a/b/dna:system[1]/dna:sources[1]",
"jcr:primaryType={http://www.jcp.org/jcr/nt/1.0}unstructured");
+ assertCreateNode(iter,
+ "/a/b/dna:system[1]/dna:sources[1]/sourceA[1]",
+ "dna:repositoryName=repositoryA",
+ "dna:retryLimit=3",
+ "jcr:primaryType={http://www.jboss.org/dna}xyz",
+
"dna:classname=org.jboss.dna.connector.inmemory.InMemoryRepositorySource");
+ assertCreateNode(iter,
+ "/a/b/dna:system[1]/dna:sources[1]/sourceB[1]",
+ "dna:repositoryName=repositoryB",
+
"jcr:primaryType={http://www.jcp.org/jcr/nt/1.0}unstructured",
+
"dna:classname=org.jboss.dna.connector.inmemory.InMemoryRepositorySource");
+ assertThat(iter.hasNext(), is(false));
+ }
+
+ public void assertCreateNode( Iterator<GraphCommand> iterator,
+ String path,
+ String... properties ) {
+ GraphCommand nextCommand = iterator.next();
+ assertThat(nextCommand, is(instanceOf(CreateNodeCommand.class)));
+ CreateNodeCommand createNode = (CreateNodeCommand)nextCommand;
+ Path expectedPath = context.getValueFactories().getPathFactory().create(path);
+ assertThat(createNode.getPath(), is(expectedPath));
+ Map<Name, Property> propertiesByName = new HashMap<Name,
Property>();
+ for (Property prop : createNode.getProperties()) {
+ propertiesByName.put(prop.getName(), prop);
+ }
+ for (String propertyStr : properties) {
+ if (propertyStr == "any properties") {
+ propertiesByName.clear();
+ break;
+ }
+ Matcher matcher =
Pattern.compile("([^=]+)=(.*)").matcher(propertyStr);
+ if (!matcher.matches()) continue;
+ System.out.println("Property: " + propertyStr + " ==>
" + matcher);
+ Name propertyName =
context.getValueFactories().getNameFactory().create(matcher.group(1));
+ System.out.println("Property name: " + matcher.group(1));
+ String value = matcher.group(2); // doesn't handle multiple values!!
+ if (value.trim().length() == 0) value = null;
+ Property actual = propertiesByName.remove(propertyName);
+ Property expectedProperty = context.getPropertyFactory().create(propertyName,
value);
+ assertThat(actual, is(expectedProperty));
+ }
+ if (!propertiesByName.isEmpty()) {
+ System.out.println("Properties for " + path + "\n" +
StringUtil.readableString(propertiesByName));
+ }
+ assertThat(propertiesByName.isEmpty(), is(true));
+ }
+
+ protected class MockRepositoryConnection implements RepositoryConnection {
+ public void close() {
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ public void execute( ExecutionContext context,
+ GraphCommand... commands ) throws RepositorySourceException
{
+ lastExecutedCommand = commands[0];
+ }
+
+ public CachePolicy getDefaultCachePolicy() {
+ return null;
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ public String getSourceName() {
+ return sourceName;
+ }
+
+ public XAResource getXAResource() {
+ return null;
+ }
+
+ public boolean ping( long time,
+ TimeUnit unit ) {
+ return true;
+ }
+
+ public void setListener( RepositorySourceListener listener ) {
+ }
+ }
+
+}
Property changes on:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryImporterTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java 2008-09-09
18:56:21 UTC (rev 512)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java 2008-09-10
15:19:33 UTC (rev 513)
@@ -46,6 +46,21 @@
*/
public class XmlSequencerTest {
+ private static final String CDATA = "dnaxml:cData";
+ private static final String CDATA_CONTENT = "dnaxml:cDataContent";
+ private static final String COMMENT = "dnaxml:comment";
+ private static final String COMMENT_CONTENT = "dnaxml:commentContent";
+ private static final String DOCUMENT = "dnaxml:document";
+ private static final String DTD_NAME = "dnadtd:name";
+ private static final String DTD_PUBLIC_ID = "dnadtd:publicId";
+ private static final String DTD_SYSTEM_ID = "dnadtd:systemId";
+ private static final String DTD_VALUE = "dnadtd:value";
+ private static final String ELEMENT_CONTENT = "dnaxml:elementContent";
+ private static final String ENTITY = "dnadtd:entity";
+ private static final String PI = "dnaxml:processingInstruction";
+ private static final String PI_CONTENT =
"dnaxml:processingInstructionContent";
+ private static final String TARGET = "dnaxml:target";
+
private XmlSequencer sequencer;
private InputStream stream;
private MockSequencerOutput output;
@@ -92,67 +107,67 @@
@Test
public void shouldSequenceXml() throws IOException {
verifyDocument(xml1);
- verifyName(XmlSequencer.COMMENT + "[1]", NameFactory.JCR_PRIMARY_TYPE,
XmlSequencer.COMMENT);
- String text = verify(XmlSequencer.COMMENT + "[1]",
XmlSequencer.COMMENT_CONTENT, String.class);
+ verifyName(COMMENT + "[1]", NameFactory.JCR_PRIMARY_TYPE, COMMENT);
+ String text = verify(COMMENT + "[1]", COMMENT_CONTENT, String.class);
assertThat(text.startsWith("\n Licensed to the Apache Software Foundation
(ASF)"), is(true));
assertThat(text.endsWith(" limitations under the License.\n"),
is(true));
- verifyString("", XmlSequencer.DTD_NAME, "Repository");
- verifyString("", XmlSequencer.DTD_PUBLIC_ID, "-//The Apache
Software Foundation//DTD Jackrabbit 1.2//EN");
- verifyString("", XmlSequencer.DTD_SYSTEM_ID,
"http://jackrabbit.apache.org/dtd/repository-1.2.dtd");
- verifyName(XmlSequencer.COMMENT + "[2]", NameFactory.JCR_PRIMARY_TYPE,
XmlSequencer.COMMENT);
- verifyString(XmlSequencer.COMMENT + "[2]",
XmlSequencer.COMMENT_CONTENT, " Example Repository Configuration File ");
- verifyName("Repository[1]", NameFactory.JCR_PRIMARY_TYPE,
"Repository");
- verifyName("Repository[1]/" + XmlSequencer.COMMENT + "[1]",
NameFactory.JCR_PRIMARY_TYPE, XmlSequencer.COMMENT);
+ verifyString("/", DTD_NAME, "Repository");
+ verifyString("/", DTD_PUBLIC_ID, "-//The Apache Software
Foundation//DTD Jackrabbit 1.2//EN");
+ verifyString("/", DTD_SYSTEM_ID,
"http://jackrabbit.apache.org/dtd/repository-1.2.dtd");
+ verifyName(COMMENT + "[2]", NameFactory.JCR_PRIMARY_TYPE, COMMENT);
+ verifyString(COMMENT + "[2]", COMMENT_CONTENT, " Example
Repository Configuration File ");
+ verifyName("Repository[1]", NameFactory.JCR_PRIMARY_TYPE,
"nt:unstructured");
+ verifyName("Repository[1]/" + COMMENT + "[1]",
NameFactory.JCR_PRIMARY_TYPE, COMMENT);
}
@Test
public void shouldHandleNamespaces() throws IOException {
verifyDocument(xml2);
- verifyName("book[1]/bookinfo[1]/xi:include[1]",
NameFactory.JCR_PRIMARY_TYPE, "xi:include");
+ verifyName("book[1]/bookinfo[1]/xi:include[1]",
NameFactory.JCR_PRIMARY_TYPE, "nt:unstructured");
verifyString("book[1]/bookinfo[1]/xi:include[1]", "xi:href",
"Author_Group.xml");
- verifyName("book[1]/bookinfo[1]/xi:include[2]",
NameFactory.JCR_PRIMARY_TYPE, "xi:include");
+ verifyName("book[1]/bookinfo[1]/xi:include[2]",
NameFactory.JCR_PRIMARY_TYPE, "nt:unstructured");
verifyString("book[1]/bookinfo[1]/xi:include[2]", "xi:href",
"Legal_Notice.xml");
}
@Test
public void shouldSequenceEntityDeclarations() throws IOException {
verifyDocument(xml2);
- verifyName(XmlSequencer.ENTITY + "[1]", NameFactory.JCR_PRIMARY_TYPE,
XmlSequencer.ENTITY);
- verifyString(XmlSequencer.ENTITY + "[1]", XmlSequencer.DTD_NAME,
"%RH-ENTITIES");
- verifyString(XmlSequencer.ENTITY + "[1]", XmlSequencer.DTD_SYSTEM_ID,
"Common_Config/rh-entities.ent");
- verifyName(XmlSequencer.ENTITY + "[2]", NameFactory.JCR_PRIMARY_TYPE,
XmlSequencer.ENTITY);
- verifyString(XmlSequencer.ENTITY + "[2]", XmlSequencer.DTD_NAME,
"versionNumber");
- verifyString(XmlSequencer.ENTITY + "[2]", XmlSequencer.DTD_VALUE,
"0.1");
- verifyName(XmlSequencer.ENTITY + "[3]", NameFactory.JCR_PRIMARY_TYPE,
XmlSequencer.ENTITY);
- verifyString(XmlSequencer.ENTITY + "[3]", XmlSequencer.DTD_NAME,
"copyrightYear");
- verifyString(XmlSequencer.ENTITY + "[3]", XmlSequencer.DTD_VALUE,
"2008");
+ verifyName(ENTITY + "[1]", NameFactory.JCR_PRIMARY_TYPE, ENTITY);
+ verifyString(ENTITY + "[1]", DTD_NAME, "%RH-ENTITIES");
+ verifyString(ENTITY + "[1]", DTD_SYSTEM_ID,
"Common_Config/rh-entities.ent");
+ verifyName(ENTITY + "[2]", NameFactory.JCR_PRIMARY_TYPE, ENTITY);
+ verifyString(ENTITY + "[2]", DTD_NAME, "versionNumber");
+ verifyString(ENTITY + "[2]", DTD_VALUE, "0.1");
+ verifyName(ENTITY + "[3]", NameFactory.JCR_PRIMARY_TYPE, ENTITY);
+ verifyString(ENTITY + "[3]", DTD_NAME, "copyrightYear");
+ verifyString(ENTITY + "[3]", DTD_VALUE, "2008");
}
@Test
public void shouldSequenceElementContent() throws IOException {
verifyDocument(xml2);
- verifyString("book[1]/chapter[4]/sect1[1]/para[8]/" +
XmlSequencer.ELEMENT_CONTENT + "[1]",
- XmlSequencer.ELEMENT_CONTENT,
+ verifyString("book[1]/chapter[4]/sect1[1]/para[8]/" + ELEMENT_CONTENT +
"[1]",
+ ELEMENT_CONTENT,
"The path expression is more complicated."
+ " Sequencer path expressions are used by the sequencing
service to determine whether a particular changed node should be sequenced."
+ " The expressions consist of two parts: a selection criteria
and an output expression."
+ " Here's a simple example:");
- verifyString("book[1]/chapter[4]/sect1[1]/para[8]/programlisting[1]/" +
XmlSequencer.ELEMENT_CONTENT + "[1]",
- XmlSequencer.ELEMENT_CONTENT,
+ verifyString("book[1]/chapter[4]/sect1[1]/para[8]/programlisting[1]/" +
ELEMENT_CONTENT + "[1]",
+ ELEMENT_CONTENT,
"/a/b/c@title => /d/e/f");
}
@Test
public void shouldSequenceCData() throws IOException {
verifyDocument(xml3);
- verifyString("mx:Application[1]/mx:Script[1]/" + XmlSequencer.CDATA +
"[1]",
- XmlSequencer.CDATA_CONTENT,
+ verifyString("mx:Application[1]/mx:Script[1]/" + CDATA +
"[1]",
+ CDATA_CONTENT,
"\n\n" + " import
mx.events.ValidationResultEvent;\t\t\t\n"
+ " private var
vResult:ValidationResultEvent;\n" + "\t\t\t\n"
+ " // Event handler to validate and format
input.\n"
+ " private function Format():void {\n" +
" \n"
- + " vResult = numVal.validate();\n\n"
- + " if (vResult.type==ValidationResultEvent.VALID)
{\n"
+ + " vResult = numVal.validate();\n\n"
+ + " if
(vResult.type==ValidationResultEvent.VALID) {\n"
+ " var
temp:Number=Number(priceUS.text); \n"
+ " formattedUSPrice.text=
usdFormatter.format(temp);\n" + " }\n"
+ " \n" + "
else {\n"
@@ -163,25 +178,25 @@
@Test
public void shouldSequenceProcessingInstructions() throws IOException {
verifyDocument(xml4);
- verifyName(XmlSequencer.PI + "[1]", NameFactory.JCR_PRIMARY_TYPE,
XmlSequencer.PI);
- verifyString(XmlSequencer.PI + "[1]", XmlSequencer.TARGET,
"eclipse");
- verifyString(XmlSequencer.PI + "[1]", XmlSequencer.PI_CONTENT,
"version=\"3.0\"");
+ verifyName(PI + "[1]", NameFactory.JCR_PRIMARY_TYPE, PI);
+ verifyString(PI + "[1]", TARGET, "eclipse");
+ verifyString(PI + "[1]", PI_CONTENT,
"version=\"3.0\"");
}
@Test
public void shouldSequenceXsds() throws IOException {
verifyDocument(xsd);
- verifyName("xs:schema[1]", NameFactory.JCR_PRIMARY_TYPE,
"xs:schema");
+ verifyName("xs:schema[1]", NameFactory.JCR_PRIMARY_TYPE,
"nt:unstructured");
verifyString("xs:schema[1]", "xs:targetNamespace",
"http://ns.adobe.com/air/application/1.0");
verifyString("xs:schema[1]", "xs:elementFormDefault",
"qualified");
- verifyName("xs:schema[1]/xs:element[1]", NameFactory.JCR_PRIMARY_TYPE,
"xs:element");
+ verifyName("xs:schema[1]/xs:element[1]", NameFactory.JCR_PRIMARY_TYPE,
"nt:unstructured");
verifyString("xs:schema[1]/xs:element[1]", "xs:name",
"application");
}
private <T> T verify( String nodePath,
String property,
Class<T> expectedClass ) {
- Object[] values = output.getPropertyValues(nodePath.length() == 0 ? "."
: "./" + nodePath, property);
+ Object[] values = output.getPropertyValues(nodePath.length() == 0 ? "."
: nodePath, property);
assertThat(values, notNullValue());
assertThat(values.length, is(1));
Object value = values[0];
@@ -193,7 +208,7 @@
stream = url.openStream();
assertThat(stream, is(notNullValue()));
sequencer.sequence(stream, output, context, monitor);
- verifyName("", NameFactory.JCR_PRIMARY_TYPE, XmlSequencer.DOCUMENT);
+ verifyName("", NameFactory.JCR_PRIMARY_TYPE, DOCUMENT);
}
private void verifyName( String nodePath,
Modified: trunk/dna-repository/src/test/resources/CurrencyFormatterExample.mxml
===================================================================
--- trunk/dna-repository/src/test/resources/CurrencyFormatterExample.mxml 2008-09-09
18:56:21 UTC (rev 512)
+++ trunk/dna-repository/src/test/resources/CurrencyFormatterExample.mxml 2008-09-10
15:19:33 UTC (rev 513)
@@ -11,9 +11,9 @@
// Event handler to validate and format input.
private function Format():void {
- vResult = numVal.validate();
+ vResult = numVal.validate();
- if (vResult.type==ValidationResultEvent.VALID) {
+ if (vResult.type==ValidationResultEvent.VALID) {
var temp:Number=Number(priceUS.text);
formattedUSPrice.text= usdFormatter.format(temp);
}
Added: trunk/dna-repository/src/test/resources/repositoryImporterTestData1.xml
===================================================================
--- trunk/dna-repository/src/test/resources/repositoryImporterTestData1.xml
(rev 0)
+++ trunk/dna-repository/src/test/resources/repositoryImporterTestData1.xml 2008-09-10
15:19:33 UTC (rev 513)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ JBoss, Home of Professional Open Source.
+ ~
+ ~ Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<dna:system
xmlns:dna="http://www.jboss.org/dna"
xmlns:jcr="http://www.jcp.org/jcr/1.0">
+ <!-- Define the RepositorySource instances that will be added if not already
defined -->
+ <dna:sources>
+ <sourceA jcr:primaryType="dna:xyz"
repositoryName="repositoryA"
dna:classname="org.jboss.dna.connector.inmemory.InMemoryRepositorySource"
retryLimit="3" />
+ <sourceB repositoryName="repositoryB"
dna:classname="org.jboss.dna.connector.inmemory.InMemoryRepositorySource" />
+ </dna:sources>
+</dna:system>
\ No newline at end of file
Property changes on:
trunk/dna-repository/src/test/resources/repositoryImporterTestData1.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-09-09
18:56:21 UTC (rev 512)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-09-10
15:19:33 UTC (rev 513)
@@ -303,10 +303,10 @@
if (type1 == type2) return
((Comparator<Object>)type1.getComparator()).compare(o1, o2);
// The types are different but the classes are the same ...
- if
(type1.getDeclaringClass().isAssignableFrom(type2.getDeclaringClass())) {
+ if (type1.getValueClass().isAssignableFrom(type2.getValueClass())) {
return ((Comparator<Object>)type1.getComparator()).compare(o1,
o2);
}
- if
(type2.getDeclaringClass().isAssignableFrom(type1.getDeclaringClass())) {
+ if (type2.getValueClass().isAssignableFrom(type1.getValueClass())) {
return ((Comparator<Object>)type2.getComparator()).compare(o1,
o2);
}
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java 2008-09-09
18:56:21 UTC (rev 512)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java 2008-09-10
15:19:33 UTC (rev 513)
@@ -26,6 +26,7 @@
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.ValueComparators;
/**
* @author Randall Hauch
@@ -101,12 +102,7 @@
while (thisIter.hasNext()) { // && thatIter.hasNext()
Object thisValue = thisIter.next();
Object thatValue = thatIter.next();
- if (thisValue == null) {
- if (thatValue != null) return false;
- // else both are null
- } else {
- if (!thisValue.equals(thatValue)) return false;
- }
+ if (ValueComparators.OBJECT_COMPARATOR.compare(thisValue, thatValue) !=
0) return false;
}
return true;
}
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java 2008-09-09
18:56:21 UTC (rev 512)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java 2008-09-10
15:19:33 UTC (rev 513)
@@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.Map;
import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
@@ -39,112 +40,112 @@
@NotThreadSafe
public class MockSequencerOutput implements SequencerOutput {
- private final Map<Path, Object[]> properties;
- private final ValueFactories factories;
+ private final Map<Path, Object[]> properties;
+ private final ValueFactories factories;
- /**
+ /**
*/
- public MockSequencerOutput() {
- this.properties = new HashMap<Path, Object[]>();
- NamespaceRegistry registry = new BasicNamespaceRegistry();
- registry.register("jcr", "http://www.jcp.org/jcr/1.0");
- registry.register("mix", "http://www.jcp.org/jcr/mix/1.0");
- registry.register("nt", "http://www.jcp.org/jcr/nt/1.0");
- registry.register("dna", "http://www.jboss.org/dna/1.0");
- registry.register("dnadtd", "http://www.jboss.org/dna/1.0/dtd");
- registry.register("dnaxml", "http://www.jboss.org/dna/1.0/xml");
- factories = new StandardValueFactories(registry);
- }
+ public MockSequencerOutput() {
+ this.properties = new HashMap<Path, Object[]>();
+ NamespaceRegistry registry = new BasicNamespaceRegistry();
+ registry.register("jcr", "http://www.jcp.org/jcr/1.0");
+ registry.register("mix", "http://www.jcp.org/jcr/mix/1.0");
+ registry.register("nt", "http://www.jcp.org/jcr/nt/1.0");
+ registry.register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
+ registry.register("dnadtd",
"http://www.jboss.org/dna/dtd/1.0");
+ registry.register("dnaxml",
"http://www.jboss.org/dna/xml/1.0");
+ factories = new StandardValueFactories(registry);
+ }
- /**
- * {@inheritDoc}
- */
- public ValueFactories getFactories() {
- return this.factories;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactories getFactories() {
+ return this.factories;
+ }
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
- * @see org.jboss.dna.spi.sequencers.SequencerOutput#getNamespaceRegistry()
- */
- public NamespaceRegistry getNamespaceRegistry() {
- return factories.getNameFactory().getNamespaceRegistry();
- }
+ /**
+ * <p>
+ * {@inheritDoc}
+ * </p>
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerOutput#getNamespaceRegistry()
+ */
+ public NamespaceRegistry getNamespaceRegistry() {
+ return factories.getNameFactory().getNamespaceRegistry();
+ }
- /**
- * {@inheritDoc}
- */
- public void setProperty( Path nodePath,
- Name propertyName,
- Object... values ) {
- Path key = createKey(nodePath, propertyName);
- if (values == null || values.length == 0) {
- this.properties.remove(key);
- } else {
- this.properties.put(key, values);
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( Path nodePath,
+ Name propertyName,
+ Object... values ) {
+ Path key = createKey(nodePath, propertyName);
+ if (values == null || values.length == 0) {
+ this.properties.remove(key);
+ } else {
+ this.properties.put(key, values);
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public void setProperty( String nodePath,
- String propertyName,
- Object... values ) {
- Path path = this.factories.getPathFactory().create(nodePath);
- Name name = this.factories.getNameFactory().create(propertyName);
- setProperty(path, name, values);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( String nodePath,
+ String propertyName,
+ Object... values ) {
+ Path path = this.factories.getPathFactory().create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ setProperty(path, name, values);
+ }
- /**
- * {@inheritDoc}
- */
- public void setReference( String nodePath,
- String propertyName,
- String... paths ) {
- PathFactory pathFactory = this.factories.getPathFactory();
- Path path = pathFactory.create(nodePath);
- Name name = this.factories.getNameFactory().create(propertyName);
- Object[] values = null;
- if (paths != null && paths.length != 0) {
- values = new Path[paths.length];
- for (int i = 0, len = paths.length; i != len; ++i) {
- String pathValue = paths[i];
- values[i] = pathFactory.create(pathValue);
- }
- }
- setProperty(path, name, values);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void setReference( String nodePath,
+ String propertyName,
+ String... paths ) {
+ PathFactory pathFactory = this.factories.getPathFactory();
+ Path path = pathFactory.create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ Object[] values = null;
+ if (paths != null && paths.length != 0) {
+ values = new Path[paths.length];
+ for (int i = 0, len = paths.length; i != len; ++i) {
+ String pathValue = paths[i];
+ values[i] = pathFactory.create(pathValue);
+ }
+ }
+ setProperty(path, name, values);
+ }
- public Object[] getPropertyValues( String nodePath,
- String property ) {
- Path key = createKey(nodePath, property);
- return this.properties.get(key);
- }
+ public Object[] getPropertyValues( String nodePath,
+ String property ) {
+ Path key = createKey(nodePath, property);
+ return this.properties.get(key);
+ }
- public boolean hasProperty( String nodePath,
- String property ) {
- Path key = createKey(nodePath, property);
- return this.properties.containsKey(key);
- }
+ public boolean hasProperty( String nodePath,
+ String property ) {
+ Path key = createKey(nodePath, property);
+ return this.properties.containsKey(key);
+ }
- public boolean hasProperties() {
- return this.properties.size() > 0;
- }
+ public boolean hasProperties() {
+ return this.properties.size() > 0;
+ }
- protected Path createKey( String nodePath,
- String propertyName ) {
- Path path = this.factories.getPathFactory().create(nodePath);
- Name name = this.factories.getNameFactory().create(propertyName);
- return createKey(path, name);
- }
+ protected Path createKey( String nodePath,
+ String propertyName ) {
+ Path path = this.factories.getPathFactory().create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ return createKey(path, name);
+ }
- protected Path createKey( Path nodePath,
- Name propertyName ) {
- return this.factories.getPathFactory().create(nodePath, propertyName);
- }
+ protected Path createKey( Path nodePath,
+ Name propertyName ) {
+ return this.factories.getPathFactory().create(nodePath, propertyName);
+ }
}