Package com.bradmcevoy.http

Examples of com.bradmcevoy.http.CollectionResource


                log.warn( "parent is not a collection: " + path );
                return null;
            }
        }

        CollectionResource parent = findNearestParent( manager, host, path.getParent() );
        return parent;
    }
View Full Code Here


        String dest = parameters.get( "destination");
        Path pDest = Path.path( dest );
        Resource rDestParent = resourceFactory.getResource( host, pDest.getParent().toString());
        if( rDestParent == null ) throw new BadRequestException( wrapped, "The destination parent does not exist");
        if(rDestParent instanceof CollectionResource ) {
            CollectionResource colDestParent = (CollectionResource) rDestParent;
            if( colDestParent.child( pDest.getName()) == null ) {
                try {
                    wrapped.copyTo( colDestParent, pDest.getName() );
                } catch( ConflictException ex ) {
                    log.warn( "Exception copying to: " + pDest.getName(), ex);
                    throw new BadRequestException( rDestParent, "conflict: " + ex.getMessage());
View Full Code Here

        String newName = args.get( 0 );
        log.debug( "mkdir. execute: " + newName );
        if( !cursor.isFolder() ) {
            return result( "current dir not found: " + cursor.getPath() );
        } else {
            CollectionResource cur = (CollectionResource) cursor.getResource();
            Result validationResult = validate( cur, newName );
            if( validationResult != null ) {
                return validationResult;
            }
            if( cur instanceof MakeCollectionableResource ) {
                MakeCollectionableResource mcr = (MakeCollectionableResource) cur;
                CollectionResource newCol;
                try {
                    newCol = doCreate( mcr, newName );
                } catch( BadRequestException ex) {
                    log.debug( "ex", ex );
                    return result( "BadRequestException exception: " + ex.getMessage() );
                } catch( ConflictException ex ) {
                    log.debug( "ex", ex );
                    return result( "conflict exception: " + ex.getMessage() );
                } catch( NotAuthorizedException ex ) {
                    log.debug( "ex", ex );
                    return result( "you are not authorized to create a folder here: " + ex.getMessage() );
                }
                Path newPath = cursor.getPath().child( newName );
                return new Result( cursor.getPath().toString(), "created: <a href='" + newPath + "'>" + newCol.getName() + "</a>" );
            } else {
                return result( "current dir does not support creating child collections: " + cursor.getPath() );
            }
        }
    }
View Full Code Here

            }
        }
    }

    protected CollectionResource doCreate(MakeCollectionableResource parent, String newName ) throws ConflictException, NotAuthorizedException, BadRequestException {
        CollectionResource col = parent.createCollection( newName );
        if( eventManager != null ) {
            eventManager.fireEvent( new NewFolderEvent( col));
        }
        return col;
    }
View Full Code Here

            log.debug( "target not found: " + srcPath );
            return result( "target not found: " + srcPath );
        } else {
            if( target instanceof MoveableResource ) {

                CollectionResource currentParent = (CollectionResource) sourceCursor.getParent().getResource();
                MoveableResource mv = (MoveableResource) target;
                try {
                    mv.moveTo( currentParent, destName );
                } catch( NotAuthorizedException e ) {
                    return result( "not authorised" );
View Full Code Here

    public Result execute() {
        Resource cur = currentResource();
        if( cur == null ) {
            return result("current dir not found: " + cursor.getPath().toString());
        }
        CollectionResource target;
        Cursor newCursor;
        if( args.size() > 0 ) {
            String dir = args.get(0);
            log.debug( "dir: " + dir);
            newCursor = cursor.find( dir );

            if( !newCursor.exists() ) {
                return result("not found: " + dir);
            } else if( !newCursor.isFolder() ) {
                return result("not a folder: " + dir);
            }
            target = (CollectionResource) newCursor.getResource();
        } else {
            newCursor = cursor;
            target = currentResource();
        }
        StringBuilder sb = new StringBuilder();
        List<? extends Resource> children = target.getChildren();
        sb.append( resultFormatter.begin( children));
        for( Resource r1 : target.getChildren() ) {
            String href = newCursor.getPath().child(r1.getName()).toString();
            sb.append(resultFormatter.format( href, r1 ));
        }
        sb.append( resultFormatter.end());
        return result(sb.toString());
View Full Code Here

        ByteArrayInputStream inputStream = new ByteArrayInputStream( content.getBytes());

        if( !cursor.isFolder() ) {
            return result("Couldnt find current folder");
        }
        CollectionResource cur = (CollectionResource) cursor.getResource();
        if( cur.child(newName) != null ) return result("File already exists: " + newName);

        if( cur instanceof PutableResource ) {
            PutableResource putable = (PutableResource) cur;
            try {
                putable.createNew( newName, inputStream, (long) content.length(), newName );
View Full Code Here

                }
            } else if( p.equals( "." ) ) {
                // do nothing
            } else {               
                if( child instanceof CollectionResource ) {
                    CollectionResource col = (CollectionResource) child;
                    child = col.child( p );
                    lastPath = Path.path( lastPath, p );
                    if( child == null ) {
                        String s = "child " + p + " not found in folder " + lastPath;
                        return new Cursor( resourceFactory, host, lastPath, null, s);
                    }
View Full Code Here

        if( !(r instanceof CollectionResource) ) {
            log.debug( "resource is not a collectionresource. is a: " + r.getClass());
            msg = "not a folder " + path;
            return null;
        }
        CollectionResource cur = (CollectionResource) r;
        Pattern pattern = null;
        try {
            log.debug("findWithWildCard: compiling " + sPattern);
            pattern = Pattern.compile(sPattern);
        } catch (Exception e) {
            msg = "Couldnt compile regular expression: " + sPattern;
            return null;
        }
        List<Resource> list = new ArrayList<Resource>();
        for (Resource res : cur.getChildren()) {
            Matcher m = pattern.matcher(res.getName());
            if (m.matches()) {
                log.debug("findWithWildCard: matches: " + res.getName());
                list.add(res);
            } else {
View Full Code Here

    private Result doCopy( Resource src, Resource dest, String name ) {
        if( src instanceof CopyableResource ) {
            CopyableResource cr = (CopyableResource) src;
            if( dest instanceof CollectionResource ) {
                CollectionResource destFolder = (CollectionResource) dest;
                try {
                    cr.copyTo( destFolder, name );
                } catch( NotAuthorizedException e ) {
                    return result( "not authorised" );
                } catch( BadRequestException e ) {
View Full Code Here

TOP

Related Classes of com.bradmcevoy.http.CollectionResource

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.