Package org.apache.excalibur.source

Examples of org.apache.excalibur.source.TraversableSource


                            }
                        });
                    } 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


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

        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

        SourceMeta meta;
       
        if (source instanceof TraversableSource) {
           
            final TraversableSourceMeta tmeta = new TraversableSourceMeta();
            final TraversableSource tsource = (TraversableSource) source;
           
            tmeta.setName(tsource.getName());
            tmeta.setIsCollection(tsource.isCollection());
           
            if (tmeta.isCollection()) {
                final Collection children = tsource.getChildren();
                if (children != null) {
                    final String[] names = new String[children.size()];
                    final Iterator iter = children.iterator();
                    int count = 0;
                    while(iter.hasNext()) {
                        TraversableSource child = (TraversableSource) iter.next();
                        names[count] = child.getName();
                        count++;
                    }
                    tmeta.setChildren(names);
                }
            }
View Full Code Here

            mimetype = source.getMimeType();
            contentlength = source.getContentLength();
            lastmodified = source.getLastModified();

            if (source instanceof TraversableSource) {
                TraversableSource traversablesource = (TraversableSource) source;
 
                iscollection = traversablesource.isCollection();

                name = traversablesource.getName();

                try {
                    if (iscollection && deep)
                        for(Iterator i = traversablesource.getChildren().iterator(); i.hasNext(); )
                            children.add(new SourceDTO((Source)i.next(), false));
                } catch (SourceException se) {}

                try {
                    if (deep && (traversablesource.getParent()!=null))
                        parent = new SourceDTO(traversablesource.getParent(), false);
                } catch (SourceException se) {}
            }

            if (source instanceof InspectableSource) {
                InspectableSource inspectablesource = (InspectableSource) source;
View Full Code Here

    }

    private static Source resolve(String uri)
    throws MalformedURLException, IOException {
        SourceResolver resolver = null;
        TraversableSource source;
        try {
            resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
            source = (TraversableSource) resolver.resolveURI(uri);
        } catch (ComponentException ce) {
            throw new IOException("ComponentException");
View Full Code Here

        }
        return source;
    }

    private static TraversableSource getCollection(String colName) {
      TraversableSource source;
        try {
            source = (TraversableSource)resolve(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)resolve(collection.getURI() + "/" + code);
               
                save(part, result);
            } else if (name.startsWith("delete:")) {
                String value = request.getParameter(name);
                if (value.length() > 0) {              
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.