stefan      2004/07/30 08:01:11

  Modified:    proposals/jcrri/src/org/apache/slide/jcr/core
                        AccessManagerImpl.java HierarchyManagerImpl.java
                        Path.java InternalValue.java PropertyImpl.java
                        Test.java TicketImpl.java WorkspaceImpl.java
                        NodeImpl.java
  Log:
  jcrri
  
  Revision  Changes    Path
  1.11      +2 -3      
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/AccessManagerImpl.java
  
  Index: AccessManagerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/AccessManagerImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AccessManagerImpl.java    30 Jul 2004 06:50:29 -0000      1.10
  +++ AccessManagerImpl.java    30 Jul 2004 15:01:10 -0000      1.11
  @@ -24,7 +24,6 @@
   package org.apache.slide.jcr.core;
   
   import org.apache.log4j.Logger;
  -import org.apache.slide.jcr.util.MalformedPathException;
   
   import javax.jcr.Credentials;
   import javax.jcr.ItemNotFoundException;
  
  
  
  1.6       +1 -2      
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/HierarchyManagerImpl.java
  
  Index: HierarchyManagerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/HierarchyManagerImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HierarchyManagerImpl.java 30 Jul 2004 06:50:29 -0000      1.5
  +++ HierarchyManagerImpl.java 30 Jul 2004 15:01:10 -0000      1.6
  @@ -25,7 +25,6 @@
   
   import org.apache.log4j.Logger;
   import org.apache.slide.jcr.core.state.*;
  -import org.apache.slide.jcr.util.MalformedPathException;
   
   import javax.jcr.ItemNotFoundException;
   import javax.jcr.PathNotFoundException;
  
  
  
  1.9       +2 -4      
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/Path.java
  
  Index: Path.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/Path.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Path.java 30 Jul 2004 06:50:29 -0000      1.8
  +++ Path.java 30 Jul 2004 15:01:10 -0000      1.9
  @@ -23,8 +23,6 @@
    */
   package org.apache.slide.jcr.core;
   
  -import org.apache.slide.jcr.util.MalformedPathException;
  -
   import javax.jcr.NamespaceException;
   import javax.jcr.PathNotFoundException;
   import java.util.ArrayList;
  
  
  
  1.10      +2 -3      
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/InternalValue.java
  
  Index: InternalValue.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/InternalValue.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- InternalValue.java        30 Jul 2004 06:50:29 -0000      1.9
  +++ InternalValue.java        30 Jul 2004 15:01:11 -0000      1.10
  @@ -24,7 +24,6 @@
   package org.apache.slide.jcr.core;
   
   import org.apache.slide.jcr.fs.FileSystemResource;
  -import org.apache.slide.jcr.util.MalformedPathException;
   import org.apache.slide.jcr.util.uuid.UUID;
   import org.apache.slide.jcr.util.ValueHelper;
   
  
  
  
  1.21      +2 -3      
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/PropertyImpl.java
  
  Index: PropertyImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/PropertyImpl.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- PropertyImpl.java 30 Jul 2004 06:50:29 -0000      1.20
  +++ PropertyImpl.java 30 Jul 2004 15:01:11 -0000      1.21
  @@ -30,7 +30,6 @@
   import org.apache.slide.jcr.core.state.PersistentPropertyState;
   import org.apache.slide.jcr.core.state.PropertyState;
   import org.apache.slide.jcr.util.IteratorHelper;
  -import org.apache.slide.jcr.util.MalformedPathException;
   import org.apache.slide.jcr.util.uuid.UUID;
   
   import javax.jcr.*;
  
  
  
  1.12      +8 -4      
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/Test.java
  
  Index: Test.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/Test.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Test.java 22 Jul 2004 16:14:22 -0000      1.11
  +++ Test.java 30 Jul 2004 15:01:11 -0000      1.12
  @@ -70,6 +70,8 @@
        Ticket t = r.login(new SimpleCredentials("anonymous", "".toCharArray()), null);
        Workspace wsp = t.getWorkspace();
   
  +     wsp.exportSysView("/", new FileOutputStream("d:/temp/export0.xml"), true, 
false);
  +
        NodeTypeManager ntMgr = wsp.getNodeTypeManager();
        NodeTypeIterator ntIter = ntMgr.getAllNodeTypes();
        while (ntIter.hasNext()) {
  @@ -92,7 +94,7 @@
        System.out.println();
        dumpTree(root, System.out);
   
  -     t.move("/foo", "/misc/bla");
  +     //t.move("/foo", "/misc/bla");
        System.out.println("after move...");
        System.out.println();
        dumpTree(root, System.out);
  @@ -109,7 +111,7 @@
            root.save();
        }
   
  -     //root.setProperty("blob", new FileInputStream(new File("d:/temp/jcrri.zip")));
  +     root.setProperty("blob", new FileInputStream(new File("d:/temp/jcrri.zip")));
   
        root.setProperty("bla", 1);
        root.setProperty("bla", 1.4);
  @@ -176,7 +178,7 @@
            imported = root.getNode("imported");
        }
   
  -     //importNode(new File("d:/dev/jcr/ri/src"), imported);
  +     importNode(new File("d:/dev/jcr/ri/src"), imported);
   
        if (root.hasNode("foo")) {
            root.remove("foo");
  @@ -219,6 +221,8 @@
        System.out.println("exiting...");
        System.out.println();
        ((WorkspaceImpl) wsp).dump(System.out);
  +
  +     wsp.exportSysView("/", new FileOutputStream("d:/temp/export1.xml"), false, 
false);
   
        repProps = ((RepositoryImpl) r).getProperties();
        System.out.println("repository properties:");
  
  
  
  1.19      +59 -25    
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/TicketImpl.java
  
  Index: TicketImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/TicketImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- TicketImpl.java   30 Jul 2004 06:50:29 -0000      1.18
  +++ TicketImpl.java   30 Jul 2004 15:01:11 -0000      1.19
  @@ -27,8 +27,8 @@
   import org.apache.slide.jcr.core.nodetype.*;
   import org.apache.slide.jcr.core.state.NodeState;
   import org.apache.slide.jcr.core.state.TicketItemStateManager;
  -import org.apache.slide.jcr.util.MalformedPathException;
  -import org.xml.sax.ContentHandler;
  +import org.xml.sax.*;
  +import org.xml.sax.helpers.XMLReaderFactory;
   
   import javax.jcr.*;
   import javax.jcr.access.AccessDeniedException;
  @@ -443,44 +443,78 @@
       }
   
       /**
  -     * @see Ticket#importXML(String, InputStream)
  +     * @see Ticket#getImportContentHandler(String)
        */
  -    public void importXML(String parentAbsPath, InputStream in)
  -         throws IOException, PathNotFoundException, ItemExistsException,
  -         ConstraintViolationException, InvalidSerializedDataException,
  -         RepositoryException {
  -     // @todo implement importXML
  -     throw new RepositoryException("Ticket.importXML() is not implemented yet.");
  -
  -     // @todo rewrite Deserializer to support xml document view 
  -/*
  +    public ContentHandler getImportContentHandler(String parentAbsPath) throws 
PathNotFoundException, RepositoryException {
        Item item = null;
        try {
            item = itemMgr.getItem(Path.create(parentAbsPath, getNamespaceResolver(), 
true));
        } catch (MalformedPathException mpe) {
  -         String msg = "invalid path: " + parentAbsPath;
  +         String msg = parentAbsPath + ": invalid path";
            log.error(msg, mpe);
            throw new RepositoryException(msg, mpe);
        } catch (AccessDeniedException ade) {
            throw new PathNotFoundException(parentAbsPath);
        }
        if (!item.isNode()) {
  -         log.error("node expected: " + parentAbsPath);
  -         throw new RepositoryException("node expected: " + parentAbsPath);
  +         String msg = parentAbsPath + ": node expected";
  +         log.error(msg);
  +         throw new RepositoryException(msg);
        }
        Node parent = (Node) item;
  -     Deserializer.deserialize(parent, in);
  -     // persist imported node tree
  -     parent.save();
  -*/
  +
  +     // @todo implement ContentHandler for asynchronuos import of document xml view
  +     throw new RepositoryException("Ticket.getImportContentHandler() is not 
implemented yet.");
       }
   
       /**
  -     * @see Ticket#getImportContentHandler(String)
  +     * @see Ticket#importXML(String, InputStream)
        */
  -    public ContentHandler getImportContentHandler(String parentAbsPath) throws 
PathNotFoundException, RepositoryException {
  -     // @todo implement ContentHandler for asynchronuos import of document xml view
  -     throw new RepositoryException("Ticket.getImportContentHandler() is not 
implemented yet.");
  +    public void importXML(String parentAbsPath, InputStream in)
  +         throws IOException, PathNotFoundException, ItemExistsException,
  +         ConstraintViolationException, InvalidSerializedDataException,
  +         RepositoryException {
  +     ContentHandler handler = getImportContentHandler(parentAbsPath);
  +     try {
  +         XMLReader parser = 
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
  +/*
  +         parser.setFeature("http://xml.org/sax/features/validation";, true);
  +         parser.setFeature("http://apache.org/xml/features/validation/schema";, 
true);
  +         
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking";, 
true);
  +*/
  +         parser.setContentHandler(handler);
  +         parser.setErrorHandler(new ErrorHandler() {
  +             public void error(SAXParseException exception) /*throws SAXException*/ 
{
  +                 log.error("error encountered while parsing XML stream", exception);
  +             }
  +
  +             public void fatalError(SAXParseException exception) /*throws 
SAXException*/ {
  +                 log.error("fatal error encountered while parsing XML stream", 
exception);
  +             }
  +
  +             public void warning(SAXParseException exception) /*throws 
SAXException*/ {
  +                 log.warn("warning encountered while parsing XML stream", 
exception);
  +             }
  +         });
  +/*
  +         // validate against system view schema
  +         URL urlSchema = 
this.class.getClassLoader().getResource("javax/jcr/systemview.xsd");
  +         
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";,
 urlSchema.toString());
  +         
parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation";,
  +                 urlSchema.toString() + " " + "http://www.jcp.org/jcr/sv/1.0";);
  +*/
  +         parser.parse(new InputSource(in));
  +     } catch (SAXException se) {
  +         // check for wrapped repository exception
  +         Exception e = se.getException();
  +         if (e != null && e instanceof RepositoryException) {
  +             throw (RepositoryException) e;
  +         } else {
  +             String msg = "failed to parse XML stream";
  +             log.error(msg, se);
  +             throw new InvalidSerializedDataException(msg, se);
  +         }
  +     }
       }
   
       /**
  
  
  
  1.12      +55 -37    
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/WorkspaceImpl.java
  
  Index: WorkspaceImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/WorkspaceImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- WorkspaceImpl.java        30 Jul 2004 06:50:29 -0000      1.11
  +++ WorkspaceImpl.java        30 Jul 2004 15:01:11 -0000      1.12
  @@ -26,8 +26,9 @@
   import org.apache.log4j.Logger;
   import org.apache.slide.jcr.core.nodetype.*;
   import org.apache.slide.jcr.core.state.*;
  -import org.apache.slide.jcr.util.MalformedPathException;
   import org.apache.slide.jcr.util.uuid.UUID;
  +import org.apache.xml.serialize.OutputFormat;
  +import org.apache.xml.serialize.XMLSerializer;
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
   
  @@ -932,7 +933,30 @@
        */
       public void exportDocView(String absPath, ContentHandler contentHandler, 
boolean binaryAsLink, boolean noRecurse)
            throws PathNotFoundException, SAXException, RepositoryException {
  +     // check path & retrieve state
  +     Path path;
  +     Path.PathElement name;
  +     PersistentNodeState state;
  +     try {
  +         path = Path.create(absPath, ticket.getNamespaceResolver(), true);
  +         name = path.getNameElement();
  +         state = getNodeState(path, hierMgr, persistentStateMgr);
  +     } catch (MalformedPathException mpe) {
  +         String msg = "invalid path: " + absPath;
  +         log.error(msg, mpe);
  +         throw new RepositoryException(msg, mpe);
  +     }
  +
  +     // check read access
  +     if (!ticket.getAccessManager().isGranted(state.getId(), Permission.READ_ITEM)) 
{
  +         throw new PathNotFoundException(absPath);
  +     }
        // @todo implement export of document xml view
  +/*
  +     new DocViewSAXEventGenerator(state, name.getName(), noRecurse, binaryAsLink,
  +             persistentStateMgr, (NamespaceRegistryImpl) rep.getNamespaceRegistry(),
  +             ticket.getAccessManager(), hierMgr, contentHandler).serialize();
  +*/
        throw new RepositoryException("not yet implemented");
       }
   
  @@ -941,8 +965,13 @@
        */
       public void exportDocView(String absPath, OutputStream out, boolean 
binaryAsLink, boolean noRecurse)
            throws IOException, PathNotFoundException, RepositoryException {
  -     // @todo implement export of document xml view
  -     throw new RepositoryException("not yet implemented");
  +     OutputFormat format = new OutputFormat("xml", "UTF-8", true);
  +     XMLSerializer serializer = new XMLSerializer(out, format);
  +     try {
  +         exportDocView(absPath, serializer.asContentHandler(), binaryAsLink, 
noRecurse);
  +     } catch (SAXException se) {
  +         throw new RepositoryException(se);
  +     }
       }
   
       /**
  @@ -950,51 +979,40 @@
        */
       public void exportSysView(String absPath, ContentHandler contentHandler, 
boolean binaryAsLink, boolean noRecurse)
            throws PathNotFoundException, SAXException, RepositoryException {
  -     // @todo implement export of system xml view
  -     // @todo rewrite sax event generator
  -     throw new RepositoryException("not yet implemented");
  -     /*
  -     Item item = null;
  -     try {
  -         item = itemMgr.getItem(Path.create(absPath, ticket.getNamespaceResolver(), 
true));
  +     // check path & retrieve state
  +     Path path;
  +     Path.PathElement name;
  +     PersistentNodeState state;
  +     try {
  +         path = Path.create(absPath, ticket.getNamespaceResolver(), true);
  +         name = path.getNameElement();
  +         state = getNodeState(path, hierMgr, persistentStateMgr);
        } catch (MalformedPathException mpe) {
            String msg = "invalid path: " + absPath;
            log.error(msg, mpe);
            throw new RepositoryException(msg, mpe);
  -     } catch (AccessDeniedException ade) {
  -         throw new PathNotFoundException(absPath);
        }
  -     if (!item.isNode()) {
  -         log.error("node expected: " + absPath);
  -         throw new RepositoryException("node expected: " + absPath);
  +
  +     // check read access
  +     if (!ticket.getAccessManager().isGranted(state.getId(), Permission.READ_ITEM)) 
{
  +         throw new PathNotFoundException(absPath);
        }
  -     new SAXEventGenerator((Node) item, noRecurse, binaryAsLink, 
contentHandler).serialize();
  -     */
  +
  +     new SysViewSAXEventGenerator(state, name.getName(), noRecurse, binaryAsLink,
  +             persistentStateMgr, (NamespaceRegistryImpl) rep.getNamespaceRegistry(),
  +             ticket.getAccessManager(), hierMgr, contentHandler).serialize();
       }
   
       /**
        * @see Workspace#exportSysView(String, OutputStream, boolean, boolean)
        */
       public void exportSysView(String absPath, OutputStream out, boolean 
binaryAsLink, boolean noRecurse) throws IOException, PathNotFoundException, 
RepositoryException {
  -     // @todo implement export of system xml view
  -     // @todo rewrite Serializer according to spec
  -     throw new RepositoryException("not yet implemented");
  -     /*
  -     Item item = null;
  +     OutputFormat format = new OutputFormat("xml", "UTF-8", true);
  +     XMLSerializer serializer = new XMLSerializer(out, format);
        try {
  -         item = itemMgr.getItem(Path.create(absPath, ticket.getNamespaceResolver(), 
true));
  -     } catch (MalformedPathException mpe) {
  -         String msg = "invalid path: " + absPath;
  -         log.error(msg, mpe);
  -         throw new RepositoryException(msg, mpe);
  -     } catch (AccessDeniedException ade) {
  -         throw new PathNotFoundException(absPath);
  -     }
  -     if (!item.isNode()) {
  -         log.error("node expected: " + absPath);
  -         throw new RepositoryException("node expected: " + absPath);
  +         exportSysView(absPath, serializer.asContentHandler(), binaryAsLink, 
noRecurse);
  +     } catch (SAXException se) {
  +         throw new RepositoryException(se);
        }
  -     new Serializer((Node) item, noRecurse, binaryAsLink, out).serialize();
  -     */
       }
   }
  
  
  
  1.29      +2 -3      
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/NodeImpl.java
  
  Index: NodeImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/NodeImpl.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- NodeImpl.java     30 Jul 2004 06:50:29 -0000      1.28
  +++ NodeImpl.java     30 Jul 2004 15:01:11 -0000      1.29
  @@ -29,7 +29,6 @@
   import org.apache.slide.jcr.core.version.VersionImpl;
   import org.apache.slide.jcr.util.ChildrenCollector;
   import org.apache.slide.jcr.util.IteratorHelper;
  -import org.apache.slide.jcr.util.MalformedPathException;
   import org.apache.slide.jcr.util.uuid.UUID;
   
   import javax.jcr.*;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to