Package org.w3c.tools.resources

Examples of org.w3c.tools.resources.ResourceReference


    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


      (requrl.getHost().equalsIgnoreCase(url.getHost()))))
       || (ls.isInternal())) {
      // Call super.lookup:
      super.lookupOther(ls, lr);
      if ( ls.hasMoreComponents() ) {
    ResourceReference root = getLocalRootResource();
    if ( root == null ) {
        lr.setTarget(this.getResource().getResourceReference());
        return true;
    }
    try {
        // because the root eats the lookup state components
        // we have to return true.
        // Should not be continued by the caller.
        FramedResource res = (FramedResource)root.lock();
        boolean done = res.lookup(ls, lr);
        if (! done)
      lr.setTarget(null);
        return true;
    } catch (InvalidResourceException ex) {
        // should never happen with the root resource
        ex.printStackTrace();
    } finally {
        root.unlock();
    }
    return true; // should never be reached
      } else {
    request.setState(STATE_CONTENT_LOCATION, "true");
    // return the index file.
    String index = getIndex();
    if ( index != null && index.length() > 0) {
        ResourceReference root = getLocalRootResource();
        try {
      DirectoryResource dir =
          (DirectoryResource)root.lock();
      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();
          }
      }
        } catch (InvalidResourceException ex) {
      root.unlock();
        }
View Full Code Here

    protected Resource createFileResource(File directory,
            RequestInterface req,
            String name,
            Hashtable defs)
    {
  ResourceReference rr = null;
  FramedResource template = null;
  Resource       newres = null;
  Class proto = null;
  try {
      proto = Class.forName("org.w3c.tools.resources.ProtocolFrame");
  } catch (Exception ex) {
      // fatal error!
      return 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 ;
  }
  // Create the runtime-time default values for attributes.
  if ( defs == null ) {
      defs = new Hashtable(5) ;
  }
  String s_dir = "directory".intern();
  String s_ide = "identifier".intern();
  String s_fil = "filename".intern();
  String s_con = "context".intern();

  if ( defs.get(s_dir) == null ) {
      defs.put(s_dir, directory) ;
  }
  if ( defs.get(s_ide) == null ) {
      defs.put(s_ide, getIndexedFileName(name)) ;
  } else {
      defs.put(s_ide, getIndexedFileName((String)defs.get(s_ide))) ;
  }
  if ( defs.get(s_fil) == null) {
      defs.put(s_fil, name) ;
  }
  if ( defs.get(s_con) == null ) {
      defs.put(s_con, getContext());
  }
  try {
      template = (FramedResource) rr.lock();
      if (exts != null) {
    // Merge with values defined by the extension:
    for (int i = exts.length ; --i >= 0 ; )
        mergeDefaultAttributes(template, exts[i], defs) ;
      }
      // Create, initialize and return the new resouce
      try {
    newres = (FramedResource) template.getClone(defs);
      } catch (Exception ex) {
    ex.printStackTrace() ;
    return null ;
      }
  } catch (InvalidResourceException ex) {
      ex.printStackTrace();
      return null;
  } finally {
      rr.unlock();
  }
    // clone has been done, merge frames now
  if (exts != null) {
      ResourceFrame rf[] = newres.collectFrames(proto);
      if (rf != null) {
    for (int j=0; j < rf.length; j++) {
        for (int i = exts.length-1 ; i >= 0 ; i--) {
      rr = getTemplateFor(exts[i]) ;
      if ( rr != null ) {
          FramedResource fr = null;
          try {
        fr = (FramedResource) rr.lock();
        ResourceReference trr = null;
        trr = fr.getFrameReference(proto);
        if (trr != null) {
            mergeFrameAttributes(rf[j], exts[i], trr);
        }
          } catch (InvalidResourceException iex) {
View Full Code Here

     * @param name The name of the template to load.
     * @return An instance of ResourceReference, or <strong>null</strong>.
     */

    public synchronized ResourceReference loadDirectory(String name) {
  ResourceReference rr = getDirectories();
  try {
      TemplateContainer dirs = (TemplateContainer) rr.lock();
      return dirs.lookup(name);
  } catch (InvalidResourceException ex) {
      // Emit an error message, and remove it !
      String msg = ("[resource indexer]: directory template \""+
        name + "\" couldn't be restored. It has "+
        "been removed.");
      getContext().getServer().errlog(msg);
      return null;
  } finally {
      rr.unlock();
  }
    }
View Full Code Here

                 Hashtable defs)
    {
  // Lookup the directory path, for an existing template.
  File         dir      = new File(directory, name) ;
  Resource dirtempl = null;
  ResourceReference rr = null;
 
  rr = loadDirectory(name);
  // If no template available, default to a raw DirectoryResource
  if ((rr == null) && ((rr=loadDirectory(defname)) == null))
      return null;
  try {
      dirtempl = rr.lock();
      // Clone the appropriate template:
      if ( defs == null ) {
    defs = new Hashtable(3);
      }
      String s_dir = "directory".intern();
      String s_ide = "identifier".intern();     
      if ( defs.get(s_dir) == null ) {
    defs.put(s_dir, directory) ;
      }
      if ( defs.get(s_ide) == null ) {
    defs.put(s_ide, getIndexedDirName(name)) ;
      } else {
    defs.put(s_ide, getIndexedDirName((String)defs.get(s_ide))) ;
      }
      //FIXME context ???
      //      if ( defs.get("context") == null )
      //  defs.put("context", getContext());
      try {
    return (Resource) dirtempl.getClone(defs);
      } catch (Exception ex) {
    ex.printStackTrace() ;
    return null ;
      }
  } catch (InvalidResourceException ex) {
      ex.printStackTrace();
      return null;
  } finally {
      rr.unlock();
  }
    }
View Full Code Here

    protected Resource createVirtualResource( File directory,
                RequestInterface req,
                String name,
                Hashtable defs)
    {
  ResourceReference rr = null;
  Resource dirtempl = null;
 
  rr = loadDirectory(name);
  if (rr != null) {
      try {
    dirtempl = rr.lock();
    String classname = dirtempl.getClass().getName().intern();
    String idr =
        "org.w3c.jigsaw.resources.DirectoryResource".intern();
    if (classname == idr) {
        File file = new File(directory, name) ;
        // check in this case that we will have a special
        // configuration ONLY for a real directory
        if (!file.exists()) {
      return null;
        }
        if (!file.isDirectory()) {
            return null;
        }
    }
    String ifr =
        "org.w3c.tools.resources.FileResource".intern()
    if (classname == ifr) {
        File file = new File(directory, name) ;
        // check that we won't override a bad resource type
        if (!file.exists()) {
            return null;
        }
        if (file.isDirectory()) {
      return null;
        }
    }
    if ( defs == null ) {
        defs = new Hashtable(4);
    }
    String s_dir = "directory".intern();
    String s_ide = "identifier".intern();
    String s_con = "context".intern();   
    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());
    }
    try {
        return (Resource) dirtempl.getClone(defs);
    } catch (Exception ex) {
        ex.printStackTrace() ;
        return null ;
    }
      } catch (InvalidResourceException ex) {
    ex.printStackTrace();
    return null;
      } finally {
    rr.unlock();
      }
  }
  return null;
    }
View Full Code Here

  String superIndexer = getSuperIndexer();
  if ( superIndexer == null )
      return null;
  IndexerModule m = null;
  m = (IndexerModule) getContext().getModule(IndexerModule.NAME);
  ResourceReference rri = m.getIndexer(superIndexer);
  if (rri == null)
      return null;
  try {
      ResourceIndexer p = (ResourceIndexer)rri.lock();
      return ((p != null)
        ? p.createResource(container, request, directory,
               name, defs)
        : null);
  } catch (InvalidResourceException ex) {
      return null;
  } finally {
      rri.unlock();
  }
    }
View Full Code Here

      return null;
  if (file.isDirectory())
      return getIndexedDirName(name);
  //make sure that we will index this file (or directory)
  String            exts[] = getFileExtensions(name) ;
  ResourceReference rr     = null;
  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)
      return getIndexedFileName(name);
  //try the super indexer
  String superIndexer = getSuperIndexer();
  if ( superIndexer == null )
      return null;
  IndexerModule m = null;
  m = (IndexerModule) getContext().getModule(IndexerModule.NAME);
  ResourceReference rri = m.getIndexer(superIndexer);
  if (rri == null)
      return null;
  try {
      ResourceIndexer p = (ResourceIndexer)rri.lock();
      return ((p != null)
        ? p.getIndexedName(directory, name)
        : null);
  } catch (InvalidResourceException ex) {
      return null;
  } finally {
      rri.unlock();
  }
    }
View Full Code Here

  // Is this a successfull PUT request ?
  if (((put = request.getMethod().equals("PUT")) ||
       request.getMethod().equals("DELETE"))
      && ((reply.getStatus()/100) == 2)) {
      // Cool, keep track of the modified file:
      ResourceReference rr   = null;
      PutListResource   l    = null;
      boolean           done = false;
      synchronized (this) {
    rr = resolvePutListResource();
    if (rr != null) {
        try {
      l = (PutListResource) rr.lock();
      if ( l != null ) {
          if (put)
        status = l.registerRequest(request);
          else
        status = l.confirmDelete(request);
          done = true;
      }
        } catch (InvalidResourceException ex) {
      done = false;
        } finally {
      rr.unlock();
        }
    }
      }
      // Make sure we did something:
      if ( !done ) {
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.startsWith("100")) { // expect 100?
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.