/**
   * Connect to the DirContext, and retrieve the bound object, as well as its attributes. If no
   * object is bound with the name specified in the URL, then an IOException is thrown.
   *
   * @throws IOException Object not found
   */
  @Override
  public void connect() throws IOException {

    if (!connected) {

      try {
        date = System.currentTimeMillis();
        String path = URL_DECODER.convert(getURL().getFile(), false);
        if (context instanceof ProxyDirContext) {
          ProxyDirContext proxyDirContext = (ProxyDirContext) context;
          String hostName = proxyDirContext.getHostName();
          String contextPath = proxyDirContext.getContextPath();
          if (hostName != null) {
            if (!path.startsWith("/" + hostName + "/")) return;
            path = path.substring(hostName.length() + 1);
          }
          if (contextPath != null) {
            if (!path.startsWith(contextPath + "/")) {
              return;
            }
            path = path.substring(contextPath.length());
          }
        }
        object = context.lookup(path);
        attributes = context.getAttributes(path);
        if (object instanceof Resource) resource = (Resource) object;
        if (object instanceof DirContext) collection = (DirContext) object;
      } catch (NamingException e) {
        // Object not found
      }

      connected = true;
    }
  }
  /** Get input stream. */
  @Override
  public InputStream getInputStream() throws IOException {

    if (!connected) connect();

    if (resource == null) {
      throw new FileNotFoundException(getURL() == null ? "null" : getURL().toString());
    }

    // Reopen resource
    try {
      resource = (Resource) context.lookup(URL_DECODER.convert(getURL().getFile(), false));
    } catch (NamingException e) {
      // Ignore
    }

    return (resource.streamContent());
  }
示例#3
0
 private void urlDecode(ByteChunk bc) throws IOException {
   if (urlDec == null) {
     urlDec = new UDecoder();
   }
   urlDec.convert(bc, true);
 }