Package com.bradmcevoy.http

Examples of com.bradmcevoy.http.Resource


        allChildren.add( createResource( "a3" ) );
        return allChildren;
    }

    private Resource createResource(String name) {
        Resource r = createMock( Resource.class );
        expect(r.getName()).andReturn( name ).anyTimes();
        replay(r);
        return r;
    }
View Full Code Here


        Element elMulti = new Element( "multistatus", NS_DAV );
        Document resp = new Document( elMulti );
        List<PropFindResponse> respProps = new ArrayList<PropFindResponse>();

        for( String href : hrefs ) {
            Resource r = resourceFactory.getResource( host, href );
            if( r != null ) {
                if( r instanceof PropFindableResource ) {
                    PropFindableResource pfr = (PropFindableResource) r;
                    respProps.addAll( propertyBuilder.buildProperties( pfr, 0, parseResult, href ) );
                } else {
View Full Code Here

    public ResourceAndPath getResource( Path p ) {
        log.debug( "getResource: " + p );
        if( p.isRelative() ) {
            p = Path.path( currentPath.toString() + '/' + p.toString() );
            Resource r = resourceFactory.getResource( user.domain, p.toString() );
            return new ResourceAndPath( r, p );
        } else {
            Resource r = resourceFactory.getResource( user.domain, p.toString() );
            return new ResourceAndPath( r, p );
        }
    }
View Full Code Here

  @Override
  public Resource getResource(String host, String path) {
    if (path.endsWith("/" + suffix)) {
      Path p = Path.path(path);
      String realPath = p.getParent().toString();
      Resource r = wrapped.getResource(host, realPath);
      if (r == null) {
        return null;
      } else {
        if (r instanceof GetableResource) {
          return new ZSyncAdapterResource((GetableResource) r, realPath, host);
View Full Code Here

          StreamUtils.close(fin);
        }
      } else {
        log.trace("updateResourceContentActual: " + mergedFile.getAbsolutePath() + ", resource is NOT replaceable, try to replace through parent");
        String parentPath = Path.path(realPath).getParent().toString();
        Resource rParent = wrapped.getResource(host, parentPath);
        if (rParent == null) {
          throw new RuntimeException("Failed to locate parent resource to update contents. parent: " + parentPath + " host: " + host);
        }
        if (rParent instanceof PutableResource) {
          log.trace("found parent resource, implements PutableResource");
          FileInputStream fin = null;
          try {
            fin = new FileInputStream(mergedFile);
            PutableResource putable = (PutableResource) rParent;
            putable.createNew(r.getName(), fin, mergedFile.length(), r.getContentType(null));
          } finally {
            StreamUtils.close(fin);
          }
        } else {
          throw new RuntimeException("Tried to update non-replaceable resource by doing createNew on parent, but the parent doesnt implement PutableResource. parent path: " + parentPath + " host: " + host + " parent type: " + rParent.getClass());
        }
      }


    }
View Full Code Here

        this.resourceFactory = resourceFactory;
    }
    public String processForm( Map<String, String> parameters, Map<String, FileItem> files ) throws BadRequestException, NotAuthorizedException {
        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 {
View Full Code Here

    public Resource getResource( String host, String path ) {
        if(path.endsWith( suffix )) {
            int i = path.lastIndexOf( suffix);
            String p2 = path.substring( 0, i);
            Resource r = wrapped.getResource( host, p2);
            if( r != null) {
                if( r instanceof GetableResource) {
                    GetableResource gr = (GetableResource) r;
                    Path pathFull = Path.path( path );
                    log.debug( "found an ajax resource, wrapping a: " + gr.getClass());
View Full Code Here

    // This is to support a use case where a developer wants their resources to
    // be accessible through milton-json, but don't want to use DAV urls. Instead
    // they use a parameter and DO NOT implement PostableResource.
    if (request.getMethod().equals(Method.POST)) {
      Resource wrappedResource = wrapped.getResource(host, sPath);
      if (wrappedResource != null && !(wrappedResource instanceof PostableResource)) {
        LogUtils.trace(log, "getResource: is post, and got a: ", wrappedResource.getClass());
        return new PostJsonResource(host, encodedPath, wrappedResource, methodParamName, this);
      }
    }
    if (request.getMethod().equals(Method.GET) && isMatchingContentType(request.getAcceptHeader())) {
      Resource wrappedResource = wrapped.getResource(host, sPath);
      if (wrappedResource != null) {
        log.trace("getResource: matches content type, and found wrapped resource");
        return wrapResource(host, wrappedResource, Method.PROPFIND.code, encodedPath);
      } else {
        LogUtils.trace(log, "getResource: is GET and matched type, but found no actual resource on", sPath);
      }
    }
    if (isMatchingPath(parent)) {
      log.trace("getResource: is matching path");
      Path resourcePath = parent.getParent();
      if (resourcePath != null) {
        String method = path.getName();
        Resource wrappedResource = wrapped.getResource(host, resourcePath.toString());
        if (wrappedResource != null) {
          return wrapResource(host, wrappedResource, method, encodedPath);
        }
      }
    } else {
View Full Code Here

        }
        String parentPath = "/";
        if( pDest.getParent() != null ) {
            parentPath = pDest.getParent().toString();
        }
        Resource rDestParent = resourceFactory.getResource( host, parentPath);
        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 {
View Full Code Here


    public CollectionResource findNearestParent( HttpManager manager, String host, Path path ) throws NotAuthorizedException, ConflictException {
        if( path == null ) return null;

        Resource thisResource = manager.getResourceFactory().getResource( host, path.toString() );
        if( thisResource != null ) {
            if( thisResource instanceof CollectionResource ) {
                return (CollectionResource) thisResource;
            } else {
                log.warn( "parent is not a collection: " + path );
View Full Code Here

TOP

Related Classes of com.bradmcevoy.http.Resource

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.