Package org.apache.excalibur.source

Examples of org.apache.excalibur.source.TraversableSource


    /**
     * Returns the highest version id of the files included in the given
     * directory.
     */
    public static int getVersionID(String colName) {
        TraversableSource collection = getCollection(colName);
        int id = 0;
        Collection contents;
        try {
            contents = collection.getChildren();
        } catch (SourceException se) {
          throw new RuntimeException("Unable to list contents for collection " + colName);
        }
        for (Iterator iter = contents.iterator(); iter.hasNext();) {
            TraversableSource content = (TraversableSource) iter.next();
            if (!content.isCollection()) {
        try {
          int localid = getVersion(content.getName());
          if (localid > id) id = localid;
        } catch (Exception e) {}
                           
            }           
        }
View Full Code Here


       
        return ++id;
    }

    public static Object[] getVersions(String colName) {
      TraversableSource collection = getCollection(colName);
        ArrayList versions = new ArrayList();

    Collection contents;
    try {
      contents = collection.getChildren();
    } catch (SourceException se) {
      throw new RuntimeException("Unable to list contents for collection " + colName);
   

        for (Iterator iter = contents.iterator(); iter.hasNext();) {
            TraversableSource content = (TraversableSource) iter.next();
      if (!content.isCollection())  {
         try {
           int version = getVersion(content.getName());
           if (version > 0) {
             versions.add(new Integer(version));
           }
         } catch (Exception e) {}
       }
View Full Code Here

        }
        return -1;
    }
   
    public static int getID(String colName) {
        TraversableSource collection = getCollection(colName);

        int id = 0;
    Collection contents;
    try {
      contents = collection.getChildren();
    } catch (SourceException se) {
      throw new RuntimeException("Unable to list contents for collection " + colName);
    }
   
    for (Iterator iter = contents.iterator(); iter.hasNext();) {
            TraversableSource content = (TraversableSource) iter.next();
      if (content.isCollection())  {
        try {
          String name = content.getName();
          int localid = Integer.parseInt(name);
          if (localid > id) id = localid;
        } catch (Exception e) {}
      }          
        } 
View Full Code Here

     * @throws MetaDataException
     */
    public void write(String sourceUri) throws ServiceException, MalformedURLException,
            IOException, RepositoryException, DocumentException, MetaDataException {
        SourceResolver resolver = null;
        TraversableSource source = null;
        try {
            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
            source = (TraversableSource) resolver.resolveURI(sourceUri);
            write(source.getInputStream(),
                    source.getMimeType(),
                    source.getName(),
                    source.getContentLength());
        } finally {
            if (resolver != null) {
                if (source != null) {
                    resolver.release(source);
                }
View Full Code Here

    /**
     *
     */
    public Collection getChildren() throws RepositoryException {
        SourceResolver resolver = null;
        TraversableSource source = null;
        try {
            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
            source = (TraversableSource) resolver.resolveURI(this.contentSource.getRealSourceUri());
            Collection children = source.getChildren();
            java.util.Iterator iterator = children.iterator();
            java.util.Vector newChildren = new java.util.Vector();
            while (iterator.hasNext()) {
                TraversableSource child = (TraversableSource) iterator.next();
                newChildren.add(new SourceNode(getSession(),
                        getSourceURI() + "/" + child.getName(), this.manager, getLogger()));
            }
            return newChildren;
        } catch (Exception e) {
            throw new RepositoryException(e);
        }
View Full Code Here

    /**
     *
     */
    public boolean isCollection() throws RepositoryException {
        SourceResolver resolver = null;
        TraversableSource source = null;
        try {
            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
            source = (TraversableSource) resolver.resolveURI(this.contentSource.getRealSourceUri());
            return source.isCollection();
        } catch (Exception e) {
            throw new RepositoryException(e);
        }
    }
View Full Code Here

        }

        ByteArrayOutputStream out = null;
        InputStream in = null;
        SourceResolver resolver = null;
        TraversableSource source = null;
        try {
            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
            source = (TraversableSource) resolver.resolveURI(getRealSourceUri());

            if (source.exists() && !source.isCollection()) {
                byte[] buf = new byte[4096];
                out = new ByteArrayOutputStream();
                in = source.getInputStream();
                int read = in.read(buf);

                while (read > 0) {
                    out.write(buf, 0, read);
                    read = in.read(buf);
                }

                this.data = out.toByteArray();
                this.mimeType = source.getMimeType();
            }
        } catch (Exception e) {
            throw new RepositoryException(e);
        } finally {
            try {
View Full Code Here

        if (getLogger().isDebugEnabled()) {
            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

        if (! (dest instanceof ModifiableSource)) {
            throw new IllegalArgumentException("Non-writeable URI : " + dest.getURI());
        }
       
        if (dest instanceof TraversableSource) {
            TraversableSource trDest = (TraversableSource) dest;
            if (trDest.isCollection()) {
                if (src instanceof TraversableSource) {
                    dest = trDest.getChild(((TraversableSource)src).getName());
                } else if (src instanceof PartSource){
                    // FIXME : quick hack to store "upload://xxx" sources into directories
                    // it would be better for the PartSource to be Traversable, or to
                    // create a new "NamedSource" interface
                    dest = trDest.getChild(((PartSource)src).getPart().getFileName());
                }
            }
        }
       
        ModifiableSource wdest = (ModifiableSource)dest;
View Full Code Here

     * @throws  SAXException if an error occurs while outputting the document
     * @throws  ProcessingException if something went wrong while traversing
     *                              the source hierarchy
     */
    public void generate() throws SAXException, ProcessingException {
        TraversableSource inputSource = null;
        try {
            Source src = this.resolver.resolveURI(this.source);
            if (!(src instanceof TraversableSource)) {
                throw new SourceException(this.source + " is not a traversable source");
            }
            inputSource = (TraversableSource) this.resolver.resolveURI(this.source);

            if (!inputSource.exists()) {
                throw new ResourceNotFoundException(this.source + " does not exist.");
            }

            this.contentHandler.startDocument();
            this.contentHandler.startPrefixMapping(PREFIX, URI);
View Full Code Here

TOP

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

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.