📄 get.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.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.vfs.NetworkPlaceResourceType;
import com.sslexplorer.vfs.webdav.AbstractNetworkPlaceMount;
import com.sslexplorer.vfs.webdav.DAVInputStream;
import com.sslexplorer.vfs.webdav.DAVResource;
import com.sslexplorer.vfs.webdav.DAVTransaction;
/**
* <p>
* <a href="http://www.rfc-editor.org/rfc/rfc2616.txt">HTTP</a>
* <code>GET</code> metohd implementation.
* </p>
*
* @author <a href="/">Pier Fumagalli</a>
*/
public class GET extends HEAD {
/**
* <p>
* The mime type this method will return for collections.
* </p>
*/
public static final String COLLECTION_MIME_TYPE = "text/html";
/**
* <p>
* Create a new {@link GET} instance.
* </p>
*/
public GET() {
super();
}
/**
* <p>
* Process the <code>GET</code> method.
* </p>
*/
public void process(DAVTransaction transaction, DAVResource resource) throws IOException {
super.process(transaction, resource);
try {
if (resource.isCollection() || resource.isMount()) {
String mime = COLLECTION_MIME_TYPE + "; charset=\"utf-8\"";
transaction.setContentType(mime);
transaction.setHeader("Cache-Control", "no-cache"); // HTTP 1.1
transaction.setHeader("Pragma", "no-cache"); // HTTP 1.0
transaction.setHeader("Expires", "-1");
PrintWriter out = transaction.write("utf-8");
String path = resource.getFullPath();
out.println("<html>");
out.println("<head>");
out.println("<title>Collection: " + path + "</title>");
out.println("</head>");
out.println("<body>");
out.println("<h2>Collection: " + path + "</h2>");
out.println("<ul>");
/* Process the parent */
DAVResource parent = resource.getParent();
if (parent != null)
out.print("<li><a href=\"..\">../</a>");
/* Process the children */
Iterator iterator = resource.getChildren();
if (iterator != null) {
while (iterator.hasNext()) {
DAVResource child = (DAVResource) iterator.next();
String childPath = child.getDisplayName();
out.print("<li><a href=\"");
out.print(childPath);
out.print("\">" + childPath + "</a> (" + child.getBasename() + ") - " + child.getClass().getName());
}
}
out.println("</ul>");
out.println("</body>");
out.println("</html>");
out.flush();
return;
}
} catch (Exception e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
// BPS to JB and or Lee - We need to speak about this
//
// This completely breaks HTML application launching (e.g. RMAS),
// the content type must be correct.
//
// If this was done to prevent content being opened in the same
// browser window then this is not really the place to do it and
// another solution needs to found. Perhaps we need to use the file
// download interceptors.
//
// Another possibility would be to have the store return the mime
// type given a path
//
// Im going to leave this as returning the correct MIME type as i
// need it for working on Xtra / RMAS
int total = 0;
try {
transaction.setHeader("Content-Type", resource.getContentType());
/* Processing a normal resource request */
OutputStream out = transaction.write();
DAVInputStream in = resource.read();
byte buffer[] = new byte[4096];
int k = -1;
while ((k = in.read(buffer)) != -1) {
out.write(buffer, 0, k);
total += k;
}
//out.flush();
} catch (IOException ioe) {
throw ioe;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -