
java.fedora.server.access.ReportServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fcrepo-client Show documentation
Show all versions of fcrepo-client Show documentation
The Fedora Client is a Java Library that allows API access to a Fedora Repository. The client is typically one part of a full Fedora installation.
The newest version!
/*
* -----------------------------------------------------------------------------
*
* License and Copyright: The contents of this file are subject to 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.fedora-commons.org/licenses.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The entire file consists of original code.
* Copyright © 2008 Fedora Commons, Inc.
*
Copyright © 2002-2007 The Rector and Visitors of the University of
* Virginia and Cornell University
* All rights reserved.
*
* -----------------------------------------------------------------------------
*/
package fedora.server.access;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import fedora.common.Constants;
import fedora.server.Context;
import fedora.server.ReadOnlyContext;
import fedora.server.Server;
import fedora.server.errors.InitializationException;
import fedora.server.errors.QueryParseException;
import fedora.server.errors.ServerException;
import fedora.server.errors.authorization.AuthzException;
import fedora.server.errors.servletExceptionExtensions.RootException;
/**
* Servlet exposing reporting functionality.
*
* @author [email protected]
*/
public class ReportServlet
extends HttpServlet {
private static final long serialVersionUID = 1L;
private Server s_server=null;
private Server getServer() {
return s_server;
}
public void init() throws ServletException {
try {
s_server=Server.getInstance(new File(Constants.FEDORA_HOME), false);
} catch (InitializationException ie) {
throw new ServletException("Error getting Fedora Server instance: "
+ ie.getMessage());
}
}
/** Exactly the same behavior as doGet. */
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
private static final String ADDR_EXCEPTION = "couldn't get remoteAddr";
public static final String ACTION_LABEL = "Report on Repository";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String sessionToken = request.getParameter("sessionToken");
String remoteAddr = request.getRemoteAddr();
String query = request.getParameter("query");
//Hashtable parmshash = new Hashtable();
String[] fieldsArray = null; {
ArrayList fieldsList = new ArrayList();
Enumeration enm = request.getParameterNames();
while (enm.hasMoreElements()) {
String name = (String) enm.nextElement();
if (Report.allFields.contains(name)) {
fieldsList.add(name);
//} else if (Report.parms.contains(name)) {
//parmshash.put(name,request.getParameter(name));
}
}
if (fieldsList.size() > 0) {
fieldsArray = (String[]) fieldsList.toArray(new String[] {});
}
}
String maxResults = request.getParameter("maxResults");
String newBase = request.getParameter("newBase");
String xslt = request.getParameter("xslt");
String reportName = request.getParameter("report");
String prefix = request.getParameter("prefix");
String dateRange = request.getParameter("dateRange");
Report report = null;
try {
Context context = ReadOnlyContext.getContext(Constants.HTTP_REQUEST.REST.uri, request);
report = Report.getInstance(context, remoteAddr, sessionToken, reportName, fieldsArray, query, xslt, maxResults, newBase,
prefix, dateRange);
} catch (AuthzException ae) {
throw RootException.getServletException (ae, request, ACTION_LABEL, new String[0]);
} catch (QueryParseException e1) {
throw new ServletException("bad query parm", e1);
} catch (ServerException e1) {
throw new ServletException("server not available", e1);
}
String contentType = report.getContentType();
response.setContentType(contentType + "; charset=UTF-8");
OutputStream out = null; // PrintWriter
if ("text/xml".equals(contentType)) {
out = response.getOutputStream();
} else if ("text/html".equals(contentType)) {
out = response.getOutputStream(); //response.getWriter();
}
try {
report.writeOut(out);
} catch (QueryParseException e) {
throw new ServletException(e.getMessage(),e);
} catch (ServerException e) {
throw new ServletException(e.getMessage(), e);
} catch (TransformerConfigurationException e) {
throw new ServletException(e.getMessage(),e);
} catch (IOException e) {
throw new ServletException(e.getMessage(),e);
} catch (TransformerException e) {
throw new ServletException(e.getMessage(),e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy