| Method from org.apache.naming.resources.DirContextURLConnection Detail: |
public void connect() throws IOException {
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;
}
}
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. |
public Object getContent() throws IOException {
if (!connected)
connect();
if (resource != null)
return getInputStream();
if (collection != null)
return collection;
if (object != null)
return object;
throw new FileNotFoundException();
}
|
public Object getContent(Class[] classes) throws IOException {
Object object = getContent();
for (int i = 0; i < classes.length; i++) {
if (classes[i].isInstance(object))
return object;
}
return null;
}
|
public int getContentLength() {
return getHeaderFieldInt(ResourceAttributes.CONTENT_LENGTH, -1);
}
Return the content length value. |
public String getContentType() {
return getHeaderField(ResourceAttributes.CONTENT_TYPE);
}
Return the content type value. |
public long getDate() {
return date;
}
Return the last modified date. |
public String getHeaderField(String name) {
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);
}
Returns the name of the specified header field. |
public InputStream getInputStream() throws IOException {
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() {
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;
}
Return the last modified date. |
public Permission getPermission() {
return permission;
}
Get the Permission for this URL |
public Enumeration list() throws IOException {
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();
}
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. |