Package org.apache.excalibur.source

Examples of org.apache.excalibur.source.TraversableSource


     *
     * @param source the traversable source whose ancestors shall be retrieved
     * @return a Stack containing the ancestors.
     */
    protected Stack getAncestors(TraversableSource source) throws IOException {
        TraversableSource parent = source;
        Stack ancestors = new Stack();

        while ((parent != null) && !isRoot(parent)) {
            parent = (TraversableSource) parent.getParent();
            if (parent != null) {
                ancestors.push(parent);
            } else {
                // no ancestor matched the root pattern
                ancestors.clear();
View Full Code Here


                        }
                    });
                } else if (sort.equals("collection")) {
                    Arrays.sort(contents.toArray(), new Comparator() {
                        public int compare(Object o1, Object o2) {
                            TraversableSource ts1 = (TraversableSource) o1;
                            TraversableSource ts2 = (TraversableSource) o2;

                            if (reverse) {
                                if (ts2.isCollection() && !ts1.isCollection())
                                    return -1;
                                if (!ts2.isCollection() && ts1.isCollection())
                                    return 1;
                                return ts2.getName().compareTo(ts1.getName());
                            }
                            if (ts2.isCollection() && !ts1.isCollection())
                                return 1;
                            if (!ts2.isCollection() && ts1.isCollection())
                                return -1;
                            return ts1.getName().compareTo(ts2.getName());
                        }
                    });
                }
               
                for (int i = 0; i < contents.size(); i++) {
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

        }
        return instance;
    }

    private static TraversableSource getCollection(String colName) {
      TraversableSource source;
        try {
            source = (TraversableSource) env.resolveURI(colName);
        } catch (MalformedURLException e) {
      throw new RuntimeException("'unable to resolve source: malformed URL");
        } catch (IOException e) {
      throw new RuntimeException("'unable to resolve source: IOException");
        }
        if (!source.isCollection()) throw new RuntimeException(colName + " is not a collection!");
        return source;
    }
View Full Code Here

        if (!source.isCollection()) throw new RuntimeException(colName + " is not a collection!");
        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!!");
//System.out.println("[param] " + name);
            if (name.startsWith("save:")) {
                Part part = (Part) request.get(name);
                String code = name.substring(5);
                if (!(collection instanceof ModifiableSource)) {
                  throw new RuntimeException("Cannot modify the given source");
               
                result = (ModifiableTraversableSource)env.resolveURI(collection.getURI() + "/" + code);
               
                save(part, result);
            } else if (name.startsWith("delete:")) {
                String value = request.getParameter(name);
                if (value.length() > 0) {              
View Full Code Here

    /**
     * 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

     * @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

           
            if (src.exists()) {
               
                boolean isCollection = false;
                if (src instanceof TraversableSource) {
                    TraversableSource traversableSource = (TraversableSource) src;
                    isCollection = traversableSource.isCollection();
                }
               
                boolean exists = type.equals("resource")
                    || type.equals("file") && !isCollection
                    || type.equals("directory") && isCollection;
View Full Code Here

        Publication pub = getPublication("test");

        Document doc = createResource(factory, pub, path, getManager(), getLogger());

        SourceResolver resolver = null;
        TraversableSource source = null;

        try {
            resolver = (SourceResolver) getManager().lookup(SourceResolver.ROLE);
            source = (TraversableSource) resolver.resolveURI(IMAGE_URL);

            assertEquals(doc.getMimeType(), source.getMimeType());
            assertEquals(doc.getContentLength(), source.getContentLength());

        } finally {
            if (resolver != null) {
                if (source != null) {
                    resolver.release(source);
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.