jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r159394 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: WorkspaceImpl.java xml/WorkspaceImporter.java
Date Tue, 29 Mar 2005 16:34:49 GMT
Author: stefan
Date: Tue Mar 29 08:34:47 2005
New Revision: 159394

URL: http://svn.apache.org/viewcvs?view=rev&rev=159394
Log:
re-implementing Workspace.importXML [work in progress...]



Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java?view=diff&r1=159393&r2=159394
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java Tue
Mar 29 08:34:47 2005
@@ -44,13 +44,11 @@
 import org.apache.jackrabbit.core.version.VersionImpl;
 import org.apache.jackrabbit.core.version.VersionSelector;
 import org.apache.jackrabbit.core.xml.ImportHandler;
-import org.apache.jackrabbit.core.xml.WorkspaceImporter;
 import org.apache.jackrabbit.core.xml.Importer;
+import org.apache.jackrabbit.core.xml.WorkspaceImporter;
 import org.apache.log4j.Logger;
-import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
@@ -1603,73 +1601,6 @@
             throws PathNotFoundException, ConstraintViolationException,
             VersionException, LockException, RepositoryException {
 
-        /**
-         * the following code (importing through temporary session) is
-         * just a work-around; a specialized WorkspaceImporter that by-passes
-         * the transient layer should be used instead.
-         *
-         * todo replace with specialized WorkspaceImporter once fully implemented
-         */
-
-        // create temporary session in order to prevent state changes
-        // of the current session
-        final SessionImpl tmpSession = rep.createSession(session.getSubject(), getName());
-        final ContentHandler handler =
-                tmpSession.getImportContentHandler(parentAbsPath);
-        return new ContentHandler() {
-            public void endDocument() throws SAXException {
-                handler.endDocument();
-                // save changes & logout
-                try {
-                    tmpSession.save();
-                } catch (RepositoryException re) {
-                    throw new SAXException(re);
-                } finally {
-                    tmpSession.logout();
-                }
-            }
-
-            public void startDocument() throws SAXException {
-                handler.startDocument();
-            }
-
-            public void characters(char ch[], int start, int length) throws SAXException
{
-                handler.characters(ch, start, length);
-            }
-
-            public void ignorableWhitespace(char ch[], int start, int length) throws SAXException
{
-                handler.ignorableWhitespace(ch, start, length);
-            }
-
-            public void endPrefixMapping(String prefix) throws SAXException {
-                handler.endPrefixMapping(prefix);
-            }
-
-            public void skippedEntity(String name) throws SAXException {
-                handler.endPrefixMapping(name);
-            }
-
-            public void setDocumentLocator(Locator locator) {
-                handler.setDocumentLocator(locator);
-            }
-
-            public void processingInstruction(String target, String data) throws SAXException
{
-                handler.processingInstruction(target, data);
-            }
-
-            public void startPrefixMapping(String prefix, String uri) throws SAXException
{
-                handler.startPrefixMapping(prefix, uri);
-            }
-
-            public void endElement(String namespaceURI, String localName, String qName) throws
SAXException {
-                handler.endElement(namespaceURI, localName, qName);
-            }
-
-            public void startElement(String namespaceURI, String localName, String qName,
Attributes atts) throws SAXException {
-                handler.startElement(namespaceURI, localName, qName, atts);
-            }
-        };
-/*
         // check state of this instance
         sanityCheck();
 
@@ -1696,7 +1627,6 @@
                 rep.getNodeTypeRegistry(), uuidBehavior);
         return new ImportHandler(importer, session.getNamespaceResolver(),
                 rep.getNamespaceRegistry());
-*/
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java?view=diff&r1=159393&r2=159394
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
Tue Mar 29 08:34:47 2005
@@ -635,6 +635,15 @@
             if (node == null) {
                 // there's no node with that name...
                 if (uuid == null) {
+                    ChildNodeDef def =
+                            wsp.findApplicableNodeDefinition(nodeName, ntName, parent);
+                    if (def.isProtected()) {
+                        // skip protected node
+                        parents.push(null); // push null onto stack for skipped node
+                        log.debug("skipping protected node " + nodeName);
+                        return;
+                    }
+
                     // no potential uuid conflict, always create new node:
                     // check if new node can be added (check access rights &
                     // node type constraints only, assume locking & versioning status
@@ -681,22 +690,23 @@
                 int type = pi.getType();
 
                 PropertyState prop = null;
+                PropDef def = null;
 
                 if (node.hasPropertyEntry(propName)) {
                     // a property with that name already exists...
                     PropertyId idExisting = new PropertyId(node.getUUID(), propName);
                     PropertyState existing =
                             (PropertyState) stateMgr.getItemState(idExisting);
-                    PropDef propDef = ntReg.getPropDef(existing.getDefinitionId());
-                    if (propDef.isProtected()) {
+                    def = ntReg.getPropDef(existing.getDefinitionId());
+                    if (def.isProtected()) {
                         // skip protected property
                         log.debug("skipping protected property "
                                 + resolveJCRPath(idExisting));
                         continue;
                     }
-                    if (propDef.isAutoCreate() && (existing.getType() == type
+                    if (def.isAutoCreate() && (existing.getType() == type
                             || type == PropertyType.UNDEFINED)
-                            && propDef.isMultiple() == existing.isMultiValued())
{
+                            && def.isMultiple() == existing.isMultiValued()) {
                         // this property has already been auto-created,
                         // no need to create it
                         prop = existing;
@@ -706,28 +716,52 @@
                 }
                 if (prop == null) {
                     // there's no property with that name,
+                    // find applicable definition
+
+                    // multi- or single-valued property?
+                    if (vals.length == 1) {
+                        // could be single- or multi-valued (n == 1)
+                        try {
+                            // try single-valued
+                            def = wsp.findApplicablePropertyDefinition(propName,
+                                    type, false, parent);
+                        } catch (ConstraintViolationException cve) {
+                            // try multi-valued
+                            def = wsp.findApplicablePropertyDefinition(propName,
+                                    type, true, parent);
+                        }
+                    } else {
+                        // can only be multi-valued (n == 0 || n > 1)
+                        def = wsp.findApplicablePropertyDefinition(propName,
+                                type, true, parent);
+                    }
+
+                    if (def.isProtected()) {
+                        // skip protected property
+                        log.debug("skipping protected property " + propName);
+                        continue;
+                    }
+
                     // create new property
-                    prop = createProperty(node, propName, type, vals.length);
+                    prop = createProperty(node, propName, type, def);
                 }
 
-                PropDef propDef = ntReg.getPropDef(prop.getDefinitionId());
-
                 // check multi-valued characteristic
-                if ((vals.length == 0 || vals.length > 1) && !propDef.isMultiple())
{
+                if ((vals.length == 0 || vals.length > 1) && !def.isMultiple())
{
                     throw new ConstraintViolationException(resolveJCRPath(prop.getId())
                             + " is not multi-valued");
                 }
 
                 // check whether type conversion is required
-                if (propDef.getRequiredType() != PropertyType.UNDEFINED
-                        && propDef.getRequiredType() != type) {
+                if (def.getRequiredType() != PropertyType.UNDEFINED
+                        && def.getRequiredType() != type) {
                     // type doesn't match required type,
                     // type conversion required
                     for (int i = 0; i < vals.length; i++) {
                         // convert InternalValue to Value of required type
                         Value v =
                                 ValueHelper.convert(vals[i].toJCRValue(nsContext),
-                                        propDef.getRequiredType());
+                                        def.getRequiredType());
                         // convert Value to InternalValue using
                         // current namespace context of xml document
                         vals[i] = InternalValue.create(v, nsContext);



Mime
View raw message