Package org.apache.excalibur.source

Examples of org.apache.excalibur.source.ModifiableTraversableSource


     * @throws IOException
     */
    public static void deleteEmptyCollections(String sourceUri, ServiceManager manager)
            throws ServiceException, MalformedURLException, IOException {
        SourceResolver resolver = null;
        ModifiableTraversableSource source = null;
        try {
            resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
            source = (ModifiableTraversableSource) resolver.resolveURI(sourceUri);
            if (source.isCollection()) {
                for (Iterator i = source.getChildren().iterator(); i.hasNext();) {
                    ModifiableTraversableSource child = (ModifiableTraversableSource) i.next();
                    deleteEmptyCollections(child.getURI(), manager);
                }
                if (source.getChildren().size() == 0) {
                    source.delete();
                }
            }
View Full Code Here


        return source;
    }

    public static void save(Request request, String dirName) throws Exception {
        TraversableSource collection = getCollection(dirName);
        ModifiableTraversableSource result;

        Enumeration params = request.getParameterNames();
        while (params.hasMoreElements()) {
            String name = (String) params.nextElement();
            if (name.indexOf("..") > -1) throw new Exception("We are under attack!!");
View Full Code Here

        contents = resource.getChildren();
      } catch (SourceException se) {
        throw new RuntimeException("Unable to list contents for collection " + resource);
      }
      for (Iterator iter = contents.iterator(); iter.hasNext();) {
                ModifiableTraversableSource element = (ModifiableTraversableSource) iter.next();
                success = remove(element);
            }

        }
        try {
View Full Code Here

        contents = from.getChildren();
      } catch (SourceException se) {
        throw new RuntimeException("Unable to list contents for collection " + from);
      }
      for (Iterator iter = contents.iterator(); iter.hasNext();) {
        ModifiableTraversableSource src = (ModifiableTraversableSource) iter.next();
        SourceUtil.copy(src, resolve(to.getURI() + "/" + src.getName()));

      }
        } else {
            to = (ModifiableTraversableSource)resolve(to.getURI());
            InputStream in = null;
View Full Code Here

            getLogger().debug("copy: " + source.getURI() + " -> " + destination.getURI());
        }
       
        if (source instanceof TraversableSource) {
            final TraversableSource origin = (TraversableSource) source;
            ModifiableTraversableSource target = null;
            if (origin.isCollection()) {
                if (!(destination instanceof ModifiableTraversableSource)) {
                    final String message = "copy() is forbidden: " +
                        "Cannot create a collection at the indicated destination.";
                    getLogger().warn(message);
                    return STATUS_FORBIDDEN;
                }
                // TODO: copy properties
                target = ((ModifiableTraversableSource) destination);
                target.makeCollection();
                if (recurse) {
                    Iterator children = origin.getChildren().iterator();
                    while (children.hasNext()) {
                        TraversableSource child = (TraversableSource) children.next();
                        int status = copy(child,target.getChild(child.getName()),recurse);
                        // TODO: record this status
                        // according to the spec we must continue moving files even though
                        // a part of the move has not succeeded
                    }
                }
View Full Code Here

   
    // ---------------------------------------------------- ModifiableTraversableSource
   
    public Source getChild(String name) throws SourceException {
        if (!m_delegate.isCollection()) return null;
        ModifiableTraversableSource child = (ModifiableTraversableSource) m_delegate.getChild(name);
        if (child == null) return null;
       
        return new RepositorySource(
            m_prefix,
            child,
View Full Code Here

    public Collection getChildren() throws SourceException {
        if (!m_delegate.isCollection()) return null;
      Collection result = new ArrayList();
    Iterator iter = m_delegate.getChildren().iterator();
      while(iter.hasNext()) {
            ModifiableTraversableSource child = (ModifiableTraversableSource) iter.next();
           
        result.add(
                new RepositorySource(
                    m_prefix,
                    child,
View Full Code Here

            getLogger().debug("copy: " + source.getURI() + " -> " + destination.getURI());
        }
       
        if (source instanceof TraversableSource) {
            final TraversableSource origin = (TraversableSource) source;
            ModifiableTraversableSource target = null;
            if (origin.isCollection()) {
                if (!(destination instanceof ModifiableTraversableSource)) {
                    final String message = "copy() is forbidden: " +
                        "Cannot create a collection at the indicated destination.";
                    getLogger().warn(message);
                    return STATUS_FORBIDDEN;
                }
                // TODO: copy properties
                target = ((ModifiableTraversableSource) destination);
                m_interceptor.preStoreSource(target);
                target.makeCollection();
                m_interceptor.postStoreSource(target);
                if (recurse) {
                    Iterator children = origin.getChildren().iterator();
                    while (children.hasNext()) {
                        TraversableSource child = (TraversableSource) children.next();
                        /*int status =*/ copy(child,target.getChild(child.getName()),recurse);
                        // TODO: record this status
                        // according to the spec we must continue moving files even though
                        // a part of the move has not succeeded
                    }
                }
View Full Code Here

        assertFalse(source.exists());
    }

    public void testDeleteDir() throws Exception {
        String text = "Wow, a lot of data going there";
        ModifiableTraversableSource source = (ModifiableTraversableSource)resolver.resolveURI("jcr://and/again/a/deep/node");

        assertFalse(source.exists());
        write(source, text);

        // Lookup 'a' node
        source = (ModifiableTraversableSource)resolver.resolveURI("jcr://and/again/a/");
        assertTrue(source.isCollection());
        source.delete();
        assertFalse(source.exists());

        // Double check with a fresh source
        source = (ModifiableTraversableSource)resolver.resolveURI("jcr://and/again/a/");
        assertFalse(source.exists());

        // Check on children
        source = (ModifiableTraversableSource)resolver.resolveURI("jcr://and/again/a/deep/node");
        assertFalse(source.exists());
    }
View Full Code Here

    }

    public void testTraverseDir() throws Exception {
        String text = "Look Ma, more data!";

        ModifiableTraversableSource dir = (ModifiableTraversableSource)resolver.resolveURI("jcr://path/to/dir");
        dir.makeCollection();

        for (int i = 0; i < 10; i++) {
            ModifiableTraversableSource src = (ModifiableTraversableSource)dir.getChild("file" + i);
            write(src, text + i);
        }

        // Lookup dir again, and inspect children
        dir = (ModifiableTraversableSource)resolver.resolveURI("jcr://path/to/dir");
        Collection children = dir.getChildren();

        assertEquals(10, children.size());

        for (int i = 0; i < 10; i++) {
            Source src = dir.getChild("file" + i);
            assertTrue(src.exists());
            assertEquals(text + i, read(src));
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.excalibur.source.ModifiableTraversableSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.