Package org.w3c.tools.resources

Examples of org.w3c.tools.resources.ResourceReference


             httpd server,
             ResourceReference sdir)
    {
  String uri  = SERVLET_BASE_P+"/"+name;
  // internal lookup
  ResourceReference rr = server.getEditRoot();
  try {
      FramedResource root = (FramedResource) rr.lock();
      try {
    DirectoryResource parent = (DirectoryResource) sdir.lock();
    LookupState  ls = new LookupState(uri);
    LookupResult lr =
        new LookupResult(root.getResourceReference());
    root.lookup(ls, lr);
    ResourceReference target = lr.getTarget();
    if (target != null) {
        try {
      ServletWrapper wrapper =
          (ServletWrapper) target.lock();
      initialize(name, wrapper, parent);
        } finally {
      target.unlock();
        }
    } else { // doesn't exists, so create it...
        initialize(name, null, parent);
    }
      } catch (ProtocolException pex) {
View Full Code Here


     * @exception ResourceException If the resource got a fatal error.
     */
    protected Reply getOtherResource (Request request)
  throws ProtocolException, ResourceException
    {
  ResourceReference rr = getResource().getParent();
  if (rr != null) {
      try {
    FramedResource p = (FramedResource)rr.unsafeLock();
    // synchronize here to create locks in the right order
    synchronized (p) {
        // verify
        Class http_class = null;
        try {
      http_class =
          Class.forName("org.w3c.jigsaw.frames.HTTPFrame");
        } catch (ClassNotFoundException ex) {
      throw new ResourceException(ex.getMessage());
        }
        ResourceReference rrf = p.getFrameReference(http_class);
        if (rrf == null) {
      throw new ResourceException("DirectoryResource has "+
                "no HTTPFrame");
        }
        try {
      HTTPFrame httpframe = (HTTPFrame) rrf.unsafeLock();
      if (p instanceof DirectoryResource)
          return httpframe.getDirectoryListing(request);
      else
          return httpframe.get(request);
        } catch (InvalidResourceException ex) {
      throw new ResourceException(
          "Invalid parent frame (lister):"+
          ex.getMessage());
        } finally {
      rrf.unlock();
        }
    }
      } catch (InvalidResourceException ex) {
    throw new ResourceException("Invalid parent (lister):"+
              ex.getMessage());
View Full Code Here

  // Check for the corresponding negotiable resource:
  String noext = getUnextendedName(name) ;
  if ( noext == null ) {
      return ;
  } else {
      ResourceReference rr = lookup(noext);
      ResourceReference rr_neg_frame = null;

      if (rr != null) {
    try {
        FramedResource r = (FramedResource)rr.lock();
        Class nClass =
      Class.forName("org.w3c.jigsaw.frames.NegotiatedFrame");
        rr_neg_frame = r.getFrameReference(nClass);
        if (rr_neg_frame == null)
      return;
    } catch (ClassNotFoundException cex) {
        return;
    } catch (InvalidResourceException ex) {
        return;
    } finally {
        rr.unlock();
    }
      }

      if (rr_neg_frame == null) {
    // we can't add a NegotiatedFrame to an existing resource.
    if (rr == null) {
        // create the resource.
        FramedResource resource = new FramedResource();
        Hashtable defs = new Hashtable(5) ;
        defs.put(id, noext);
        ResourceContext context =
      updateDefaultChildAttributes(defs);
        resource.initialize(defs);
        addResource(resource, defs);
        // add a NegotiatedFrame.
        String variants[] = new String[1] ;
        variants[0] = name ;
        NegotiatedFrame negotiated = new NegotiatedFrame();
        Hashtable f_defs = new Hashtable(5) ;
        f_defs.put("variants".intern(), variants) ;
        resource.registerFrame(negotiated, f_defs);
    }
      } else {
    try {
        NegotiatedFrame negotiated =
      (NegotiatedFrame) rr_neg_frame.lock();
        String variants[]  = negotiated.getVariantNames() ;
        boolean exists = false;
        for ( int i=0 ; i < variants.length ; i++ ) {
      if (variants[i].equals(name))
          exists = true;
        }
        if (!exists) {
      String nvariants[] = new String[variants.length+1] ;
      System.arraycopy(variants, 0, nvariants,
           0, variants.length);
      nvariants[variants.length] = name ;
      negotiated.setVariants(nvariants) ;
        }
    } catch (InvalidResourceException ex) {
        //FIXME
    } finally {
        rr_neg_frame.unlock();
    }
      }
  }
    }
View Full Code Here

      }
        }
        setLong(ATTR_DIRSTAMP, dirstamp) ;
    }
      }
      ResourceReference rr = null;
      rr = lookup(name);
      if (rr == null) {
    lr.setTarget(null);
    return false;
      }
      try {
    lr.setTarget(rr);
    FramedResource resource = (FramedResource) rr.lock();
    return (resource != null ) ? resource.lookup(ls, lr) : false;
      } catch (InvalidResourceException ex) {
    return false;
      } finally {
    rr.unlock();
      }     
  }
  return false;
    }
