Package org.w3c.tools.resources

Examples of org.w3c.tools.resources.ResourceReference


        g.append("<p><a href=\"..\">Parent</a><br>");
    }
      // List the children:
    for (int i = 0 ; i < resources.size() ; i++) {
        String            name = (String) resources.elementAt(i);
        ResourceReference rr   = null;
        long              size = -1;
        rr = cresource.lookup(name);
        FramedResource resource = null;
        if (rr != null) {
      try {
          resource = (FramedResource) rr.unsafeLock();
          // remove manually deleted FileResources
          if( resource instanceof FileResource ) {
              FileResource fr = (FileResource)resource;
        if( !fr.getFile().exists() ) {
            try {
          fr.delete();
            } catch (MultipleLockException ex) {};
            continue;
        } else {
          size = fr.getFile().length();
        }
          }
          HTTPFrame itsframe = null;
          if (http_class != null)
        itsframe =
            (HTTPFrame) resource.getFrame(http_class);
          if (itsframe != null) {
        // Icon first, if available
        String icon = itsframe.getIcon() ;
        if ( icon != null ) {
            g.append("<img src=\""+
               getIconDirectory() +"/"+ icon+
               "\" alt=\"" + icon + "\">");
        }
        // Resource's name with link:
        if (resource instanceof ContainerInterface) {
            g.append("<a href=\""
               , URLEncoder.encode(name)
               , "/\">"+name+"</a>");
        } else {
            g.append("<a href=\""
               , URLEncoder.encode(name)
               , "\">"+name+"</a>");
        }
        // resource's title, if any:
        String title = itsframe.getTitle();
        if ( title != null ) {
            g.append(" "+title);
        }
        //size (if any)
        if (size != -1) {
            String s = null;
            if (size > 1023) {
          s = " ["+(size/1024)+" KB]";
            } else {
          s = " ["+size+" bytes]";
            }
            g.append(s);
        }
        g.append("<br>\n");
          } else {
        // Resource's name with link:
        g.append(name+
           " (<i>Not available via HTTP.</i>)");
        g.append("<br>\n");
          }
      } catch (InvalidResourceException ex) {
          g.append(name+
          " cannot be loaded (server misconfigured)");
          g.append("<br>\n");
          continue;
      } finally {
          rr.unlock();
      }
        }
    }
    g.close() ;
    listing_stamp = getLastModified() ;
View Full Code Here


    }

    public Reply remoteRegisterFrame(Request request)
  throws ProtocolException
    {
   ResourceReference rr = lookup(request);
   try {
       Resource r = rr.lock();
       if ( ! ( r instanceof FramedResource) )
     error(request, "can't add frame to non-framed resource");
       // Handle the request:
       try {
    InputStream in  = getInputStream(request);
    ResourceDescription rd =
        AdminReader.readResourceDescription(in);
    String cls = rd.getClassName();
    String id  = rd.getIdentifier();
    // Create the frame:
    ResourceFrame frame = null;
     try {
         frame = (ResourceFrame) Class.forName(cls).newInstance();
     } catch (Exception ex) {
         error(request, "invalid frame class "+cls);
     }
    // Register the frame:
     Hashtable defs = new Hashtable(3);
     if ((id != null) && ! id.equals("") ) {
         defs.put("identifier", id);
     }
     ((FramedResource) r).registerFrame(frame, defs);
     // Send back the whole resource (inclding new frame):
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    writer.writeResource(frame, bout);
    return okReply(request, bout.toByteArray());
      } catch (IOException ioex) {
    error(request, "bad request");
      } catch (AdminProtocolException apex) {
    error(request, apex.getMessage());
      }
  } catch (InvalidResourceException irex) {
      error(request, "invalid resource");
  } finally {
      rr.unlock();
  }
  // not reached:
  return null;
    }
