Package org.w3c.tools.resources

Examples of org.w3c.tools.resources.Resource


  setValue(ATTR_TIME, new Long(time));
    }

    static PutedEntry makeEntry(Request request) {
  ResourceReference rr = request.getTargetResource();
  Resource          r  = null;
  if (rr != null) {
    try {
      r = rr.lock();
      // Build an entry:
      PutedEntry e = new PutedEntry();
View Full Code Here


  return getURL();
    }

    static PutedEntry makeEntry(Request request) {
  ResourceReference rr = request.getTargetResource();
  Resource          r  = null;
  if (rr != null) {
      try {
    r = rr.lock();
    // Build an entry:
    DeletedEntry e = new DeletedEntry();
View Full Code Here

  throws MultipleLockException
    {
  // Remove the two stores we are responsible for:
  DummyResourceReference rr = (DummyResourceReference) getExtensions();
  try {
      Resource r = rr.lock();
      r.delete();
  } catch (InvalidResourceException ex) {
  } finally {
      rr.invalidate();
      rr.unlock();
  }

  rr = (DummyResourceReference) getDirectories();
  try {
      Resource r = rr.lock();
      r.delete();
  } catch (InvalidResourceException ex) {
  } finally {
      rr.invalidate();
      rr.unlock();
  }
View Full Code Here

    protected ResourceReference getTemplateFor(String ext) {
  ResourceReference rr = loadExtension(ext) ;
  if (rr != null) {
      try {
    Resource template = rr.lock();
    if (template != null) {
        Resource check = new Resource();
        if (template.getClass() == check.getClass())
      return null;
        else return rr;
    }
    return null;
      } catch (InvalidResourceException ex) {
View Full Code Here

                 Hashtable into) {
  Attribute    attrs[] = template.getAttributes();
  ResourceReference rr = loadExtension(ext) ;
  if (rr != null) {
      try {
    Resource e       = rr.lock() ;
    if ( e != null ) {
        for (int i = 0 ; i < attrs.length ; i++) {
      if ( ! template.definesAttribute(i) ) {
          int idx = e.lookupAttribute(attrs[i].getName());
          if ( idx >= 0 ) {
        Object value = e.getValue(idx, null);
        if ( value != null )
            into.put(attrs[i].getName(), value) ;
          }
      }
        }
View Full Code Here

  int idx;
  Object oldval, newval;
  String atname;

  try {
      Resource frame = frameref.lock();
      Attribute attrs[] = frame.getAttributes();
      for (int i = 0 ; i < attrs.length ; i++) {
    atname = attrs[i].getName();
    try {
        oldval = origFrame.getValue(atname, null);
        if (oldval == null) { // not defined, try to merge
      try {
          origFrame.setValue(atname,
                 frame.getValue(atname, null));
      } catch (Exception ex) {
          // undefined value, will stay null
      }
        } else if (atname.equals("quality")) {
      // small hack here, quality factor are merged
      // should be removed by a quality per encoding
      Double d = (Double)frame.getValue(atname, null);
      if (d != null) {
          d = new Double(d.doubleValue() *
             ((Double) oldval).doubleValue());
          origFrame.setValue(atname, d);
      }
View Full Code Here

            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 ) {
View Full Code Here

                 String name,
                 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) {
View Full Code Here

                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) {
View Full Code Here

    }
      }
  }
  // Does this file exists ?
  File file = new File(directory, name) ;
  Resource result = null;
  result = createVirtualResource(directory, request, name, defs);
  if (result != null) {
      return result;
  }
  if (!file.exists()) {
View Full Code Here

TOP

Related Classes of org.w3c.tools.resources.Resource

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.