Package org.w3c.tools.resources

Examples of org.w3c.tools.resources.ResourceReference


  try {
      mtype = new MimeType(type);
  } catch (MimeTypeFormatException ex) {
      return null;
  }
  ResourceReference rr = getContentTypes();
  try {
      TemplateContainer types = (TemplateContainer) rr.lock();
      Enumeration e = types.enumerateResourceIdentifiers(true);
      String key = "*:*"; // if there is no better match...
      int match = -1;
      int cmatch;
      while (e.hasMoreElements()) {
    String ext_entry = (String)e.nextElement();
    MimeType entry_type = null;
    try {
        entry_type = new MimeType(ext_entry.replace(':','/'));
    } catch (MimeTypeFormatException mex) {
        // ok there is a configuration problem here
        continue;
    }
    cmatch = mtype.match(entry_type);
    if (cmatch > match) {
        match = cmatch;
        key = ext_entry;
        if (match == MimeType.MATCH_SPECIFIC_SUBTYPE)
      break; // exact match exit loop asap
    }
      }
      return types.lookup(key);
  } catch (InvalidResourceException ex) {
      String msg = ("[resource indexer]: content-types \""+
        type+
        "\" couldn't be restored ("+ex.getMessage()+")");
      getContext().getServer().errlog(msg);
      return null;
  } finally {
      rr.unlock();
  }
    }