View Full Code Here

  if ((ls.hasMoreComponents()) && getPutableFlag()) {
      Request request = (Request) ls.getRequest() ;
      if ((request == null) || request.getMethod().equals("PUT")) {
    // We might well want to create a resource:
    String            name = ls.peekNextComponent() ;
    ResourceReference rr   = dresource.lookup(name);
    if ((rr == null) && (dresource.getExtensibleFlag())) {
        if (ls.countRemainingComponents() == 1)
      rr = dresource.createResource(name, request);
        else
      rr = dresource.createDirectoryResource(name);
        if (rr == null) {
      Reply error =
          request.makeReply(HTTP.UNSUPPORTED_MEDIA_TYPE);
      error.setContent(
          "Failed to create resource "+
          name +" : "+
          "Unable to create the appropriate file:"+
          request.getURLPath()+
          " this media type is not supported");
      throw new HTTPException (error);
        }
    } else if (rr == null) {
        Reply error = request.makeReply(HTTP.FORBIDDEN) ;
        error.setContent("You are not allowed to create resource "+
             name +" : "+
             dresource.getIdentifier()+
             " is not extensible.");
        throw new HTTPException (error);
    }
      }
  }
  if ( super.lookup(ls, lr) ) {
      if ( ! ls.isDirectory() && ! ls.isInternal() ) {
    // The directory lookup URL doesn't end with a slash:
    Request request = (Request)ls.getRequest() ;
    if ( request == null ) {
        lr.setTarget(null);
        return true;
    }
    URL url = null;
    try {
        if ((request != null ) &&
      request.hasState(Request.ORIG_URL_STATE)) {
      URL oldurl;
      oldurl = (URL)request.getState(Request.ORIG_URL_STATE);
      url = new URL(oldurl, oldurl.getFile() + "/");
        } else {
      url = (ls.hasRequest()
             ? getURL(request)
             : new URL(getServer().getURL(),
           resource.getURLPath()));
        }
    } catch (MalformedURLException ex) {
        getServer().errlog(this, "unable to build full URL.");
        throw new HTTPException("Internal server error");
    }
    String msg = "Invalid requested URL: the directory resource "+
        " you are trying to reach is available only through "+
        " its full URL: <a href=\""+
        url + "\">" + url + "</a>.";
    if ( getRelocateFlag() ) {
        // Emit an error (with reloc if allowed)
        Reply reloc = request.makeReply(HTTP.FOUND);
        reloc.setContent(msg) ;
        reloc.setLocation(url);
        lr.setTarget(null);
        lr.setReply(reloc);
        return true;
    } else {
        Reply error = request.makeReply(HTTP.NOT_FOUND) ;
        error.setContent(msg) ;
        lr.setTarget(null);
        lr.setReply(error);
        return true;
    }
      } else if ( ! ls.isInternal() ) {
    Request request = (Request)ls.getRequest() ;
    request.setState(STATE_CONTENT_LOCATION, "true");
    // return the index file.
    String indexes[] = getIndexes();
    if (indexes != null) {
        for (int i = 0 ; i < indexes.length ; i++) {
      String index = indexes[i];
      if ( index != null && index.length() > 0) {
          DirectoryResource dir =
        (DirectoryResource) resource;
          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();
        }
          }
      }
        } 
    }
