Package org.w3c.tools.resources

Examples of org.w3c.tools.resources.ResourceReference


      if ((param != null) && (value != null)) {
    //store a new param for servlet "name"
    addParam(variables,name,param,value);
      }
      if (code != null) { // remote or not ??
    ResourceReference r_wrapper =
        (ResourceReference)wrappers.get(code);
    if (r_wrapper == null) { //lookup for wrapper
        httpd server =
      (httpd) ssiframe.getFileResource().getServer();
        ResourceReference rr_root = server.getRootReference();
        try {
      FramedResource root = (FramedResource) rr_root.lock();
      LookupState ls = new LookupState(code);
      LookupResult lr = new LookupResult(rr_root);
      ResourceReference wrap = null;
      if (root.lookup(ls,lr))
          wrap = lr.getTarget();
      if (wrap != null) {
          try {
        if (wrap.lock() instanceof ServletWrapper) {
            wrappers.put(code,wrap);
            r_wrapper = wrap;
        }
          } catch (InvalidResourceException ex) {
        ex.printStackTrace();
        r_wrapper = null;
          } finally {
        wrap.unlock();
          }
      }
        } catch (ProtocolException ex) {
      ex.printStackTrace();
      r_wrapper = null;
View Full Code Here


     */

    public Reply remoteLoadResource(Request request)
  throws ProtocolException
    {
  ResourceReference rr = lookup(request);

  // This request has no content
  ByteArrayOutputStream bout   = new ByteArrayOutputStream();

  try {
      Resource r = rr.lock();
      writer.writeResource(r, bout);
  } catch (IOException ex) {
      error(request, "bad request");
  } catch (InvalidResourceException ex) {
      error(request, "Invalid resource");
  } catch (AdminProtocolException ex) {
      error(request, ex.getMessage());
  } finally {
      rr.unlock();
  }
  // Setup the reply:
  return okReply(request, bout.toByteArray());
    }
View Full Code Here

     */
    protected boolean lookupOther(LookupState ls, LookupResult lr)
  throws ProtocolException
    {
  // Try to lookup on the host header:
  ResourceReference vrroot = null;
  ContainerResource root = null;
 
  root = (ContainerResource)getResource();
  Request r = (Request)ls.getRequest();
  if ( r != null ) {
      String host = r.getURL().getHost();
      String protocol = r.getURL().getProtocol();
      if (host == null) {
    host = r.getHost();
    if ( host != null ) {
        // must strip the port if different from 80!
        if (host.endsWith(":80") && protocol.equals("http")) {
      host = host.substring(0, host.lastIndexOf(":80"));
        }
        // and the same for https (443)
        if (host.endsWith(":443") && protocol.equals("https")) {
      host = host.substring(0, host.lastIndexOf(":443"));
        }
    }
      } else {
    int port = r.getURL().getPort();
    if (port != -1) {
        if ( (protocol.equals("http") && (port != 80)) ||
       (protocol.equals("https") && (port != 443)) ) {
      host = host + ":" + port;
        }
    }
      }
      if (host != null) {
    vrroot = root.lookup(host.toLowerCase());
      }
  }
  if ( vrroot == null ) {
      vrroot  = lookupFollowup();
  }
  // Check for what we got:
  if (vrroot == null) {
      return super.lookupOther(ls, lr);
  }
  try {
      lr.setTarget(vrroot);
      FramedResource resource = (FramedResource) vrroot.lock();
      boolean done =
        (resource != null ) ? resource.lookup(ls, lr) : false;
      if (! done) {
    lr.setTarget(null);
      }
      // because the vroot eats the lookup state components
      // we have to return true.
      // Should not be continued by the caller.
      return true;
  } catch (InvalidResourceException ex) {
      return false;
  } finally {
      vrroot.unlock();
  }
    }
View Full Code Here

     */
    public static RequestDispatcher getRequestDispatcher(String urlpath,
               httpd server,
               ResourceReference rr)
    {
  ResourceReference rr_root = null;
  FramedResource    root = null;
  rr_root = JigsawServletContext.getLocalRoot(server.getRootReference(),
                rr);
  try {
      root = (FramedResource) rr_root.lock();
      // Do the lookup:
      ResourceReference r_target = null;
      try {
    LookupState  ls = new LookupState(urlpath);
    LookupResult lr = new LookupResult(rr_root);
    root.lookup(ls, lr);
    r_target = lr.getTarget();
View Full Code Here

  if (! checkRequest(req))
      return null;

  Request request = (Request) req;
  ResourceReference selected;
  // get the right resources
  if (request.hasState(STATE_NEG)) {
      selected = (ResourceReference) request.getState(STATE_NEG);
  } else {
      String method = request.getMethod ();
      if (method.equals("PUT")) {
    selected = negotiatePut(request);
      } else {
    selected = negotiate(request);
      }
  }

  // This should never happen: either the negotiation succeed, or the
  // negotiate method should return an error.
  if ( selected == null ) {
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("Error negotiating among resource's variants.");
      throw new HTTPException(error) ;
  }

  try {
      FramedResource resource = (FramedResource) selected.unsafeLock();
      Reply reply = (Reply)resource.perform(request) ;
      reply.setHeaderValue(reply.H_VARY, getVary());
      HTTPFrame itsframe =
    (HTTPFrame) resource.unsafeGetFrame(httpFrameClass);
      if (itsframe != null) {
    reply.setContentLocation(
          itsframe.getURL(request).toExternalForm()) ;
    return reply;
      }
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("Error negotiating : "+
           "selected resource has no HTTPFrame");
      throw new HTTPException(error) ;
  } catch (InvalidResourceException ex) {
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("Error negotiating : Invalid selected resource");
      throw new HTTPException(error) ;
  } finally {
      selected.unlock();
  }
    }
View Full Code Here

    /**
     * Get the CVS manager associated with this resource, or create it.
     */
    protected synchronized CvsDirectory getCvsManager() {
  if (cvs == null) {
      ResourceReference rrp = resource.getParent();
      if (rrp != null) {
    try {
        Resource parent = rrp.lock();
        if (! (parent instanceof DirectoryResource)) {
      getServer().errlog(resource,
          "not a child of a DirectoryResource");
      throw new RuntimeException(
          "The server is misconfigured.");
        }
        // CVS will only work within a (filesystem)
        // directory resource
        File d = ((DirectoryResource) parent).getDirectory();
        try {
      cvs = getManager(d);
        } catch (CvsException ex) {
      String msg = ("unable to create a cvs manager for \""+
              d.getAbsolutePath()+
              "\".");
      getServer().errlog(this, msg);
      throw new RuntimeException("CVS failed.");
        }
        handler = new CvsDirectoryHandler(cvs);
    } catch (InvalidResourceException ex) {
        getServer().errlog(resource, "Invalid parent");
        throw new RuntimeException("The server is misconfigured.");
    } finally {
        rrp.unlock();
    }
      }
  }
  return cvs;
    }
View Full Code Here

  }
  return cvs;
    }

    protected boolean isIndexed(String name) {
  ResourceReference rrp = resource.getParent();
  if (rrp != null) {
      try {
    Resource parent = rrp.lock();
    if (! (parent instanceof DirectoryResource)) {
        getServer().errlog(resource,
               "not a child of a DirectoryResource");
        throw new RuntimeException("The server is misconfigured.");
    }
    return (((DirectoryResource)parent).lookup(name) != null);
      } catch (InvalidResourceException ex) {
    getServer().errlog(resource, "Invalid parent");
    throw new RuntimeException("The server is misconfigured.");
      } finally {
    rrp.unlock();
      }
  } else {
      getServer().errlog(resource, "No parent!");
      throw new RuntimeException("The server is misconfigured.");
  }
View Full Code Here

  addStyleSheet(g);
  g.addLink(new HtmlLink(null, "made", "jigsaw@w3.org"));

  String tablecolor = "white";
  String parentpath = null;
  ResourceReference rr_parent = resource.getParent();
  try {
      Resource parent = rr_parent.lock();
      parentpath = parent.getURLPath();
  } catch (InvalidResourceException ex) {
      getServer().errlog(resource, "Invalid parent");
      throw new RuntimeException("The server is misconfigured.");
  } finally {
      rr_parent.unlock();
  }

  //entries
  boolean nofile   = true;
  boolean nodir    = true;
View Full Code Here

    // Perform the comand :
    String comment = data.getValue("comment") ;

    if (action.equals("remove")) {
        //get the parent resource of our own resource
        ResourceReference rr = getResource().getParent();
        try {
      Resource res = rr.lock();
      DirectoryResource dirres = null;
      if (! (res instanceof DirectoryResource)) {
          getServer().errlog(res,
             "CvsFrame: not a child of a DirectoryResource");
          return error(this, request,
         "The server is misconfigured.",
         "The CVS Directory is not a children of a"+
         "Directory Resource.");
      }
      dirres = (DirectoryResource) res;
      for (int i=0; i < size; i++ ) {
          String name = names[i];
          ResourceReference childref = dirres.lookup(name);
          if (childref != null) {
        try {
            Resource children = childref.lock();
            if (children instanceof FileResource) {
          FileResource fres =
              (FileResource) children;
          // delete the file
          fres.getFile().delete();
          // delete the resource
          fres.delete();
            }
        } catch(MultipleLockException mex) {
            mex.printStackTrace();
            return error(this, request,
             "MultipleLockException: "+
             mex.getMessage(),
             "Resource "+name+" in use"+
             ", can't be deleted now.");
        } catch(InvalidResourceException iex) {
            iex.printStackTrace();
            return error(this, request,
             "InvalidResourceException. ",
             iex.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return error(this, request,
             "Exception occurs.",
             ex.getMessage());
        } finally {
            childref.unlock();
        }
          } else {
        //no resource, remove the file only
        File file = new File( dirres.getDirectory(),
                  name );
View Full Code Here

    //nothing to do
      }
  }
  super.setValue(idx, value);
  if ( idx == ATTR_IDENTIFIER ) {
       ResourceReference rr = getParent();
      if (rr != null) {
    try {
        Resource parent = rr.lock();
        if (parent.definesAttribute("directory")) {
      File pdir = (File) parent.getValue("directory", null);
      if ( pdir != null ) {
          // Compute and set our directory attribute:
          File dir = new File(pdir, getIdentifier()) ;
          super.setValue(ATTR_DIRECTORY, dir) ;
      }
        }
    } catch (InvalidResourceException ex) {
   
    } finally {
        rr.unlock();
    }
      }
      values[ATTR_PASSTARGET] = null;
      values[ATTR_DIRSTAMP]   = new Long(-1);
  } else if ( idx == ATTR_PASSTARGET ) {
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.