Verschiedene Ergänzungen für das Publikationsmodul
git-svn-id: https://svn.libreccm.org/ccm/trunk@2122 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
19780067af
commit
0f1a13c876
|
|
@ -45,7 +45,6 @@ public class PublicationExtraXmlGenerator implements ExtraXMLGenerator {
|
||||||
|
|
||||||
final List<PublicationFormat> formats = SciPublicationsExporters.getInstance().getSupportedFormats();
|
final List<PublicationFormat> formats = SciPublicationsExporters.getInstance().getSupportedFormats();
|
||||||
|
|
||||||
|
|
||||||
for (PublicationFormat format : formats) {
|
for (PublicationFormat format : formats) {
|
||||||
createExportLink(format, element, (Publication) item, state);
|
createExportLink(format, element, (Publication) item, state);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,7 @@ person.ui.publications.title=Publications
|
||||||
person.ui.publications.columns.name=Title
|
person.ui.publications.columns.name=Title
|
||||||
person.ui.publications.columns.year=Year
|
person.ui.publications.columns.year=Year
|
||||||
person.ui.publications.columns.type=Type
|
person.ui.publications.columns.type=Type
|
||||||
publisher.ui.publications.title=Publications of the Publisher
|
publisher.ui.publications.title=Publications of the publisher
|
||||||
publisher.ui.publications.none=No publications
|
publisher.ui.publications.none=No publications
|
||||||
publisher.ui.publications.name=Title
|
publisher.ui.publications.name=Title
|
||||||
publisher.ui.publications.columns.year=Jahr
|
publisher.ui.publications.columns.year=Jahr
|
||||||
|
|
|
||||||
|
|
@ -399,7 +399,7 @@ person.ui.publications.title=Publikationen
|
||||||
person.ui.publications.columns.name=Titel
|
person.ui.publications.columns.name=Titel
|
||||||
person.ui.publications.columns.year=Jahr
|
person.ui.publications.columns.year=Jahr
|
||||||
person.ui.publications.columns.type=Typ
|
person.ui.publications.columns.type=Typ
|
||||||
publisher.ui.publications.title=Titel des Verlages
|
publisher.ui.publications.title=Publikationen des Verlages
|
||||||
publisher.ui.publications.none=Keine Publikationen vorhanden
|
publisher.ui.publications.none=Keine Publikationen vorhanden
|
||||||
publisher.ui.publications.name=Titel
|
publisher.ui.publications.name=Titel
|
||||||
publisher.ui.publications.columns.year=Jahr
|
publisher.ui.publications.columns.year=Jahr
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,226 @@
|
||||||
|
package com.arsdigita.cms.scipublications;
|
||||||
|
|
||||||
|
import com.arsdigita.categorization.CategorizedCollection;
|
||||||
|
import com.arsdigita.categorization.Category;
|
||||||
|
import com.arsdigita.cms.ContentBundle;
|
||||||
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
|
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
|
||||||
|
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporters;
|
||||||
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
|
import com.arsdigita.kernel.ACSObject;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Code to call the SciPublications logic. Parses the parameters from the HttpServletRequest and calls to appropriate
|
||||||
|
* methods of the {@link SciPublicationsExporters} class.
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class Exporter {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(Exporter.class);
|
||||||
|
private static final String PARAM_FORMAT = "format";
|
||||||
|
private static final String PARAM_CATEGORY = "category";
|
||||||
|
private static final String PARAM_PUBLICATION = "publication";
|
||||||
|
private final Map<String, String[]> parameters;
|
||||||
|
|
||||||
|
protected Exporter(final Map<String, String[]> parameters) {
|
||||||
|
super();
|
||||||
|
this.parameters = parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doExport(final HttpServletRequest request, final HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
final String format;
|
||||||
|
|
||||||
|
try {
|
||||||
|
format = getExportFormat();
|
||||||
|
} catch (BadExportParametersException ex) {
|
||||||
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parameters.containsKey(PARAM_CATEGORY)) {
|
||||||
|
exportCategory(format, response);
|
||||||
|
} else if (parameters.containsKey(PARAM_PUBLICATION)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exportCategory(final String format,
|
||||||
|
final HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
/*
|
||||||
|
* If the category parameter is present, retrieve the specified
|
||||||
|
* category and exports all publications in it.
|
||||||
|
*/
|
||||||
|
Publication publication;
|
||||||
|
SciPublicationsExporter exporter;
|
||||||
|
String categoryIdStr;
|
||||||
|
BigDecimal categoryId;
|
||||||
|
Category category;
|
||||||
|
CategorizedCollection objects;
|
||||||
|
|
||||||
|
LOGGER.debug("Found parameter 'category'...");
|
||||||
|
if (parameters.get(PARAM_CATEGORY).length != 1) {
|
||||||
|
LOGGER.error("The parameter 'category' is expected to appear only once.");
|
||||||
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
|
"The parameter 'category' is expected to appear only once.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
categoryIdStr = parameters.get(PARAM_CATEGORY)[0];
|
||||||
|
try {
|
||||||
|
categoryId = new BigDecimal(categoryIdStr);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
LOGGER.error("The category id could not be converted to an BigDecimal value.", ex);
|
||||||
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
|
"The category id could not be converted to an BigDecimal value.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
category = new Category(categoryId);
|
||||||
|
} catch (DataObjectNotFoundException ex) {
|
||||||
|
LOGGER.error(String.format("No category with the provided "
|
||||||
|
+ "id '%s' found.",
|
||||||
|
categoryIdStr),
|
||||||
|
ex);
|
||||||
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
|
String.format("No category with the provided "
|
||||||
|
+ "id '%s' found.",
|
||||||
|
categoryIdStr));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.debug(String.format("Category: %s", category.getName()));
|
||||||
|
|
||||||
|
//Get the exporter for the specified format.
|
||||||
|
exporter = SciPublicationsExporters.getInstance().getExporterForFormat(format);
|
||||||
|
if (exporter == null) {
|
||||||
|
LOGGER.warn(String.format("The requested export format '%s' is not supported yet.",
|
||||||
|
format));
|
||||||
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
|
String.format("The requested export format '%s' is not supported yet.",
|
||||||
|
format));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the category.
|
||||||
|
objects = category.getObjects(ACSObject.BASE_DATA_OBJECT_TYPE);
|
||||||
|
LOGGER.debug(String.format("Category contains %d objects.", objects.size()));
|
||||||
|
ContentBundle bundle;
|
||||||
|
ACSObject object;
|
||||||
|
while (objects.next()) {
|
||||||
|
|
||||||
|
//Get the bundle
|
||||||
|
bundle = (ContentBundle) objects.getACSObject();
|
||||||
|
//Get the default instance of the bundle
|
||||||
|
object = bundle.getInstance(bundle.getDefaultLanguage());
|
||||||
|
|
||||||
|
//Ignore object if it is not an publication
|
||||||
|
if (object instanceof Publication) {
|
||||||
|
publication = (Publication) object;
|
||||||
|
} else {
|
||||||
|
LOGGER.debug("Object is not a publication, ignoring it.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Ignore none live versions.
|
||||||
|
if (!publication.isLiveVersion()) {
|
||||||
|
LOGGER.debug("Object is no a published version, ignoring it.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Write the exported publication to the response.
|
||||||
|
response.getWriter().append(exporter.exportPublication(publication));
|
||||||
|
//response.getWriter().append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set the MimeType of the response
|
||||||
|
response.setContentType(exporter.getSupportedFormat().getMimeType().getBaseType());
|
||||||
|
//Force the browser to display an download dialog, and set
|
||||||
|
//the filename for the downloaded file to the name of the
|
||||||
|
//selected category.
|
||||||
|
response.setHeader("Content-Disposition",
|
||||||
|
String.format("attachment; filename=%s.%s",
|
||||||
|
category.getName(),
|
||||||
|
exporter.getSupportedFormat().getFileExtension()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getExportFormat() throws BadExportParametersException {
|
||||||
|
final String format;
|
||||||
|
|
||||||
|
if (parameters.containsKey(PARAM_FORMAT)) {
|
||||||
|
if (parameters.get(PARAM_FORMAT).length == 1) {
|
||||||
|
format = parameters.get(PARAM_FORMAT)[0];
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("Query parameter 'format' contains no value"
|
||||||
|
+ "or more than one value. It is expected that "
|
||||||
|
+ "'format' contains excactly one value. Responding"
|
||||||
|
+ "with BAD_REQUEST status.");
|
||||||
|
throw new BadExportParametersException("Query parameter 'format' contains no value or more"
|
||||||
|
+ "than one value. It is expected that "
|
||||||
|
+ "'format' contains excactly one value.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("Missing query parameter 'format'. Responsding with BAD_REQUEST status code.");
|
||||||
|
throw new BadExportParametersException("Missing query parameter 'format'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class BadExportParametersException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of <code>BadExportParametersException</code> without detail message.
|
||||||
|
*/
|
||||||
|
public BadExportParametersException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance of <code>BadExportParametersException</code> with the specified detail message.
|
||||||
|
*
|
||||||
|
* @param msg The detail message.
|
||||||
|
*/
|
||||||
|
public BadExportParametersException(final String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance of <code>BadExportParametersException</code> which wraps the
|
||||||
|
* specified exception.
|
||||||
|
*
|
||||||
|
* @param exception The exception to wrap.
|
||||||
|
*/
|
||||||
|
public BadExportParametersException(final Exception exception) {
|
||||||
|
super(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance of <code>BadExportParametersException</code> with the specified message which also wraps the
|
||||||
|
* specified exception.
|
||||||
|
*
|
||||||
|
* @param msg The detail message.
|
||||||
|
* @param exception The exception to wrap.
|
||||||
|
*/
|
||||||
|
public BadExportParametersException(final String msg, final Exception exception) {
|
||||||
|
super(msg, exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,7 +23,6 @@ import com.arsdigita.bebop.Form;
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
import com.arsdigita.bebop.Page;
|
import com.arsdigita.bebop.Page;
|
||||||
import com.arsdigita.bebop.PageFactory;
|
import com.arsdigita.bebop.PageFactory;
|
||||||
import com.arsdigita.categorization.CategorizedCollection;
|
|
||||||
import com.arsdigita.categorization.Category;
|
import com.arsdigita.categorization.Category;
|
||||||
import com.arsdigita.cms.ContentBundle;
|
import com.arsdigita.cms.ContentBundle;
|
||||||
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
|
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
|
||||||
|
|
@ -32,11 +31,12 @@ import com.arsdigita.cms.contenttypes.Publication;
|
||||||
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
|
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
|
||||||
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporters;
|
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporters;
|
||||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
|
|
||||||
import com.arsdigita.domain.DomainObjectFactory;
|
import com.arsdigita.domain.DomainObjectFactory;
|
||||||
import com.arsdigita.globalization.GlobalizationHelper;
|
import com.arsdigita.globalization.GlobalizationHelper;
|
||||||
import com.arsdigita.kernel.ACSObject;
|
import com.arsdigita.kernel.ACSObject;
|
||||||
import com.arsdigita.kernel.Kernel;
|
import com.arsdigita.kernel.Kernel;
|
||||||
|
import com.arsdigita.persistence.DataCollection;
|
||||||
|
import com.arsdigita.persistence.DataObject;
|
||||||
import com.arsdigita.persistence.DataQuery;
|
import com.arsdigita.persistence.DataQuery;
|
||||||
import com.arsdigita.persistence.Filter;
|
import com.arsdigita.persistence.Filter;
|
||||||
import com.arsdigita.persistence.FilterFactory;
|
import com.arsdigita.persistence.FilterFactory;
|
||||||
|
|
@ -85,21 +85,18 @@ import org.apache.log4j.Logger;
|
||||||
public class SciPublicationsServlet extends BaseApplicationServlet {
|
public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = -632365939651657874L;
|
private static final long serialVersionUID = -632365939651657874L;
|
||||||
private static final Logger logger = Logger.getLogger(
|
private static final Logger LOGGER = Logger.getLogger(SciPublicationsServlet.class);
|
||||||
SciPublicationsServlet.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doService(HttpServletRequest request,
|
protected void doService(final HttpServletRequest request,
|
||||||
HttpServletResponse response,
|
final HttpServletResponse response,
|
||||||
Application app) throws ServletException,
|
final Application app) throws ServletException, IOException {
|
||||||
IOException {
|
|
||||||
String path = "";
|
String path = "";
|
||||||
|
|
||||||
logger.debug("SciPublicationsServlet is starting...");
|
LOGGER.debug("SciPublicationsServlet is starting...");
|
||||||
logger.debug(String.format("pathInfo = '%s'", request.getPathInfo()));
|
LOGGER.debug(String.format("pathInfo = '%s'", request.getPathInfo()));
|
||||||
|
|
||||||
logger.debug("Extracting path from pathInfo by removing leading and "
|
LOGGER.debug("Extracting path from pathInfo by removing leading and trailing slashes...");
|
||||||
+ "trailing slashes...");
|
|
||||||
if (request.getPathInfo() != null) {
|
if (request.getPathInfo() != null) {
|
||||||
if ("/".equals(request.getPathInfo())) {
|
if ("/".equals(request.getPathInfo())) {
|
||||||
path = "";
|
path = "";
|
||||||
|
|
@ -117,17 +114,18 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(String.format("path = %s", path));
|
LOGGER.debug(String.format("path = %s", path));
|
||||||
|
|
||||||
//Displays a text/plain page with a message.
|
//Displays a text/plain page with a message.
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
logger.debug("pathInfo is null, responding with default...");
|
LOGGER.debug("pathInfo is null, responding with default...");
|
||||||
|
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
response.getWriter().append("Please choose an application.");
|
response.getWriter().append("Please choose an application.");
|
||||||
|
|
||||||
//ToDo: Show a menu?
|
//ToDo: Show a menu?
|
||||||
} else if ("hellobebop".equals(path)) {
|
} else if ("hellobebop".equals(path)) {
|
||||||
|
//This is just for testing
|
||||||
Page page;
|
Page page;
|
||||||
Form form;
|
Form form;
|
||||||
Label label;
|
Label label;
|
||||||
|
|
@ -142,12 +140,11 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
page.lock();
|
page.lock();
|
||||||
|
|
||||||
Document document = page.buildDocument(request, response);
|
final Document document = page.buildDocument(request, response);
|
||||||
PresentationManager presentationManager = Templating.
|
final PresentationManager presenter = Templating.getPresentationManager();
|
||||||
getPresentationManager();
|
presenter.servePage(document, request, response);
|
||||||
presentationManager.servePage(document, request, response);
|
|
||||||
} else if ("export".equals(path)) {
|
} else if ("export".equals(path)) {
|
||||||
logger.debug("Export a publication");
|
LOGGER.debug("Export a publication");
|
||||||
|
|
||||||
Map<String, String[]> parameters;
|
Map<String, String[]> parameters;
|
||||||
String format;
|
String format;
|
||||||
|
|
@ -159,7 +156,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
if (parameters.get("format").length == 1) {
|
if (parameters.get("format").length == 1) {
|
||||||
format = parameters.get("format")[0];
|
format = parameters.get("format")[0];
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Query parameter 'format' contains no value"
|
LOGGER.warn("Query parameter 'format' contains no value"
|
||||||
+ "or more than one value. It is expected that "
|
+ "or more than one value. It is expected that "
|
||||||
+ "'format' contains excactly one value. Responding"
|
+ "'format' contains excactly one value. Responding"
|
||||||
+ "with BAD_REQUEST status.");
|
+ "with BAD_REQUEST status.");
|
||||||
|
|
@ -170,7 +167,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Missing query parameter 'format'. "
|
LOGGER.warn("Missing query parameter 'format'. "
|
||||||
+ "Responsding with BAD_REQUEST status code.");
|
+ "Responsding with BAD_REQUEST status code.");
|
||||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||||
return;
|
return;
|
||||||
|
|
@ -186,15 +183,14 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
String categoryIdStr;
|
String categoryIdStr;
|
||||||
BigDecimal categoryId;
|
BigDecimal categoryId;
|
||||||
Category category;
|
Category category;
|
||||||
CategorizedCollection objects;
|
//CategorizedCollection objects;
|
||||||
|
DataCollection objects;
|
||||||
|
|
||||||
logger.debug("Found parameter 'category'...");
|
LOGGER.debug("Found parameter 'category'...");
|
||||||
if (parameters.get("category").length != 1) {
|
if (parameters.get("category").length != 1) {
|
||||||
logger.error("The parameter 'category' is expected to"
|
LOGGER.error("The parameter 'category' is expected to appear only once.");
|
||||||
+ "have exactly one parameter.");
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
response.sendError(response.SC_BAD_REQUEST,
|
"The parameter 'category' is expected to appear only once.");
|
||||||
"The parameter 'category' is expected to"
|
|
||||||
+ "have exactly one pareameter.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,83 +198,99 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
try {
|
try {
|
||||||
categoryId = new BigDecimal(categoryIdStr);
|
categoryId = new BigDecimal(categoryIdStr);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
logger.error("The category id could not be converted to"
|
LOGGER.error("The category id could not be converted to an BigDecimal value.", ex);
|
||||||
+ "an BigDecimal value.",
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
ex);
|
"The category id could not be converted to an BigDecimal value.");
|
||||||
response.sendError(response.SC_BAD_REQUEST,
|
|
||||||
"The category id could not be converted to"
|
|
||||||
+ "an BigDecimal value.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
category = new Category(categoryId);
|
category = new Category(categoryId);
|
||||||
} catch (DataObjectNotFoundException ex) {
|
} catch (DataObjectNotFoundException ex) {
|
||||||
logger.error(String.format("No category with the provided "
|
LOGGER.error(String.format("No category with the provided "
|
||||||
+ "id '%s' found.",
|
+ "id '%s' found.",
|
||||||
categoryIdStr),
|
categoryIdStr),
|
||||||
ex);
|
ex);
|
||||||
response.sendError(response.SC_BAD_REQUEST,
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
String.format("No category with the provided "
|
String.format("No category with the provided "
|
||||||
+ "id '%s' found.",
|
+ "id '%s' found.",
|
||||||
categoryIdStr));
|
categoryIdStr));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(String.format("Category: %s", category.getName()));
|
LOGGER.debug(String.format("Category: %s", category.getName()));
|
||||||
|
|
||||||
//Get the exporter for the specified format.
|
//Get the exporter for the specified format.
|
||||||
exporter = SciPublicationsExporters.getInstance().
|
exporter = SciPublicationsExporters.getInstance().getExporterForFormat(format);
|
||||||
getExporterForFormat(
|
|
||||||
format);
|
|
||||||
if (exporter == null) {
|
if (exporter == null) {
|
||||||
logger.warn(String.format(
|
LOGGER.warn(String.format("The requested export format '%s' is not supported yet.",
|
||||||
"The requested export format '%s' is not supported yet.",
|
format));
|
||||||
format));
|
|
||||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
String.format(
|
String.format("The requested export format '%s' is not supported yet.",
|
||||||
"The requested export format '%s' is not supported yet.",
|
format));
|
||||||
format));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the category.
|
//Get the category.
|
||||||
objects = category.getObjects(ACSObject.BASE_DATA_OBJECT_TYPE);
|
//objects = category.getObjects(ACSObject.BASE_DATA_OBJECT_TYPE);
|
||||||
logger.debug(String.format("Category contains %d objects.",
|
objects = SessionManager.getSession().retrieve(Publication.BASE_DATA_OBJECT_TYPE);
|
||||||
objects.size()));
|
boolean descendCategories = false;
|
||||||
ContentBundle bundle;
|
if (parameters.containsKey("descendCategories")
|
||||||
ACSObject object;
|
&& (parameters.get("descendCategories").length >= 1)) {
|
||||||
|
descendCategories = "true".equals(parameters.get("descendCategories")[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (descendCategories) {
|
||||||
|
final Filter filter = objects.addInSubqueryFilter(
|
||||||
|
"parent.id", "com.arsdigita.categorization.objectIDsInSubtree");
|
||||||
|
filter.set("categoryID", category.getID());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
objects.addEqualsFilter("parent.categories.id", category.getID());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parameters.containsKey("filter") && (parameters.get("filter").length >= 1)) {
|
||||||
|
final String filter = parameters.get("filter")[0];
|
||||||
|
|
||||||
|
if ((filter != null) && !filter.isEmpty()) {
|
||||||
|
objects.addFilter(filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.debug(String.format("Category contains %d objects.", objects.size()));
|
||||||
|
// ContentBundle bundle;
|
||||||
|
// ACSObject object;
|
||||||
while (objects.next()) {
|
while (objects.next()) {
|
||||||
|
|
||||||
//Get the bundle
|
//Get the bundle
|
||||||
bundle = (ContentBundle) objects.getACSObject();
|
//bundle = (ContentBundle) objects.getACSObject();
|
||||||
|
final DataObject dobj = objects.getDataObject();
|
||||||
|
//bundle = (ContentBundle) DomainObjectFactory.newInstance(dobj);
|
||||||
//Get the default instance of the bundle
|
//Get the default instance of the bundle
|
||||||
object = bundle.getInstance(bundle.getDefaultLanguage());
|
//object = bundle.getInstance(bundle.getDefaultLanguage());
|
||||||
|
publication = (Publication) DomainObjectFactory.newInstance(dobj);
|
||||||
|
|
||||||
//Ignore object if it is not an publication
|
//Ignore object if it is not an publication
|
||||||
if (object instanceof Publication) {
|
// if (object instanceof Publication) {
|
||||||
publication = (Publication) object;
|
// publication = (Publication) object;
|
||||||
} else {
|
// } else {
|
||||||
logger.debug("Object is not a publication, ignoring it.");
|
// LOGGER.debug("Object is not a publication, ignoring it.");
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
|
|
||||||
//Ignore none live versions.
|
//Ignore none live versions.
|
||||||
if (!publication.isLiveVersion()) {
|
if (!publication.isLiveVersion()) {
|
||||||
logger.debug("Object is no a published version, "
|
LOGGER.debug("Object is no a published version, ignoring it.");
|
||||||
+ "ignoring it.");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Write the exported publication to the response.
|
//Write the exported publication to the response.
|
||||||
response.getWriter().append(exporter.exportPublication(
|
response.getWriter().append(exporter.exportPublication(publication));
|
||||||
publication));
|
|
||||||
//response.getWriter().append('\n');
|
//response.getWriter().append('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set the MimeType of the response
|
//Set the MimeType of the response
|
||||||
response.setContentType(exporter.getSupportedFormat().
|
response.setContentType(exporter.getSupportedFormat().getMimeType().getBaseType());
|
||||||
getMimeType().getBaseType());
|
|
||||||
//Force the browser to display an download dialog, and set
|
//Force the browser to display an download dialog, and set
|
||||||
//the filename for the downloaded file to the name of the
|
//the filename for the downloaded file to the name of the
|
||||||
//selected category.
|
//selected category.
|
||||||
|
|
@ -296,7 +308,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
publications = parameters.get("publication");
|
publications = parameters.get("publication");
|
||||||
|
|
||||||
if (publications.length < 1) {
|
if (publications.length < 1) {
|
||||||
logger.warn("Parameter 'publications' has no value(s). "
|
LOGGER.warn("Parameter 'publications' has no value(s). "
|
||||||
+ "Responding with status BAD_REQUEST.");
|
+ "Responding with status BAD_REQUEST.");
|
||||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
"Parameter 'publication' has no "
|
"Parameter 'publication' has no "
|
||||||
|
|
@ -312,7 +324,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
try {
|
try {
|
||||||
publicationId = new BigDecimal(publications[i]);
|
publicationId = new BigDecimal(publications[i]);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
logger.warn(String.format(
|
LOGGER.warn(String.format(
|
||||||
"Can't convert publication id "
|
"Can't convert publication id "
|
||||||
+ "'%s' on index %d to a BigDecimal.",
|
+ "'%s' on index %d to a BigDecimal.",
|
||||||
publications[i], i));
|
publications[i], i));
|
||||||
|
|
@ -369,16 +381,16 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Kernel.getConfig().languageIndependentItems()) {
|
if (Kernel.getConfig().languageIndependentItems()) {
|
||||||
FilterFactory ff = publicationsQuery.getFilterFactory();
|
final FilterFactory filterFactory = publicationsQuery.getFilterFactory();
|
||||||
Filter filter = ff.or().
|
final Filter filter = filterFactory.or().
|
||||||
addFilter(ff.equals("language", GlobalizationHelper.
|
addFilter(filterFactory.equals("language", GlobalizationHelper.
|
||||||
getNegotiatedLocale().getLanguage())).
|
getNegotiatedLocale().getLanguage())).
|
||||||
addFilter(ff.and().
|
addFilter(filterFactory.and().
|
||||||
addFilter(
|
addFilter(
|
||||||
ff.equals("language",
|
filterFactory.equals("language",
|
||||||
GlobalizationHelper.LANG_INDEPENDENT)).
|
GlobalizationHelper.LANG_INDEPENDENT)).
|
||||||
addFilter(ff.notIn("parent",
|
addFilter(filterFactory.notIn("parent",
|
||||||
"com.arsdigita.navigation.getParentIDsOfMatchedItems").
|
"com.arsdigita.navigation.getParentIDsOfMatchedItems").
|
||||||
set("language", GlobalizationHelper.
|
set("language", GlobalizationHelper.
|
||||||
getNegotiatedLocale().getLanguage())));
|
getNegotiatedLocale().getLanguage())));
|
||||||
publicationsQuery.addFilter(filter);
|
publicationsQuery.addFilter(filter);
|
||||||
|
|
@ -403,13 +415,11 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
SessionManager.getSession().retrieveQuery(
|
SessionManager.getSession().retrieveQuery(
|
||||||
"com.arsdigita.cms.contenttypes.getPublicationsForAuthor");
|
"com.arsdigita.cms.contenttypes.getPublicationsForAuthor");
|
||||||
|
|
||||||
final BigDecimal authorId = new BigDecimal(parameters.get(
|
final BigDecimal authorId = new BigDecimal(parameters.get("authorId")[0]);
|
||||||
"authorId")[0]);
|
|
||||||
final GenericPerson author = new GenericPerson(authorId);
|
final GenericPerson author = new GenericPerson(authorId);
|
||||||
final StringBuilder authorFilterBuilder = new StringBuilder();
|
final StringBuilder authorFilterBuilder = new StringBuilder();
|
||||||
authorFilterBuilder.append('(');
|
authorFilterBuilder.append('(');
|
||||||
authorFilterBuilder.append(String.format("authorId = %s",
|
authorFilterBuilder.append(String.format("authorId = %s", authorId.toString()));
|
||||||
authorId.toString()));
|
|
||||||
|
|
||||||
if (author.getAlias() != null) {
|
if (author.getAlias() != null) {
|
||||||
addAuthorAliasToFilter(authorFilterBuilder,
|
addAuthorAliasToFilter(authorFilterBuilder,
|
||||||
|
|
@ -421,22 +431,20 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
publicationsQuery.addFilter(authorFilterBuilder.toString());
|
publicationsQuery.addFilter(authorFilterBuilder.toString());
|
||||||
|
|
||||||
if (parameters.containsKey("year")) {
|
if (parameters.containsKey("year")) {
|
||||||
publicationsQuery.addFilter(String.format("yearOfPublication = %s",
|
publicationsQuery.addFilter(String.format("yearOfPublication = %s", parameters.get("year")[0]));
|
||||||
parameters.get(
|
|
||||||
"year")[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Kernel.getConfig().languageIndependentItems()) {
|
if (Kernel.getConfig().languageIndependentItems()) {
|
||||||
FilterFactory ff = publicationsQuery.getFilterFactory();
|
final FilterFactory filterFactory = publicationsQuery.getFilterFactory();
|
||||||
Filter filter = ff.or().
|
final Filter filter = filterFactory.or().
|
||||||
addFilter(ff.equals("language", GlobalizationHelper.
|
addFilter(filterFactory.equals("language", GlobalizationHelper.
|
||||||
getNegotiatedLocale().getLanguage())).
|
getNegotiatedLocale().getLanguage())).
|
||||||
addFilter(ff.and().
|
addFilter(filterFactory.and().
|
||||||
addFilter(
|
addFilter(
|
||||||
ff.equals("language",
|
filterFactory.equals("language",
|
||||||
GlobalizationHelper.LANG_INDEPENDENT)).
|
GlobalizationHelper.LANG_INDEPENDENT)).
|
||||||
addFilter(ff.notIn("parent",
|
addFilter(filterFactory.notIn("parent",
|
||||||
"com.arsdigita.navigation.getParentIDsOfMatchedItems").
|
"com.arsdigita.navigation.getParentIDsOfMatchedItems").
|
||||||
set("language", GlobalizationHelper.
|
set("language", GlobalizationHelper.
|
||||||
getNegotiatedLocale().getLanguage())));
|
getNegotiatedLocale().getLanguage())));
|
||||||
publicationsQuery.addFilter(filter);
|
publicationsQuery.addFilter(filter);
|
||||||
|
|
@ -457,7 +465,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
exportPublications(format, publicationIds, response);
|
exportPublications(format, publicationIds, response);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Export action needs either a publication id or a "
|
LOGGER.warn("Export action needs either a publication id or a "
|
||||||
+ "term id. Neither was found in the query parameters."
|
+ "term id. Neither was found in the query parameters."
|
||||||
+ "Responding with BAD_REQUEST status.");
|
+ "Responding with BAD_REQUEST status.");
|
||||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
|
|
@ -467,7 +475,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//Respond with 404 when the requested action is unknown.
|
//Respond with 404 when the requested action is unknown.
|
||||||
logger.warn(String.format("Unknown pathinfo '%s', "
|
LOGGER.warn(String.format("Unknown pathinfo '%s', "
|
||||||
+ "responding with 404...",
|
+ "responding with 404...",
|
||||||
path));
|
path));
|
||||||
response.sendError(HttpServletResponse.SC_NOT_FOUND,
|
response.sendError(HttpServletResponse.SC_NOT_FOUND,
|
||||||
|
|
@ -495,7 +503,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
|
|
||||||
if (exporter == null) {
|
if (exporter == null) {
|
||||||
logger.warn(String.format(
|
LOGGER.warn(String.format(
|
||||||
"The requested export format '%s' is not supported yet.",
|
"The requested export format '%s' is not supported yet.",
|
||||||
format));
|
format));
|
||||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||||
|
|
@ -513,20 +521,20 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
Publication publication = null;
|
Publication publication = null;
|
||||||
String publicationName = "publication";
|
String publicationName = "publication";
|
||||||
StringBuilder result = new StringBuilder();
|
final StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
for (BigDecimal publicationId : publicationIds) {
|
for (BigDecimal publicationId : publicationIds) {
|
||||||
try {
|
try {
|
||||||
//Get the publication
|
//Get the publication
|
||||||
publication = new Publication(publicationId);
|
publication = new Publication(publicationId);
|
||||||
logger.debug(String.format("OID of publication: %s",
|
LOGGER.debug(String.format("OID of publication: %s",
|
||||||
publication.getOID()));
|
publication.getOID()));
|
||||||
//Specialize the publication
|
//Specialize the publication
|
||||||
publication =
|
publication =
|
||||||
(Publication) DomainObjectFactory.newInstance(
|
(Publication) DomainObjectFactory.newInstance(
|
||||||
publication.getOID());
|
publication.getOID());
|
||||||
} catch (DataObjectNotFoundException ex) {
|
} catch (DataObjectNotFoundException ex) {
|
||||||
logger.warn(String.format("No publication found for id '%s'.",
|
LOGGER.warn(String.format("No publication found for id '%s'.",
|
||||||
publicationId.toPlainString()), ex);
|
publicationId.toPlainString()), ex);
|
||||||
response.sendError(HttpServletResponse.SC_NOT_FOUND,
|
response.sendError(HttpServletResponse.SC_NOT_FOUND,
|
||||||
String.format(
|
String.format(
|
||||||
|
|
@ -536,7 +544,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(String.format("Publication is of type: %s",
|
LOGGER.debug(String.format("Publication is of type: %s",
|
||||||
publication.getClass().getName()));
|
publication.getClass().getName()));
|
||||||
|
|
||||||
//Write the exported publication data to the response.
|
//Write the exported publication data to the response.
|
||||||
|
|
@ -580,4 +588,5 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
|
||||||
addAuthorAliasToFilter(builder, alias.getAlias());
|
addAuthorAliasToFilter(builder, alias.getAlias());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -615,7 +615,7 @@ public class ImporterUtil {
|
||||||
bundle.setContentSection(folder.getContentSection());
|
bundle.setContentSection(folder.getContentSection());
|
||||||
bundle.save();
|
bundle.save();
|
||||||
|
|
||||||
publication.addSeries(series);
|
publication.addSeries(series, 1);
|
||||||
|
|
||||||
if (publish) {
|
if (publish) {
|
||||||
publishItem(series);
|
publishItem(series);
|
||||||
|
|
@ -633,7 +633,7 @@ public class ImporterUtil {
|
||||||
if (!pretend) {
|
if (!pretend) {
|
||||||
collection.next();
|
collection.next();
|
||||||
final Series series = new Series(collection.getDataObject());
|
final Series series = new Series(collection.getDataObject());
|
||||||
publication.addSeries(series);
|
publication.addSeries(series, 1);
|
||||||
}
|
}
|
||||||
report.setCreated(false);
|
report.setCreated(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue