Methods Summary |
---|
public void | connect()Connect to the DirContext, and retrive 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.
if (!connected) {
try {
date = System.currentTimeMillis();
String path = getURL().getFile();
if (context instanceof ProxyDirContext) {
ProxyDirContext proxyDirContext =
(ProxyDirContext) context;
String hostName = proxyDirContext.getHostName();
String contextName = proxyDirContext.getContextName();
if (hostName != null) {
if (!path.startsWith("/" + hostName + "/"))
return;
path = path.substring(hostName.length()+ 1);
}
if (contextName != null) {
if (!path.startsWith(contextName + "/")) {
return;
} else {
path = path.substring(contextName.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;
}
|
public java.lang.Object | getContent()Get object content.
if (!connected)
connect();
if (resource != null)
return getInputStream();
if (collection != null)
return collection;
if (object != null)
return object;
throw new FileNotFoundException();
|
public java.lang.Object | getContent(java.lang.Class[] classes)Get object content.
Object object = getContent();
for (int i = 0; i < classes.length; i++) {
if (classes[i].isInstance(object))
return object;
}
return null;
|
public int | getContentLength()Return the content length value.
return getHeaderFieldInt(ResourceAttributes.CONTENT_LENGTH, -1);
|
public java.lang.String | getContentType()Return the content type value.
return getHeaderField(ResourceAttributes.CONTENT_TYPE);
|
public long | getDate()Return the last modified date.
return date;
|
public java.lang.String | getHeaderField(java.lang.String name)Returns the name of the specified header field.
if (!connected) {
// Try to connect (silently)
try {
connect();
} catch (IOException e) {
}
}
if (attributes == null)
return (null);
Attribute attribute = attributes.get(name);
try {
return attribute.get().toString();
} catch (Exception e) {
// Shouldn't happen, unless the attribute has no value
}
return (null);
|
public java.io.InputStream | getInputStream()Get input stream.
if (!connected)
connect();
if (resource == null) {
throw new FileNotFoundException();
} else {
// Reopen resource
try {
resource = (Resource) context.lookup(getURL().getFile());
} catch (NamingException e) {
}
}
return (resource.streamContent());
|
public long | getLastModified()Return the last modified date.
if (!connected) {
// Try to connect (silently)
try {
connect();
} catch (IOException e) {
}
}
if (attributes == null)
return 0;
Attribute lastModified =
attributes.get(ResourceAttributes.LAST_MODIFIED);
if (lastModified != null) {
try {
Date lmDate = (Date) lastModified.get();
return lmDate.getTime();
} catch (Exception e) {
}
}
return 0;
|
public java.security.Permission | getPermission()Get the Permission for this URL
return permission;
|
public java.util.Enumeration | list()List children of this collection. The names given are relative to this
URI's path. The full uri of the children is then : path + "/" + name.
if (!connected) {
connect();
}
if ((resource == null) && (collection == null)) {
throw new FileNotFoundException();
}
Vector result = new Vector();
if (collection != null) {
try {
NamingEnumeration enumeration = context.list(getURL().getFile());
while (enumeration.hasMoreElements()) {
NameClassPair ncp = (NameClassPair) enumeration.nextElement();
result.addElement(ncp.getName());
}
} catch (NamingException e) {
// Unexpected exception
throw new FileNotFoundException();
}
}
return result.elements();
|