View Full Code Here

    protected Reply deleteMe(Request request)
  throws HTTPException
    {
  // Delete the resource if parent is extensible:
  boolean shrinkable = false;
  ResourceReference rr = fresource.getParent();
  ResourceReference rrtemp = null;
  Resource p = null;
  while ( true ) {
      try {
    if (rr == null)
        break;
View Full Code Here

  StringBuffer sb        = new StringBuffer() ;

  // As we have enumerated all resources, just looking the store is ok
  for (int i = 0 ; i < rsize ; i++) {
      String            rname = (String) resources.elementAt(i) ;
      ResourceReference rr    = null;
      Resource          r     = null;
      try {
    rr = dresource.lookup(rname) ;
    r = rr.lock();
    // may throw InvalidResourceException

    if ( r instanceof DirectoryResource ) {
        sb.append("application/x-navidir "+
            rname+
            "\r\n") ;
    } else {
        HTTPFrame itsframe =
      (HTTPFrame) resource.getFrame(getClass());
        if (itsframe != null) {
      sb.append(itsframe.getContentType().toString()+
          " "+
          rname+
          "\r\n") ;
        }
    }
      } catch (InvalidResourceException ex) {
    continue;
      } finally {
    rr.unlock();
      }
  }
  Reply reply = request.makeReply(HTTP.OK) ;
  reply.addPragma("no-cache");
  reply.setNoCache();
View Full Code Here

    public Reply remoteRegisterResource(Request request)
  throws ProtocolException
    {
   // Check target resource class:
   ResourceReference rr = lookup(request);
   try {
       Resource r = rr.lock();
       if ( ! ( r instanceof ContainerInterface) )
     error(request, "can't add child in non-container");
       // Handle request:
       try {
    InputStream in = getInputStream(request);
    ResourceDescription rd =
        AdminReader.readResourceDescription(in);
    String cls = rd.getClassName();
    String id  = rd.getIdentifier();
     // Create the resource:
     Resource child = null;
     try {
         child = (Resource) Class.forName(cls).newInstance();
     } catch (Exception ex) {
         error(request, "invalid resource class "+cls);
     }
     // Add it to the container:
     try {
         ((ContainerInterface) r).registerResource(id, child, null);
     } catch (InvalidResourceException ex) {
         error(request, ex.getMessage());
     }
     // Write back the new resource:
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    writer.writeResource(child, bout);
    return okReply(request, bout.toByteArray());
       } catch (IOException ex) {
     error(request, "bad request");
       } catch (AdminProtocolException apex) {
    error(request, apex.getMessage());
      }
   } catch (InvalidResourceException ex) {
       error(request, "Invalid resource");
   } finally {
       rr.unlock();
   }
  // not reached:
  return null;
    }
View Full Code Here

    public Reply remoteReindexResource(Request request, boolean rec)
  throws ProtocolException
    {
  // Check target resource class:
  ResourceReference rr = lookup(request);
  // Handle request:
  try {
      Resource r = rr.lock();
      if(r != null) {
    if (r instanceof org.w3c.tools.resources.DirectoryResource) {
        org.w3c.tools.resources.DirectoryResource dir =
      (org.w3c.tools.resources.DirectoryResource) r;
        dir.reindex(rec);
        return okReply(request);
    } else {
        error(request, "Can't reindex this resource"+
        "(not a DirectoryResource)");
    }
      } else {
    error(request, "Bad request");
      }
  } catch (InvalidResourceException ex) {
      error(request, "Invalid resource");
  } finally {
      rr.unlock();
  }
  // not reached
  return null;
    }
View Full Code Here

    public Reply remoteDeleteResource(Request request)
  throws ProtocolException
    {
  // Check target resource class:
  ResourceReference rr = lookup(request);
  // Handle request:
  try {
      Resource r = rr.lock();
      if(r != null) {
    try {
        r.delete();
    } catch (MultipleLockException ex) {
        error(request, ex.getMessage());
    }
    return okReply(request);
      } else {
    error(request, "Bad request");
      }
  } catch (InvalidResourceException ex) {
      error(request, "Invalid resource");
  } finally {
      rr.unlock();
  }
  // not reached
  return null;
    }
View Full Code Here

  } catch (org.w3c.tools.resources.ProtocolException ex) {
      ex.printStackTrace();
      throw new HTTPException(ex);
  }
  LookupResult  lr = new LookupResult(null);
  ResourceReference rr = null; // cr
  ls.markInternal();
  if ( ! ls.hasMoreComponents() )
      return admin.getRootReference();
  // Lookup the target resource:
  String name = ls.getNextComponent();
  ServerHandler sh = shm.lookupServerHandler(name);
  if ( sh == null ) {
      if(name.equals("realms")) {
    rr = admin.getRealmCatalogResource();
      } else if (name.equals("control")) {
    rr = admin.getControlResource();
      } else {
    error(request, "unknown server handler");
      }
  } else {
      // Lookup that resource, from the config resource of that server:
      rr = sh.getConfigResource();
  }
  if ( rr != null ) {
      ResourceReference rr_temp = null;
      while ( ls.hasMoreComponents() ) {
    try {
        if (rr == null)
      error(request, "url too long");
        Resource r = rr.lock();
        if ( ! ( r instanceof ContainerInterface) )
      error(request, "url too long");
        rr_temp = ((ContainerInterface) r).lookup(
                   ls.getNextComponent());
    } catch (InvalidResourceException ex) {
        error(request, "unable to restore resource");
    } finally {
        rr.unlock();
        rr = rr_temp;
    }
      }
      if ( rr == null )
    error(request, "unknown resource");
      String query = request.getQueryString();
      if ( query != null ) {
    try {
        Resource r = rr.lock();
        // Querying a frame !
        if ( ! (r instanceof FramedResource) )
      error(request, "not a framed resource");
    } catch (InvalidResourceException ex) {
        error(request, "unable to restore resource");
    } finally {
        rr.unlock();
    }

    //search the right frame
    LookupFrameState lfs = new LookupFrameState(query);
 
    String frameName = null;
    ResourceReference the_rrf   = rr;
    ResourceReference[] rra = null;   

    while (lfs.hasMoreComponents()) {

        try {
      rra = ((FramedResource)
             the_rrf.lock()).getFramesReference();
      if (rra == null)
          error(request, "unknown frame");
        } catch (InvalidResourceException ex) {
      error(request, ex.getMessage());
        } finally {
      the_rrf.unlock();
        }
        the_rrf = null;
        frameName = lfs.getNextComponent();
        ResourceReference rrf   = null;
        ResourceFrame     frame = null;

        for (int i = 0 ; i < rra.length ; i++) {
      rrf = rra[i];
      try {
          frame = (ResourceFrame) rrf.lock();
          if (frame.getIdentifier().equals(frameName)) {
        the_rrf = rrf;
        break;
          }
      } catch (InvalidResourceException ex) {
          error(request, ex.getMessage());
      } finally {
          rrf.unlock();
      }
        }
        if (the_rrf == null)
      error(request,"unknown frame");
    }
View Full Code Here

    public Reply remoteSetValues(Request request)
  throws ProtocolException
    {
  InputStream in = getInputStream(request);
  //Get the target resource to act on:
  ResourceReference   rr    = lookup(request);
  try {
      Resource r = rr.lock();
      ResourceDescription descr =
    AdminReader.readResourceDescription(in);
      AttributeDescription attrs[] = descr.getAttributeDescriptions();
      for (int i = 0 ; i < attrs.length ; i++) {
    AttributeDescription ad = attrs[i];
    r.setValue(ad.getName(), ad.getValue());
      }
  } catch (InvalidResourceException irex) {
      irex.printStackTrace();
      error(request, "Invalid resource");
  } catch (IOException ioex) {
      error(request, "bad request");
  } catch (AdminProtocolException apex) {
      error(request, apex.getMessage());
  } finally {
      rr.unlock();
  }
  // All the changes done, return OK:
  return okReply(request);
    }
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.