View Full Code Here


    protected Resource createFileResource(File directory,
            RequestInterface req,
            String name,
            Hashtable defs)
    {
  ResourceReference rr = null;
  FramedResource template = null;
 
  //try with content type in request.
  if (req instanceof Request) {
      Request request = (Request) req;
      MimeType type = request.getContentType();
      if (type != null)
    rr = loadContentType(type.toString());
      if (rr != null) {
    String s_dir = "directory".intern();
    String s_ide = "identifier".intern();
    String s_fil = "filename".intern();
    String s_con = "context".intern();
    if ( defs == null )
        defs = new Hashtable(5) ;
    if ( defs.get(s_dir) == null )
        defs.put(s_dir, directory) ;
    if ( defs.get(s_ide) == null )
        defs.put(s_ide, name) ;
    if ( defs.get(s_con) == null )
        defs.put(s_con, getContext());
    //read attribute from request
    try {
        template = (FramedResource) rr.lock();
        // Create, initialize and return the new resouce
        try {
      FramedResource resource = null;
      resource = (FramedResource) template.getClone(defs);
      // Now update HTTPFrame from request
      String contentLanguage[] =
          request.getContentLanguage();
      String contentEncoding[] =
          request.getContentEncoding();
      //get the HTTPFrame.
      Class httpFrameClass =
          Class.forName("org.w3c.jigsaw.frames.HTTPFrame");
      HTTPFrame hframe = (HTTPFrame)
          resource.getFrame(httpFrameClass);
      if (hframe != null) {
          if ((contentLanguage != null) &&
        (contentLanguage.length > 0))
        hframe.setValue("content-language",
            contentLanguage[0]);
          if ((contentEncoding != null) &&
        (contentEncoding.length > 0))
        hframe.setValue("content-encoding",
            contentEncoding[0]);
      }
      return resource;
        } catch (Exception ex) {
      ex.printStackTrace() ;
        }
    } catch (InvalidResourceException ex) {
        ex.printStackTrace();
    } finally {
        rr.unlock();
    }
      }
  }
  // nothing found with this content-type, try usual indexing
  return super.createFileResource(directory, req, name, defs);
View Full Code Here

   
    /**
     * The Path where we can find the servlet class file.
     */
    public File getServletDirectory() {
  ResourceReference rr = getParent();
  if (rr != null) {
      try {
    Resource parent = rr.lock();
    if (parent.definesAttribute("directory"))
        return (File) parent.getValue("directory", null);
      } catch(InvalidResourceException ex) {
    ex.printStackTrace();
      } finally {
    rr.unlock();
      }
  }
  return null;
    }
View Full Code Here

  defs.put(id, name);
  updateDefaultChildAttributes(defs);
  ResourceContext context = getContext();
  // Try to get the indexer to create the resource:
  Resource    resource = null;
  ResourceReference rr_indexer  = null;
  ResourceReference rr_lastidx  = null;
  while ( context != null ) {
      // Lookup for next indexer in hierarchy:
      do {
    rr_indexer = getIndexer(context);
    context = context.getParent();
View Full Code Here

  // If we did get the realm:
  if ( rr_realm != null ) {
      try {
    AuthRealm realm = (AuthRealm) rr_realm.lock();
    // Get the user:
    ResourceReference rr_user = realm.loadUser(username);
    if (rr_user == null)
        return false;
    try {
        AuthUser user = (AuthUser)rr_user.lock();
        // Check the old password first:
        String passwd = user.getPassword();
        if ((passwd == null) || ! passwd.equals(oldpassword))
      return false;
        // Set the new password:
        user.setPassword(newpassword);
        return true;
    } catch (InvalidResourceException ex) {
        return false;
    } finally {
        rr_user.unlock();
    }
      } catch (InvalidResourceException ex) {
    return false;
      } finally {
    rr_realm.unlock();
View Full Code Here

    if (e.hasMoreElements()) {
        ipmatcher       = new IPMatcher() ;
    }
    while (e.hasMoreElements()) {
        String   uname = (String) e.nextElement() ;
        ResourceReference rr_user = realm.loadUser(uname) ;
        try {
      AuthUser user  = (AuthUser) rr_user.lock();
      short    ips[][] = user.getIPTemplates() ;
      if ( ips != null ) {
          for (int i = 0 ; i < ips.length ; i++)
        ipmatcher.add(ips[i], rr_user) ;
      }
        } catch (InvalidResourceException ex) {
      System.out.println("Invalid user reference : "+uname);
        } finally {
      rr_user.unlock();
        }
    }
      } catch (InvalidResourceException ex) {

      } finally {
View Full Code Here

     * @return A AuthUser instance if check succeeded, <strong>null</strong>
     *    otherwise.
     */

    protected ResourceReference checkBasicAuth(BasicAuthContext ctxt) {
  ResourceReference rr_user = (ResourceReference)lookupUser(ctxt.user) ;
  if (rr_user != null) {
      try {
    AuthUser user = (AuthUser) rr_user.lock();
    // This user doesn't even exists !
    if ( user == null )
        return null ;
    // If it has a password check it
    if ( ! user.definesAttribute("password") ) {
        return  rr_user;
    } else {
        return user.getPassword().equals(ctxt.password)
      ? rr_user
      : null ;
    }
      } catch (InvalidResourceException ex) {
    return null;
      } finally {
    rr_user.unlock();
      }
  }
  return null;
    }
View Full Code Here

  Client client = request.getClient() ;
  if ( client == null )
      return ;
  // Check for User by IP address:
  boolean ipchecked = false ;
  ResourceReference rr_user = lookupUser(client.getInetAddress());
  if (rr_user != null) {
      try {
    AuthUser user = (AuthUser) rr_user.lock();
    if ( user != null ) {
        ipchecked = true ;
        // Good the user exists, does it need more authentication ?
        if ( ! user.definesAttribute("password") &&
       checkUser(user)) {
      request.setState(STATE_AUTHUSER, user.getName()) ;
      request.setState(STATE_AUTHTYPE, "ip");
      return ;
        }
    }
      } catch (InvalidResourceException ex) {
    //FIXME
      } finally {
    rr_user.unlock();
      }
  }
  // Check authentication according to auth method:
  if ((request.hasAuthorization() && ! request.isProxy())
      || (request.isProxy() && request.hasProxyAuthorization())) {
      BasicAuthContext ctxt = null ;
      try {
    ctxt = new BasicAuthContext(request);
      } catch (BasicAuthContextException ex) {
    ctxt = null;
      }
      // Is that user allowed ?
      if ( ctxt != null ) {
    rr_user = checkBasicAuth(ctxt) ;
    if (rr_user != null) {
        try {
      AuthUser user = (AuthUser) rr_user.lock();
      if ((user != null) && checkUser(user)) {
          // Check that if IP auth was required,
          // it succeeded:
          boolean iprequired =
        user.definesAttribute("ipaddress") ;
          if ( ( ! iprequired) || ipchecked ) {
        // Set the request fields, and continue:
        request.setState(STATE_AUTHUSER, ctxt.user);
        request.setState(STATE_AUTHTYPE, "Basic") ;
        return ;
          }
      }
        } catch (InvalidResourceException ex) {
      //FIXME
        } finally {
      rr_user.unlock();
        }
    }
      }
  }
     
View Full Code Here

  protected synchronized void updateHeaders() {
      try {
    CvsFrame cvsframe = (CvsFrame) rr_cvsframe.lock();
    Resource res      = cvsframe.getResource();
    ResourceReference rr_dir = res.getParent();
    try {
        Resource parent = rr_dir.lock();
        if (parent instanceof ContainerResource) {
      ContainerResource dir = (ContainerResource) parent;
      ResourceReference rr_res = dir.lookup(name);
      if (rr_res == null) {
          this.setValue(ATTR_CONTENT_TYPE,
             org.w3c.www.mime.Utils.getMimeType(name));
          return;
      }
      try {
          res = rr_res.lock();
          if (res instanceof FileResource) {
        HTTPFrame httpFrame = (HTTPFrame)
            res.getFrame(
           Class.forName(
             "org.w3c.jigsaw.frames.HTTPFrame"));
        this.setValue(ATTR_CONTENT_LANGUAGE,
                httpFrame.getContentLanguage());
        this.setValue(ATTR_CONTENT_ENCODING,
                httpFrame.getContentEncoding());
        this.setValue(ATTR_CONTENT_TYPE,
                httpFrame.getContentType());
          }
      } catch (InvalidResourceException ex) {
          //nothing to do ;(
      } catch (ClassNotFoundException ex2) {
          //pfff
      } finally {
          rr_res.unlock();
      }
        }
    } catch (InvalidResourceException ex) {
        //nothing to do ;(
    } finally {
View Full Code Here

    protected File resDirectory = null;

    protected synchronized File getResourceDirectory() {
  if (resDirectory == null) {
      ResourceReference rr = getFileResource().getParent();
      ResourceReference rrtemp = null;
      Resource p = null;
      while ( true ) {
    try {
        if (rr == null)
      return null;
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.