📄 propfind.java
字号:
/* ========================================================================== *
* Copyright (C) 2004-2005 Pier Fumagalli <http://www.betaversion.org/~pier/> *
* All rights reserved. *
* ========================================================================== *
* *
* Licensed under the Apache License, Version 2.0 (the "License"). You may *
* not use this file except in compliance with the License. You may obtain a *
* copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>. *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT *
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the *
* License for the specific language governing permissions and limitations *
* under the License. *
* *
* ========================================================================== */
package com.sslexplorer.vfs.webdav.methods;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.vfs.NetworkPlaceResourceType;
import com.sslexplorer.vfs.webdav.AbstractNetworkPlaceMount;
import com.sslexplorer.vfs.webdav.DAVException;
import com.sslexplorer.vfs.webdav.DAVMethod;
import com.sslexplorer.vfs.webdav.DAVRedirection;
import com.sslexplorer.vfs.webdav.DAVResource;
import com.sslexplorer.vfs.webdav.DAVTransaction;
import com.sslexplorer.vfs.webdav.DAVUtilities;
/**
* <p>
* <a href="http://www.rfc-editor.org/rfc/rfc2518.txt">WebDAV</a>
* <code>PROPFIND</code> metohd implementation.
* </p>
*
* @author <a href="http://www.betaversion.org/~pier/">Pier Fumagalli</a>
*/
public class PROPFIND implements DAVMethod {
private static Log log = LogFactory.getLog(PROPFIND.class);
/**
* <p>
* Create a new {@link PROPFIND} instance.
* </p>
*/
public PROPFIND() {
super();
}
/**
* <p>
* Process the <code>PROPFIND</code> method.
* </p>
*/
public void process(DAVTransaction transaction, DAVResource resource) throws IOException {
if (transaction.isRequiredRootRedirect() || !transaction.isResourcePath(resource.getFullPath())) {
throw new DAVRedirection(false, resource);
}
try {
/* Check depth */
int depth = transaction.getDepth();
if (depth > 1)
new DAVException(403, "Invalid depth");
/* What to do on a collection resource */
transaction.setStatus(207);
transaction.setContentType("text/xml; charset=\"utf-8\"");
PrintWriter out = transaction.write("utf-8");
/* Output the XML declaration and the root document tag */
out.print("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
out.println("<D:multistatus xmlns:D=\"DAV:\">");
/* Process this resource's property (always) */
this.process(transaction, out, resource);
/* Process this resource's children (if required) */
if (resource.isCollection() && (depth > 0)) {
Iterator children = resource.getChildren();
while (children.hasNext()) {
DAVResource child = (DAVResource) children.next();
this.process(transaction, out, child);
}
}
/* Close up the XML Multi-Status response */
out.println("</D:multistatus>");
out.flush();
// #ifdef XTRA
if (resource.getMount().getStore().isFireEvents()) {
CoreServlet.getServlet().fireCoreEvent(
NetworkPlaceResourceType.getResourceAccessListEvent(this, ((AbstractNetworkPlaceMount) resource.getMount())
.getNetworkPlace(), transaction.getRequest(), resource.getFullURI().getPath(), resource
.getFile().getName().getURI(), null));
}
// #endif
} catch (Exception e) {
// #ifdef XTRA
if (resource.getMount().getStore().isFireEvents()) {
CoreServlet.getServlet().fireCoreEvent(
NetworkPlaceResourceType.getResourceAccessListEvent(this, ((AbstractNetworkPlaceMount) resource.getMount())
.getNetworkPlace(), transaction.getRequest(), resource.getFullURI().getPath(), resource
.getFile().getName().getURI(), e));
}
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
}
private void process(DAVTransaction txn, PrintWriter out, DAVResource res) {
out.println(" <D:response>");
if (log.isDebugEnabled())
log.debug("Returning " + res.getFullURI().toString());
out.println(" <D:href>" + (txn.getRequest().isSecure() ? "https" : "http") + "://" + txn.getRequest().getHeader("Host")
+ "/fs" + res.getFullURI().toASCIIString() + "</D:href>");
out.println(" <D:propstat>");
if (res.isNull()) {
out.println(" <D:status>HTTP/1.1 404 Not Found</D:status>");
} else {
out.println(" <D:prop>");
/* Figure out what we're dealing with here */
if (res.isCollection()) {
this.process(out, "resourcetype", "<D:collection/>");
this.process(out, "getcontenttype", GET.COLLECTION_MIME_TYPE);
} else {
this.process(out, "getcontenttype", res.getContentType());
}
this.process(out, "getetag", res.getEntityTag());
String lmod = DAVUtilities.format(res.getLastModified());
this.process(out, "getlastmodified", lmod);
String clen = DAVUtilities.format(res.getContentLength());
this.process(out, "getcontentlength", clen);
out.println(" </D:prop>");
out.println(" <D:status>HTTP/1.1 200 OK</D:status>");
}
out.println(" </D:propstat>");
out.println(" </D:response>");
}
private void process(PrintWriter out, String name, String value) {
if (value == null)
return;
out.print(" <D:");
out.print(name);
out.print(">");
out.print(value);
out.print("</D:");
out.print(name);
out.println(">");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -