Package org.w3c.tools.resources

Examples of org.w3c.tools.resources.ResourceReference


  }
  try {
      LookupState   ls  = new LookupState(checkurl);
      LookupResult  lr  = new LookupResult(root.getResourceReference());
      if (root.lookup(ls,lr)) {
    ResourceReference  target = lr.getTarget();
    if (target != null) {
        try {
      Resource res = target.lock();
      if (res instanceof CheckpointResource) {
          ((CheckpointResource) res).activate();
          errlog("Chekpointer started at: "+new Date()+".");
      } else {
          errlog("The chekpointer url ("+checkurl+
           ") doesn't point to a CheckpointResource");
          checkpoint();
      }
        } catch (InvalidResourceException ex) {
      errlog("Invalid Checkpointer : "+ex.getMessage());
      checkpoint();
        } finally {
      target.unlock();
        }
    } else {
        errlog("can't find Checkpointer");
        checkpoint();
    }
View Full Code Here


     * root resource store.
     * @return The new installed root resource, or <strong>null</strong>
     * if we couldn't load the given resource.
     */
    public synchronized ResourceReference loadRoot(String name) {
  ResourceReference newroot = null;
  String editRootName = props.getString(EDIT_ROOT_P, null);

  // Restore the appropriate root resource:
  Hashtable defs = new Hashtable(11) ;
  defs.put("url", "/");
  defs.put("directory", space_dir) ;
  ResourceContext context = null;
  if ((editRootName != null) && (! name.equals(editRootName))) {
      if (editroot == null) {
    Hashtable edefs = new Hashtable(11) ;
    edefs.put("url", "/");
    edefs.put("directory", space_dir) ;
    ResourceContext econtext =
        new ResourceContext(getDefaultContext());
    edefs.put("context", econtext) ;
    editroot = manager.loadRootResource(editRootName, edefs);
    if (editroot != null)
        econtext.setResourceReference(editroot);
      }
      context = new ResourceContext(editroot);
  } else {
      context = new ResourceContext(getDefaultContext());
  }
  defs.put("context", context) ;
  ResourceReference rr = manager.loadRootResource(name, defs);
  if (rr != null)
      context.setResourceReference(rr);
  return rr;
    }
View Full Code Here

      context.setResourceReference(rr);
  return rr;
    }

    private synchronized FramedResource changeRoot(String name) {
  ResourceReference newroot = loadRoot(name);
  FramedResource oldroot = this.root;
  String oldroot_name = this.root_name;
  if ( newroot != null ) {
      try {
    this.root      = (FramedResource)newroot.lock();
    this.root_name = name;
    if (root_reference != null)
        root_reference.unlock();
    root_reference = newroot;
    return root;
View Full Code Here

      boolean doit = true;
      LookupState   ls = new LookupState(request);
      LookupResult  lr = new LookupResult(root.getResourceReference());
      try {
    if ( root.lookup(ls, lr) ) {
        ResourceReference  target = lr.getTarget();
        if (target != null) {
      try {
          // this is plain ugly and won't work for proxy
          // not based on this resource
          // do we need another way to to this?
          FramedResource fr = (FramedResource) target.lock();
          Class cff = Class.forName(
                  "org.w3c.jigsaw.proxy.ForwardFrame");
          doit = (fr.getFrameReference(cff) == null);
      } catch (Exception ex) {
          // fail miserably to the fallback
      } finally {
          target.unlock();
      }
        }
    }
      } catch (Exception ex) {};
      if (doit) {
    Reply reply = request.makeReply(HTTP.OK);
    reply.setNoCache(); // don't cache this
    reply.setMaxAge(-1);
    // Dump the request as the body
    // Removed unused headers:
    // FIXME should be something else for chuncked stream
    ByteArrayOutputStream ba = new ByteArrayOutputStream();
    try {
        reply.setContentType(new MimeType("message/http"));
        request.dump(ba);
        reply.setContentLength(ba.size());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    reply.setStream(new ByteArrayInputStream(ba.toByteArray()));
    return reply;
      }
  }
  // Create a lookup state, and a lookup result:

  ProtocolException error = null;
  LookupState   ls = null;
  LookupResult  lr = null;
  // Run the lookup algorithm of root resource:
  // catch exception to get error (FIXME)
  try {
      lr = new LookupResult(root.getResourceReference());
      ls = new LookupState(request);

      if ( root.lookup(ls, lr) ) {
    if (lr.hasReply())
        return lr.getReply();
      }
  } catch (ProtocolException ex) {
      error = ex;
  } catch (Exception ex) {
      /*
       * We have a problem here, the error can be a configuration
       * or resource/extension problem, and it should be a
       * 5xx error, or it is a client side error and it should be
       * a 4xx error, ex, try with "Authorization:" and it fails.
       * For now we will reply with a 400, but with a FIXME
       */
      Reply err = request.makeReply(HTTP.BAD_REQUEST);
      err.setContent("<html><head><title>Bad Request</title></head>\n"
         + "<body><p>The server was not able to "
         + "understand this request</p></body></html>");
      error = new ProtocolException(err);
  }
  // Let the target resource perform the method
  ResourceReference  target = lr.getTarget();
  Reply              reply  = null;

  ResourceFilter filters[]  = lr.getFilters();
  int            infilter   = 0;

  if (error == null) {
      //call the ingoing filters:
      try {
    // temporary target resource !!! WARNING
    request.setTargetResource(target);
    if ( filters != null ) {
        for ( ; infilter < filters.length ; infilter++ ) {
      if ( filters[infilter] == null )
          continue;
      reply = (Reply)filters[infilter].
                                     ingoingFilter(request,
                     filters,
                     infilter);
      if ( reply != null ) {
          return reply;
      }
        }
    }
      } catch (ProtocolException ex) {
    error = ex;
      }
      //perform the request:
      if ((error == null) && (target != null)) {
    request.setFilters(filters, infilter);
    request.setTargetResource(target);
    try {
        FramedResource res = (FramedResource)target.lock();
        reply = (Reply) res.perform(request);
        if (reply == null) {
      reply = request.makeReply(HTTP.NOT_FOUND);
      if (uri_error) {
          reply.setContent("<html><head><title>Not Found" +
               "</title></head>\n"+
               "<body><h1>Invalid" +
               " URL</h1><p>The URL <b>"+
               request.getURL()+
               "</b> that you requested is not" +
               " available "+
               " for this protocol.</body>\n"
               +"</html>");
      } else {
          reply.setContent("<html><head><title>Not Found" +
               "</title></head>\n"+
               "<body><h1>Invalid" +
               " URL</h1><p>The URL" +
               "</b> that you requested is not" +
               " available "+
               " for this protocol.</body>\n"
               +"</html>");
      }
      reply.setContentType(org.w3c.www.mime.MimeType.
               TEXT_HTML);
        }
    } catch (InvalidResourceException ex) {
        //FIXME
        reply = request.makeReply(HTTP.NOT_FOUND);
        if (uri_error) {
      reply.setContent("<html><head><title>Not"+
           " Found</title>"+
           "</head><body><b>The URL <b>"+
           request.getURL()+
           "</b> that you requested is not " +
           "available, "+
           " probably deleted.</body></html>");
        } else {
      reply.setContent("<html><head><title>Not"+
           " Found</title>"+
           "</head><body><b>The URL"+
           " that you requested is not " +
           "available, "+
           " probably deleted.</body></html>");
        }
        reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
    } finally {
        target.unlock();
    }
      } else {
    reply = request.makeReply(HTTP.NOT_FOUND);
    if (uri_error) {
        reply.setContent("<html><head>\n"+
View Full Code Here

    /**
     * ServletContext implementation - Lookup a given servlet.
     */
    public Servlet getServlet(String name) {
  if (dresource != null) {
      ResourceReference rr = dresource.lookup(name);
      if (rr != null) {
    try {
        Resource resource = rr.lock();
        if (resource instanceof ServletWrapper)
      return ((ServletWrapper) resource).getServlet();
    } catch (InvalidResourceException ex) {
        return null;
    } finally {
        rr.unlock();
    }
      }
  }
  return null;
    }
View Full Code Here

     * Lookup a given servlet without accessing it.
     * @return true if and only if loading was successful
     */
    public boolean isServletLoaded(String name) {
  if (dresource != null) {
      ResourceReference rr = dresource.lookup(name);
      if (rr != null) {
    try {
        Resource resource = rr.lock();
        if (resource instanceof ServletWrapper)
      return ((ServletWrapper) resource).isServletLoaded();
    } catch (InvalidResourceException ex) {
        return false;
    } finally {
        rr.unlock();
    }
      }
  }
  return false;
    }
View Full Code Here

      try {
    AuthRealm realm = (AuthRealm) rr_realm.lock();
    Enumeration e   = realm.enumerateUserNames() ;
    while (e.hasMoreElements()) {
        String   uname = (String) e.nextElement() ;
        ResourceReference rr_user = realm.loadUser(uname) ;
        try {
      AuthUser user  = (AuthUser) rr_user.lock();
      createEntry(user);
        } catch (InvalidResourceException ex) {
      System.out.println("Invalid user reference : "+uname);
        } finally {
      rr_user.unlock();
        }
    }
      } catch (InvalidResourceException ex) {

      } finally {
View Full Code Here

  File dir = server.getConfigDirectory();
  File servletProps = new File(dir, SERVLET_PROPS_FILE);
  if (servletProps.exists()) {
      readProperties(servletProps);
      Enumeration       e    = servlets.keys();
      ResourceReference sdir = getServletDirectoryReference(server);
      if (sdir == null) {
    throw new RuntimeException("No servlet directory defined!");
      }
      while (e.hasMoreElements()) {
    String name = (String) e.nextElement(); //servlet name
    initializeServlet(name, server, sdir);
      }
      // startup servlets...
      String startups = (String) general.get(STARTUP_P);
      if (startups != null) {
    StringTokenizer st =
        new StringTokenizer(startups, ARGS_SEPARATOR);
    FramedResource root = server.getRoot();
    LookupState    ls   = null;
    LookupResult   lr   = null;
    String         name = null;
    String         uri  = null;
    while (st.hasMoreTokens()) {
        name = st.nextToken();
        uri  = SERVLET_BASE_P+"/"+name;
        try {
      ls   = new LookupState(uri);
      lr   = new LookupResult(root.getResourceReference());
      root.lookup(ls, lr);
      ResourceReference rr = lr.getTarget();
      if (rr != null) {
          try {
        ServletWrapper wrapper =
            (ServletWrapper) rr.lock();
        wrapper.checkServlet();
          } catch(InvalidResourceException ex) {
        ex.printStackTrace();
          } catch (ClassNotFoundException cnfex) {
        cnfex.printStackTrace();
          } catch (ServletException sex) {
        sex.printStackTrace();
          } finally {
        rr.unlock();
          }
      }
        } catch (ProtocolException pex) {
      pex.printStackTrace();
        }
View Full Code Here

    dac = new DigestAuthContext(request);
      } catch (DigestAuthFilterException ex) {
    dac = null;
      }
      if (dac != null) {
    ResourceReference rr_user =
        (ResourceReference)lookupUser(dac.dac_user) ;
    try {
        AuthUser user = (AuthUser) rr_user.lock();
        // This user doesn't even exists !
        if ( user != null ) {
      // If it has a password check it
      if (user.definesAttribute("password") ) {
          if (dac.authenticate(user.getName(),
             loaded_realm,
             user.getPassword())) {
        request.setState(STATE_AUTHUSER, dac.dac_user);
        request.setState(STATE_AUTHTYPE, "Digest");
        request.setState(STATE_AUTHCONTEXT, dac);
        return;
          }
      }
        }
    } catch (InvalidResourceException ex) {
    } finally {
        rr_user.unlock();
    }
      }
  }
     
  // Every possible scheme has failed for this request, emit an error
View Full Code Here

    /**
     * Get the servlet directory reference.
     * @return a ResourceReference
     */
    protected ResourceReference getServletDirectoryReference(httpd server) {
  ResourceReference rr = server.getEditRoot();
  try {
      FramedResource root = (FramedResource) rr.lock();
      try {
    LookupState  ls = new LookupState(SERVLET_BASE_P);
    LookupResult lr =
        new LookupResult(root.getResourceReference());
    root.lookup(ls, lr);
    return lr.getTarget();
      } catch (ProtocolException ex) {
    ex.printStackTrace();
    return null;
      }
  } catch (InvalidResourceException ex) {
      return null;
  } finally {
      rr.unlock();
  }
    }
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.