Package com.bradmcevoy.common

Examples of com.bradmcevoy.common.Path$LengthComparator


  }

  @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) {
View Full Code Here


        String name;
        if (log.isDebugEnabled()) {
            log.debug("process request: host: " + host + " url: " + finalurl);
        }

        Path finalpath = Path.path(finalurl); //this is the parent collection it goes in
        name = finalpath.getName();
        Path parent = finalpath.getParent();
        String parenturl = parent.toString();

        Resource parentcol = manager.getResourceFactory().getResource(host, parenturl);
        if (parentcol != null) {
            log.debug("process: resource: " + parentcol.getClass().getName());
View Full Code Here

            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());
                    return new AjaxLoginResource( pathFull.getName(), gr );
                } else {
                    return r;
                }
            }
        }
View Full Code Here

    this.propPatchHandler = new JsonPropPatchHandler(patchSetter, permissionService, eventManager);
  }

  public Resource getResource(String host, String sPath) {
    LogUtils.trace(log, "getResource", host, sPath);
    Path path = Path.path(sPath);
    Path parent = path.getParent();
    Request request = HttpManager.request();
    String encodedPath = request.getAbsolutePath();

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

        if( dest == null ) {
            throw new BadRequestException(this, "The destination parameter is null");
        } else if (dest.trim().length() == 0 ) {
            throw new BadRequestException(this, "The destination parameter is empty");
        }
        Path pDest = Path.path( dest );
        if( pDest == null ) {
            throw new BadRequestException(this, "Couldnt parse the destination header, returned null from: " + dest);
        }
        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 {
                    System.out.println("move to: " + colDestParent.getName());
                    wrapped.moveTo( colDestParent, pDest.getName() );
                } catch( ConflictException ex ) {
                    log.warn( "Exception copying to: " + pDest.getName(), ex);
                    throw new BadRequestException( rDestParent, "conflict: " + ex.getMessage());
                }
                return null;
            } else {
                log.warn( "destination already exists: " + pDest.getName() + " in folder: " + colDestParent.getName());
                throw new BadRequestException( rDestParent, "File already exists");
            }
        } else {
            throw new BadRequestException( wrapped, "The destination parent is not a collection resource");
        }
View Full Code Here

    }


    public Resource getResource( String host, String path ) {
        log.debug( "getResource: " + path );
        Path p = Path.path( path );
        log.debug( "length: " + p.getLength() );
        if( p.getLength() == 0 ) {
            return new AllMakes( this, sm );
        } else if( p.getLength() == 1 ) {
            if( p.getName().equals( "allvehicles.csv")) {
                return new AllVehiclesCsv( "allvehicles.csv", this, sm, vehicleDao);
            } else {
                return new VehicleMake( this, sm, p.getName() );
            }
        } else if( p.getLength() == 2 ) {
            VehicleMake makeResource = new VehicleMake( this, sm, p.getParent().getName() );
            return makeResource.child( p.getName());
        } else {
            return null;
        }
    }