View Full Code Here

     * Add the new directory in the CVS repository.
     * @param name the name of the resource.
     * @return A ResourceReference instance.
     */
    public ResourceReference createDirectoryResource(String name) {
  ResourceReference newdir = super.createDirectoryResource(name);
  if ((newdir != null) && isCvsExtensible()) {
      String names[] = new String[1];
      names[0] = name;
      try {
    getCvsManager().add(names);
View Full Code Here

     * @param name The name of the resource.
     * @return A ResourceReference instance, or <strong>null</strong>.
     */

    public ResourceReference lookup(String name) {
  ResourceReference rr = super.lookup(name);
  if (rr == null) {
      // This may be an unchecked out directory:
      try {
    CvsDirectory cvs = getCvsManager();
    if ( cvs.getDirectoryStatus(name) == CVS.DIR_NCO )
View Full Code Here

            String name,
            Hashtable defs)
    {
  if (! name.endsWith(".class"))
      return super.createFileResource(directory, req, name, defs);
  ResourceReference rr = null;
  FramedResource template = null;
 
  // Check that at least one class is defined for all the extensions:
  String exts[] = getFileExtensions(name) ;
  if ( exts == null )
      return null ;
  for (int i = exts.length-1 ; i >= 0 ; i--) {
      rr = getTemplateFor(exts[i]) ;
      if ( rr != null )
    break ;
  }
  if ( rr == null ) {
      // Look for a default template:
      if ((rr = loadExtension(defname)) == null)
    return null ;
      return super.createFileResource(directory, req, name, defs);
  } else {
      //this could become a servlet
      Hashtable tempdefs = null;
      String s_dir = "directory".intern();
      String s_ide = "identifier".intern();
      String s_ser = "servlet-class".intern();
      String s_con = "context".intern();
      String s_url = "url".intern();
      if (defs != null) {
    tempdefs = (Hashtable) defs.clone();
      } else {
    tempdefs = new Hashtable(5) ;
      }
      if ( tempdefs.get(s_dir) == null )
    tempdefs.put(s_dir, directory) ;
      if ( tempdefs.get(s_con) == null )
    tempdefs.put(s_con, getContext());
      try {
    template = (FramedResource) rr.lock();
    if (template instanceof ServletWrapper) {
        if (tempdefs.get(s_ser) == null)
      tempdefs.put(s_ser, name);
        String id = getIndexedFileName(name);
        tempdefs.put(s_ide, id) ;
        String url = (String) tempdefs.get(s_url);
        if ((url != null) && (url.endsWith(".class"))) {
      int idx = url.lastIndexOf(".class");
      tempdefs.put(s_url, url.substring(0, idx));
        }
    } else {
        if ( tempdefs.get(s_ide) == null )
      tempdefs.put(s_ide, name);
    }
    if (exts != null) {
        // Merge with values defined by the extension:
        for (int i = exts.length ; --i >= 0 ; )
      mergeDefaultAttributes(template, exts[i], tempdefs) ;
    }
    // Create, initialize and return the new resource
    try {
        FramedResource cloned =
      (FramedResource) template.getClone(tempdefs);
        if (cloned instanceof ServletWrapper) {
      ServletWrapper wrapper = (ServletWrapper) cloned;
      // check the servlet class
      if (! wrapper.isWrappingAServlet())
          return null;
        }
        //ok, the defs are good.
        copyDefs(tempdefs, defs);
        return cloned;
    } catch (Exception ex) {
        ex.printStackTrace() ;
        return null ;
    }
      } catch (InvalidResourceException ex) {
    ex.printStackTrace();
    return null;
      } finally {
    rr.unlock();
      }
  }
    }
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);
        } else {
      rr = dresource.createDirectoryResource(name);
        }
        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 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

       +"\">\n");
    String listername = getResource().getIdentifier();
    // List the children:
    g.append("<table border=\"0\">\n");

    ResourceReference rr       = null;
    FramedResource    resource = null;
    String            name     = null;
    //ugly hack to put CVS link first
    rr = dirResource.lookup("CVS");
    if (rr != null) {
View Full Code Here

      // delete file now... avoit deleting CVS and lister
      // (should be in an attribute)
      synchronized (this) {
    DirectoryResource dr;
    Resource toDeleteRes;
    ResourceReference rr;
    File dir, toDeleteFile;
    try {
        dr = (DirectoryResource) getDirResourceRef().lock();
        dir = dr.getDirectory();
        if (debug)
      System.out.println("Deleting " + name);
        rr = dr.lookup(name);
        if (rr != null) {
      try {
          toDeleteFile = new File(dir, name);
          toDeleteFile.delete();
      } catch (Exception ex) {
          // fancy message. file not present
          // Or security manager forbiding deletion.
      }
      // and now, at least remove the resource
      try {
          toDeleteRes = (Resource) rr.lock();
          toDeleteRes.delete();
      } catch (Exception ex) {
          // some other locks... or pb with the resource
      } finally {
          rr.unlock();
      }
        }
    } catch (Exception ex) {
        // some other locks... abort
    } finally {
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.