Package org.w3c.tools.resources

Examples of org.w3c.tools.resources.ResourceReference


  if (dresource != null) {
      String newcol = (String) request.getState(REMAINING_PATH);
      if (newcol != null) {
    if (dresource.getExtensibleFlag() && getPutableFlag()) {
        // create a new collection
        ResourceReference rr =
      dresource.createDirectoryResource(newcol);
        if (rr == null) {
      Reply error =
          request.makeReply(HTTP.UNSUPPORTED_MEDIA_TYPE);
      error.setContent("Failed to create collection "+
View Full Code Here


      DAVMultiStatus dms =
    DAVFactory.createMultiStatus(document.getDocumentElement());
      boolean multistatus = false;
      // Children resource
      Enumeration       e = dresource.enumerateResourceIdentifiers();
      ResourceReference rr   = null;
      FramedResource    fr   = null;
      while (e.hasMoreElements()) {
    String name = (String)e.nextElement();
    rr = dresource.lookup(name);
    if (rr != null) {
        try {
      fr = (FramedResource) rr.lock();
      if (fr == resource) { // for root
          continue;
      }
      DAVFrame df   = (DAVFrame)fr.getFrame(DAVFrame.class);
      URL      dest = null;
      if (df != null) {
          try {
        dest = computeDestURL(destination, df);
          } catch (MalformedURLException ex) {
        Reply error =
        request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
        String msg = "Can't build destination URI : "+
            ex.getMessage();
        error.setContent(msg);
        throw new HTTPException(error);
          }
          if (df.isCollection()) {
        try {
            // silent success
            df.copyCollection(dest,
                  request,
                  overwrite,
                  body,
                  document);
        } catch (MultiStatusException ex) {
            multistatus = true;
            ex.printStackTrace();
            ex.addResponses(document, dms);
        }
          } else {
        try {
            // silent success
            df.copyDAVResource(request,
                   df.getURL(request),
                   dest,
                   body);
        } catch (MultiStatusException ex) {
            multistatus = true;
            ex.printStackTrace();
            // add to multistatus node
            ex.addResponses(document, dms);
        }
          }
      } else {
          // what should I do there?
          // nothing I guess
      }
        } catch (InvalidResourceException ex) {
      // build error response?
        } finally {
      rr.unlock();
        }
    }
      }
      if (multistatus) {
    throw new MultiStatusException(document);
View Full Code Here

      DAVMultiStatus dms =
    DAVFactory.createMultiStatus(document.getDocumentElement());
      boolean multistatus = false;
      // Children resource
      Enumeration       e = dresource.enumerateResourceIdentifiers();
      ResourceReference rr   = null;
      FramedResource    fr   = null;
      while (e.hasMoreElements()) {
    String name = (String)e.nextElement();
    rr = dresource.lookup(name);
    if (rr != null) {
        try {
      fr = (FramedResource) rr.lock();
      if (fr == resource) { // for root
          continue;
      }
      DAVFrame df   = (DAVFrame)fr.getFrame(DAVFrame.class);
      URL      dest = null;
      if (df != null) {
          try {
        dest = computeDestURL(destination, df);
          } catch (MalformedURLException ex) {
        Reply error =
        request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
        String msg = "Can't build destination URI : "+
            ex.getMessage();
        error.setContent(msg);
        throw new HTTPException(error);
          }
          if (df.isCollection()) {
        try {
            // silent success
            df.internalCopyCollection(dest,
                    request,
                    overwrite,
                    body,
                    document);
        } catch (MultiStatusException ex) {
            multistatus = true;
            ex.printStackTrace();
            ex.addResponses(document, dms);
        }
          } else {
        try {
            // silent success
            df.internalCopyDAVResource(request,
                  df.getURL(request),
                  dest,
                        body);
        } catch (MultiStatusException ex) {
            multistatus = true;
            ex.printStackTrace();
            // add to multistatus node
            ex.addResponses(document, dms);
        }
          }
      } else {
          // what should I do there?
          // nothing I guess
      }
        } catch (InvalidResourceException ex) {
      // build error response?
        } finally {
      rr.unlock();
        }
    }
      }
      if (multistatus) {
    throw new MultiStatusException(document);
View Full Code Here

      }
      if (rtoken.equals(mytoken) && checkLockOwner(request)) {
    if (definesAttribute(ATTR_LOCK_TOKEN)) {
        unlock();
    } else {
        ResourceReference rr =
      (ResourceReference) request.getState(LOCKED_REREFENCE);
        if (rr == null) {
      Reply error =
          request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("Unable to unlock, no request state");
      throw new HTTPException(error);
        } else {
      try {
          DAVFrame fr = (DAVFrame)rr.lock();
          fr.unlock();
      } catch (Exception ex) {
          ex.printStackTrace();
          Reply error =
        request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
          error.setContent(ex.getMessage());
          throw new HTTPException(error);
      } finally {
          rr.unlock();
      }
        }
    }
    return request.makeReply(HTTP.NO_CONTENT);
      } else {
View Full Code Here

      updateStates(request);
  }
  if (ls.hasMoreComponents()) {
      if (request.getMethod().equals("PUT")) {
    String            name = ls.peekNextComponent() ;
    ResourceReference rr   = dresource.lookup(name);
    if ((rr == null) &&
        dresource.getExtensibleFlag() &&
        getPutableFlag()) {
        // the resource doesn't exists
        if (ls.countRemainingComponents() == 1) {
      rr = dresource.createResource(name, request);
      if (rr == null) {
          Reply error =
        request.makeReply(HTTP.UNSUPPORTED_MEDIA_TYPE);
          error.setContent(
             "Failed to create resource "+
             name +" : "+
             "Unable to create the appropriate file:"+
             request.getURLPath()+
             " this media type is not supported");
          throw new HTTPException (error);
      }
        } else { //FORBIDDEN IN WEBDAV
      Reply error = request.makeReply(HTTP.CONFLICT) ;
      error.setContent(name +" does not exists!");
      throw new HTTPException (error);
        }
    } else if (rr == null) {
        Reply error = request.makeReply(HTTP.FORBIDDEN) ;
        error.setContent("You are not allowed to create resource "+
             name +" : "+
             dresource.getIdentifier()+
             " is not extensible.");
        throw new HTTPException (error);
    }
      } else if (request.getMethod().equals("MKCOL")) {
    String            name = ls.peekNextComponent() ;
    ResourceReference rr   = dresource.lookup(name);
    if (rr == null) {
        if (ls.countRemainingComponents() == 1) {
      request.setState(REMAINING_PATH, name);
      return true;
        } else {
      Reply error = request.makeReply(HTTP.CONFLICT) ;
      error.setContent("Can't create "+
           ls.getRemainingPath(true));
      throw new HTTPException (error);
        }
    }
      }
  }
  // normal lookup
  if ( super.lookupOther(ls, lr) ) {
      if ( ! ls.isDirectory() && ! ls.isInternal() ) {
    // The directory lookup URL doesn't end with a slash:
    if ( request == null ) {
        lr.setTarget(null);
        return true;
    } else if (! acceptRedirect(request)) {
        return true;
    }
    URL url = null;
    try {
        if ((request != null ) &&
      request.hasState(Request.ORIG_URL_STATE)) {
      URL oldurl;
      oldurl = (URL)request.getState(Request.ORIG_URL_STATE);
      url = new URL(oldurl, oldurl.getFile() + "/");
        } else {
      url = (ls.hasRequest()
             ? getURL(request)
             : new URL(getServer().getURL(),
           resource.getURLPath()));
        }
    } catch (MalformedURLException ex) {
        getServer().errlog(this, "unable to build full URL.");
        throw new HTTPException("Internal server error");
    }
    String msg = "Invalid requested URL: the directory resource "+
        " you are trying to reach is available only through "+
        " its full URL: <a href=\""+
        url + "\">" + url + "</a>.";
    if ( getRelocateFlag() ) {
        // Emit an error (with reloc if allowed)
        Reply reloc = request.makeReply(HTTP.FOUND);
        reloc.setContent(msg) ;
        reloc.setLocation(url);
        lr.setTarget(null);
        lr.setReply(reloc);
        return true;
    } else {
        Reply error = request.makeReply(HTTP.NOT_FOUND) ;
        error.setContent(msg) ;
        lr.setTarget(null);
        lr.setReply(error);
        return true;
    }
      } else if ( ! ls.isInternal() && acceptRedirect(request) ) {
    request.setState(STATE_CONTENT_LOCATION, "true");
    // return the index file.
    String indexes[] = getIndexes();
    if (indexes != null) {
        for (int i = 0 ; i < indexes.length ; i++) {
      String index = indexes[i];
      if ( index != null && index.length() > 0) {
          DirectoryResource dir =
        (DirectoryResource) resource;
          ResourceReference rr = dir.lookup(index);
          if (rr != null) {
        try {
            FramedResource rindex =
          (FramedResource) rr.lock();
            return rindex.lookup(ls,lr);
        } catch (InvalidResourceException ex) {
        } finally {
            rr.unlock();
        }
          }
      }
        } 
    }
View Full Code Here

import org.w3c.tools.resources.ResourceReference;

public class StructureChangedEvent extends ResourceEvent {

    public String toString() {
  ResourceReference rr = (ResourceReference) getSource();
  String ssource = null;
  try {
      Resource resource = rr.lock();
      ssource = resource.getURLPath();
  } catch (InvalidResourceException ex) {
      ssource = "invalid";
  } catch (Exception ex) {
      ssource = "invalid"
  } finally {
      rr.unlock();
  }
  String stype = null;
  switch (id) {
  case Events.RESOURCE_CREATED:
      stype = "RESOURCE_CREATED";
View Full Code Here

    root.initialize(defs);
   
    NewStoreEntry entry = new NewStoreEntry(this,
              ROOT_REP,
              getRootKey());
    ResourceReference rr = entry.addResource(root, defs);
    ResourceContext context = (ResourceContext)
        defs.get("context");
    context.setResourceReference(rr);
    entry.saveResource(root);
    entries.put(getRootKey(), entry);
View Full Code Here

    }
      } catch (IOException ex) {
    return null;
      }
      // verify that the target resource is putable
      ResourceReference rr = request.getTargetResource();
      if (rr != null) {
    try {
        FramedResource target = (FramedResource) rr.lock();
        HTTPFrame frame = null;
        try {
      frame = (HTTPFrame) target.getFrame(
         Class.forName("org.w3c.jigsaw.frames.HTTPFrame"));
        } catch (ClassNotFoundException cex) {
      cex.printStackTrace();
      //big big problem ...
        }
        if (frame == null) // can't be putable
      return null;
        // now we can verify if the target resource is putable
        if (! frame.getPutableFlag()) {
      return null;
        }
        // and that the PUT can happen (taken from putFileResource
        int cim = frame.checkIfMatch(request);
        if ((cim == HTTPFrame.COND_FAILED)
      || (cim == HTTPFrame.COND_WEAK)
      || (frame.checkIfNoneMatch(request) ==
          HTTPFrame.COND_FAILED)
      || (frame.checkIfModifiedSince(request) ==
          HTTPFrame.COND_FAILED)
      || (frame.checkIfUnmodifiedSince(request) ==
          HTTPFrame.COND_FAILED)) {
      Reply r = request.makeReply(HTTP.PRECONDITION_FAILED);
      r.setContent("Pre-condition failed.");
      return r;
        }
    } catch (InvalidResourceException ex) {
        ex.printStackTrace();
        // problem ...
    } finally {
        rr.unlock();
    }
      }
      String expect = request.getExpect();
      if (expect != null) {
    if (expect.equalsIgnoreCase(HTTP.HTTP_100_CONTINUE)) {
View Full Code Here

    public Object getNewValue() {
  return newvalue;
    }

    public String toString() {
  ResourceReference rr = (ResourceReference) getSource();
  String ssource = null;
  String id = null;
  try {
      Resource resource = rr.lock();
      ssource = resource.getURLPath();
      id = resource.getIdentifier();
  } catch (InvalidResourceException ex) {
      ssource = "invalid";
  } catch (Exception ex) {
      ssource = "invalid"
  } finally {
      rr.unlock();
  }
  return ("AttributeChangedEvent : ["+ssource+
    " ("+id+")"+
    " : "+attr.getName()+
    " <- "+newvalue+"]");
View Full Code Here

     */

    private ResourceReference list = null;
    protected synchronized ResourceReference resolvePutListResource() {
  // Prepare for lookup:
  ResourceReference rr_root = null;
  rr_root = ((httpd) getServer()).getRootReference();
  FramedResource root = null;
  root = ((httpd) getServer()).getRoot();
  String       u  = getPutListURL();
  if ( u == null )
      return null;
  // Do the lookup:
  ResourceReference r_target = null;
  try {
      LookupState  ls = new LookupState(u);
      LookupResult lr = new LookupResult(rr_root);
      root.lookup(ls, lr);
      r_target = lr.getTarget();
  } catch (Exception ex) {
      r_target = null;
  }
  if (r_target != null) {
    try {
      Resource target = r_target.lock();
      if (! (target instanceof PutListResource) )
        r_target = null;
      else
        list = r_target;
    } catch (InvalidResourceException ex) {
      // continue
    } finally {
      r_target.unlock();
    }
  }
  return r_target;
    }
View Full Code Here

TOP

Related Classes of org.w3c.tools.resources.ResourceReference

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.