View Full Code Here

        String host = request.getHostHeader();
        String urlToCreateOrUpdate = HttpManager.decodeUrl( request.getAbsolutePath() );
        log.debug( "process request: host: " + host + " url: " + urlToCreateOrUpdate );

        Path path = Path.path( urlToCreateOrUpdate );
        urlToCreateOrUpdate = path.toString();

        Resource existingResource = manager.getResourceFactory().getResource( host, urlToCreateOrUpdate );
        ReplaceableResource replacee;

        StorageErrorReason storageErr = null;
        if( existingResource != null ) {
            //Make sure the parent collection is not locked by someone else
            if( handlerHelper.isLockedOut( request, existingResource ) ) {
                log.warn( "resource is locked, but not by the current user" );
                respondLocked( request, response, existingResource );
                return;
            }
            Resource parent = manager.getResourceFactory().getResource( host, path.getParent().toString() );
            if( parent instanceof CollectionResource ) {
                CollectionResource parentCol = (CollectionResource) parent;
                storageErr = handlerHelper.checkStorageOnReplace( request, parentCol, existingResource, host );
            } else {
                log.warn( "parent exists but is not a collection resource: " + path.getParent() );
            }
        } else {
            CollectionResource parentCol = putHelper.findNearestParent( manager, host, path );
            storageErr = handlerHelper.checkStorageOnAdd( request, parentCol, path.getParent(), host );
        }

        if( storageErr != null ) {
            respondInsufficientStorage( request, response, storageErr );
            return;
        }

        if( existingResource != null && existingResource instanceof ReplaceableResource ) {
            replacee = (ReplaceableResource) existingResource;
        } else {
            replacee = null;
        }

        if( replacee != null ) {
            if( log.isTraceEnabled() ) {
                log.trace( "replacing content in: " + replacee.getName() + " - " + replacee.getClass() );
            }
            long t = System.currentTimeMillis();
            try {
                manager.onProcessResourceStart( request, response, replacee );
                processReplace( manager, request, response, replacee );
            } finally {
                t = System.currentTimeMillis() - t;
                manager.onProcessResourceFinish( request, response, replacee, t );
            }
        } else {
            // either no existing resource, or its not replaceable. check for folder
            String nameToCreate = path.getName();
            CollectionResource folderResource = findOrCreateFolders( manager, host, path.getParent() );
            if( folderResource != null ) {
                long t = System.currentTimeMillis();
                try {
                    if( folderResource instanceof PutableResource ) {
View Full Code Here

    public void processExistingResource( HttpManager manager, Request request, Response response, Resource resource ) throws NotAuthorizedException, BadRequestException, ConflictException {
        String host = request.getHostHeader();
        String urlToCreateOrUpdate = HttpManager.decodeUrl( request.getAbsolutePath() );
        log.debug( "process request: host: " + host + " url: " + urlToCreateOrUpdate );

        Path path = Path.path( urlToCreateOrUpdate );
        urlToCreateOrUpdate = path.toString();

        Resource existingResource = manager.getResourceFactory().getResource( host, urlToCreateOrUpdate );
        ReplaceableResource replacee;

        if( existingResource != null ) {
            //Make sure the parent collection is not locked by someone else
            if( handlerHelper.isLockedOut( request, existingResource ) ) {
                log.warn( "resource is locked, but not by the current user" );
                response.setStatus( Status.SC_LOCKED ); //423
                return;
            }

        }
        if( existingResource != null && existingResource instanceof ReplaceableResource ) {
            replacee = (ReplaceableResource) existingResource;
        } else {
            replacee = null;
        }

        if( replacee != null ) {
            processReplace( manager, request, response, (ReplaceableResource) existingResource );
        } else {
            // either no existing resource, or its not replaceable. check for folder
            String urlFolder = path.getParent().toString();
            String nameToCreate = path.getName();
            CollectionResource folderResource = findOrCreateFolders( manager, host, path.getParent() );
            if( folderResource != null ) {
                if( log.isDebugEnabled() ) {
                    log.debug( "found folder: " + urlFolder + " - " + folderResource.getClass() );
                }
                if( folderResource instanceof PutableResource ) {
View Full Code Here

     * @param url
     */
    private void processNonExistingResource( HttpManager manager, Request request, Response response, String host, String url ) throws NotAuthorizedException {
        String name;

        Path parentPath = Path.path( url );
        name = parentPath.getName();
        parentPath = parentPath.getParent();
        url = parentPath.toString();

        Resource r = manager.getResourceFactory().getResource( host, url );
        if( r != null ) {
            if( !handlerHelper.checkAuthorisation( manager, r, request ) ) {
                responseHandler.respondUnauthorised( r, response, request );
View Full Code Here

        return list;
    }

    public Resource getResource( String host, String url ) {
        log.debug( "getResource: url: " + url );
        Path path = Path.path( url );
        Resource r = find( path );
        log.debug( "_found: " + r + " for url: " + url + " and path: " + path );
        return r;
    }
View Full Code Here

TOP

Related Classes of com.bradmcevoy.common.Path$LengthComparator

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.