mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged CMIS063 to HEAD
15943: Addition of CMIS FileShare to cmis.html front page. 15974: Merge content type to stylesheet change from latest CMIS FileShare. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@17238 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -48,6 +48,8 @@
|
||||
<li>CMIS Web Services Binding: <a href="${url.context}/cmis">WSDL Documents</a></li>
|
||||
</ul>
|
||||
|
||||
<p>You can also browse this repository via the <a href="${url.context}/cmisbrowse?url=${absurl(url.serviceContext)}/api/cmis">CMIS FileShare browser</a>.</p>
|
||||
|
||||
<h5><span id="repoinfo" class="toggle" onclick="return toggleDisplay(this)">+</span> CMIS Repository Information</h5>
|
||||
<table id="repoinfo_body" style="display: none;">
|
||||
<tr><td>Version Supported</td><td>${cmisVersion}</td></tr>
|
||||
@@ -126,6 +128,10 @@
|
||||
<li><a href="http://incubator.apache.org/chemistry/">Home Page</a></li>
|
||||
<li><a href="http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/">Source Code</a> for TCK</li>
|
||||
</ul>
|
||||
<h3>CMIS FileShare</h3>
|
||||
<ul>
|
||||
<li><a href="http://cmisfs.fmui.de/">Home Page</a></li>
|
||||
</ul>
|
||||
<h3>Provide Feedback</h3>
|
||||
<ul>
|
||||
<li><a href="http://forums.alfresco.com/en/viewforum.php?f=45">CMIS Forum</a></li>
|
||||
|
248
source/java/de/fmui/cmis/fileshare/info/BrowseServlet.java
Normal file
248
source/java/de/fmui/cmis/fileshare/info/BrowseServlet.java
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* Copyright (c) 2009, Florian Müller <mueller@gotux.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package de.fmui.cmis.fileshare.info;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public class BrowseServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String PARAM_URL = "url";
|
||||
private static final String INIT_PARAM_WEBCONTENTROOT = "webcontentroot";
|
||||
private static final String INIT_PARAM_STYLESHEET = "stylesheet:";
|
||||
|
||||
private static final int BUFFER_SIZE = 64 * 1024;
|
||||
|
||||
private String webContentRoot = "";
|
||||
private Map<String, Source> fStyleSheets;
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
fStyleSheets = new HashMap<String, Source>();
|
||||
|
||||
DocumentBuilder builder = null;
|
||||
try {
|
||||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
||||
builderFactory.setNamespaceAware(true);
|
||||
builder = builderFactory.newDocumentBuilder();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
Enumeration<String> initParams = config.getInitParameterNames();
|
||||
while (initParams.hasMoreElements()) {
|
||||
String param = initParams.nextElement();
|
||||
if (param.startsWith(INIT_PARAM_STYLESHEET)) {
|
||||
String contentType = param.substring(INIT_PARAM_STYLESHEET.length());
|
||||
String stylesheetFileName = config.getInitParameter(param);
|
||||
|
||||
InputStream stream = config.getServletContext().getResourceAsStream(stylesheetFileName);
|
||||
if (stream != null) {
|
||||
try {
|
||||
Document xslDoc = builder.parse(stream);
|
||||
addStylesheet(contentType, new DOMSource(xslDoc));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String initWebContentRoot = config.getInitParameter(INIT_PARAM_WEBCONTENTROOT);
|
||||
if (initWebContentRoot != null) {
|
||||
webContentRoot = initWebContentRoot;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
if (req.getParameter(PARAM_URL) == null) {
|
||||
printInput(req, resp);
|
||||
return;
|
||||
}
|
||||
|
||||
doBrowse(req, resp);
|
||||
}
|
||||
|
||||
protected void doBrowse(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String browseUrl = req.getParameter(PARAM_URL);
|
||||
|
||||
try {
|
||||
// get content
|
||||
URL url = new URL(browseUrl);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(false);
|
||||
conn.setRequestMethod("GET");
|
||||
String authHeader = req.getHeader("Authorization");
|
||||
if (authHeader != null) {
|
||||
conn.setRequestProperty("Authorization", authHeader);
|
||||
}
|
||||
conn.connect();
|
||||
|
||||
// ask for login
|
||||
if (conn.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
|
||||
resp.setHeader("WWW-Authenticate", conn.getHeaderField("WWW-Authenticate"));
|
||||
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
|
||||
return;
|
||||
}
|
||||
|
||||
// find stylesheet
|
||||
Source stylesheet = getStylesheet(conn.getContentType());
|
||||
|
||||
OutputStream out = null;
|
||||
InputStream in = new BufferedInputStream(conn.getInputStream(), BUFFER_SIZE);
|
||||
|
||||
if (stylesheet == null) {
|
||||
// no stylesheet found -> conduct content
|
||||
resp.setContentType(conn.getContentType());
|
||||
out = new BufferedOutputStream(resp.getOutputStream(), BUFFER_SIZE);
|
||||
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int b;
|
||||
while ((b = in.read(buffer)) > -1) {
|
||||
out.write(buffer, 0, b);
|
||||
}
|
||||
} else {
|
||||
// apply stylesheet
|
||||
TransformerFactory f = TransformerFactory.newInstance();
|
||||
Transformer t = f.newTransformer(stylesheet);
|
||||
t.setParameter("browseUrl", InfoUtil.getServletUrl(req) + "?url=");
|
||||
t.setParameter("webContentRoot", webContentRoot);
|
||||
|
||||
resp.setContentType("text/html");
|
||||
out = new BufferedOutputStream(resp.getOutputStream(), BUFFER_SIZE);
|
||||
|
||||
Source s = new StreamSource(in);
|
||||
Result r = new StreamResult(out);
|
||||
t.transform(s, r);
|
||||
}
|
||||
|
||||
try {
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
printError(req, resp, e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected void printError(HttpServletRequest req, HttpServletResponse resp, String message, Exception e)
|
||||
throws ServletException, IOException {
|
||||
resp.setContentType("text/html;charset=utf-8");
|
||||
PrintWriter pw = resp.getWriter();
|
||||
|
||||
InfoUtil.printHeader(pw, "Error");
|
||||
pw.println("<div style=\"background-color:#eeeeee; margin:15px; padding:5px;\">");
|
||||
pw.println("<h3>" + message + "</h3>");
|
||||
|
||||
if (e != null) {
|
||||
pw.print("<pre>");
|
||||
e.printStackTrace(pw);
|
||||
pw.println("</pre>");
|
||||
}
|
||||
|
||||
pw.println("</div>");
|
||||
InfoUtil.printFooter(pw);
|
||||
}
|
||||
|
||||
protected void printInput(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setContentType("text/html;charset=utf-8");
|
||||
PrintWriter pw = resp.getWriter();
|
||||
|
||||
InfoUtil.printHeader(pw, "CMIS Browse");
|
||||
pw.println("<h1>CMIS Browser</h1>");
|
||||
pw.println("<div style=\"background-color:#eeeeee; margin:15px; padding:5px;\">");
|
||||
pw.println("<form action=\"\" method=\"GET\">");
|
||||
pw.println("CMIS AtomPub URL: ");
|
||||
pw.println("<input name=\"url\" type=\"text\" size=\"100\" value=\"" + InfoUtil.getContextUrl(req) + "/atom"
|
||||
+ "\"/>");
|
||||
pw.println("<input type=\"submit\" value=\" GO \">");
|
||||
pw.println("</form>");
|
||||
pw.println("</div>");
|
||||
InfoUtil.printFooter(pw);
|
||||
}
|
||||
|
||||
private void addStylesheet(String contentType, Source source) {
|
||||
fStyleSheets.put(contentType, source);
|
||||
}
|
||||
|
||||
private Source getStylesheet(String contentType) {
|
||||
String[] ctp = contentType.split(";");
|
||||
|
||||
Source source = null;
|
||||
String match = "";
|
||||
int i = 0;
|
||||
while (source == null && i < ctp.length)
|
||||
{
|
||||
if (i > 0) {
|
||||
match += ";";
|
||||
}
|
||||
match += ctp[i];
|
||||
source = fStyleSheets.get(match);
|
||||
i++;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
}
|
75
source/java/de/fmui/cmis/fileshare/info/InfoUtil.java
Normal file
75
source/java/de/fmui/cmis/fileshare/info/InfoUtil.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package de.fmui.cmis.fileshare.info;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class InfoUtil {
|
||||
|
||||
private InfoUtil() {
|
||||
}
|
||||
|
||||
public static String getContextUrl(HttpServletRequest request) {
|
||||
String scheme = request.getScheme();
|
||||
int port = request.getServerPort();
|
||||
|
||||
if ("http".equals(scheme) && (port == 80)) {
|
||||
port = -1;
|
||||
}
|
||||
if ("https".equals(scheme) && (port == 443)) {
|
||||
port = -1;
|
||||
}
|
||||
|
||||
return scheme + "://" + request.getServerName() + (port > 0 ? ":" + port : "") + request.getContextPath();
|
||||
}
|
||||
|
||||
public static String getServletUrl(HttpServletRequest request) {
|
||||
return getContextUrl(request) + request.getServletPath();
|
||||
}
|
||||
|
||||
public static void printHeader(PrintWriter pw, String title) {
|
||||
pw.print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"");
|
||||
pw.println("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
|
||||
pw.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
|
||||
pw.println("<head>");
|
||||
pw.println("<title>" + title + "</title>");
|
||||
pw.println("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">");
|
||||
pw.println("<style type=\"text/css\">");
|
||||
pw.println("body { font-family: arial,sans-serif; font-size: 10pt; }");
|
||||
pw.println("</style>");
|
||||
pw.println("</head>");
|
||||
pw.println("<body>");
|
||||
}
|
||||
|
||||
public static void printFooter(PrintWriter pw) {
|
||||
pw.println("</body>");
|
||||
pw.println("</html>");
|
||||
}
|
||||
|
||||
public static void printStartSection(PrintWriter pw, String header) {
|
||||
pw.println("<div style=\"background-color:#eeeeee; margin:15px; padding:5px;\">");
|
||||
pw.println("<h3>" + header + "</h3>");
|
||||
}
|
||||
|
||||
public static void printEndSection(PrintWriter pw) {
|
||||
pw.println("</div>");
|
||||
}
|
||||
|
||||
public static void printStartTable(PrintWriter pw) {
|
||||
pw.println("<table>");
|
||||
}
|
||||
|
||||
public static void printEndTable(PrintWriter pw) {
|
||||
pw.println("</table>");
|
||||
}
|
||||
|
||||
public static void printRow(PrintWriter pw, String... cols) {
|
||||
pw.print("<tr>");
|
||||
|
||||
for (String col : cols) {
|
||||
pw.print("<td>" + col + "</td>");
|
||||
}
|
||||
|
||||
pw.println("</tr>");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user