From 14ab3849252db31b7448a155dafb7e3cb155bfec Mon Sep 17 00:00:00 2001 From: jensp Date: Sun, 6 Feb 2011 12:31:47 +0000 Subject: [PATCH] =?UTF-8?q?-=20JavaDoc=20f=C3=BCr=20SciPublications,=20Sci?= =?UTF-8?q?PublicationsExporter=20und=20BibTeX=20Exporter=20(noch=20nicht?= =?UTF-8?q?=20komplett)=20-=20RIS=20Exporter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@736 8810af33-2d31-482b-a856-94f89814c4df --- ...lications.exporter.SciPublicationsExporter | 3 +- ....scipublications.exporter.ris.RisConverter | 13 + .../cms/scipublications/SciPublications.java | 33 +- .../SciPublicationsLoader.java | 1 + .../SciPublicationsServlet.java | 128 +++++-- .../exporter/PublicationFormat.java | 32 +- .../exporter/SciPublicationsExporter.java | 32 +- .../exporter/SciPublicationsExporters.java | 49 ++- .../exporter/bibtex/BibTeXExporter.java | 26 +- .../builders/AbstractBibTeXBuilder.java | 2 +- .../converters/AbstractBibTeXConverter.java | 85 ++++- .../ArticleInCollectedVolumeConverter.java | 20 +- .../bibtex/converters/BibTeXConverter.java | 34 +- .../bibtex/converters/BibTeXConverters.java | 63 +++- .../bibtex/converters/ExpertiseConverter.java | 10 +- .../converters/GreyLiteratureConverter.java | 8 +- .../converters/InProceedingsConverter.java | 3 +- .../converters/InternetArticleConverter.java | 1 - .../bibtex/converters/MonographConverter.java | 2 +- .../converters/PublicationConverter.java | 2 +- .../bibtex/converters/package-info.java | 5 + .../exporter/bibtex/package-info.java | 5 + .../exporter/ris/AbstractRisConverter.java | 123 +++++++ .../ArticleInCollectedVolumeConverter.java | 55 +++ .../ris/ArticleInJournalConverter.java | 61 ++++ .../ris/CollectedVolumeConverter.java | 46 +++ .../exporter/ris/ExpertiseConverter.java | 44 +++ .../exporter/ris/GreyLiteratureConverter.java | 44 +++ .../exporter/ris/InProceedingsConverter.java | 65 ++++ .../ris/InternetArticleConverter.java | 44 +++ .../exporter/ris/MonographConverter.java | 46 +++ .../exporter/ris/ProceedingsConverter.java | 49 +++ .../exporter/ris/PublicationConverter.java | 23 ++ .../PublicationWithPublisherConverter.java | 43 +++ .../exporter/ris/ReviewConverter.java | 15 + .../exporter/ris/RisBuilder.java | 105 ++++++ .../exporter/ris/RisConverter.java | 46 +++ .../exporter/ris/RisConverters.java | 80 +++++ .../exporter/ris/RisExporter.java | 54 +++ .../exporter/ris/RisFields.java | 335 ++++++++++++++++++ .../exporter/ris/RisTypes.java | 169 +++++++++ .../ris/UnsupportedCcmTypeException.java | 34 ++ .../exporter/ris/WorkingPaperConverter.java | 45 +++ .../cms/scipublications/package-info.java | 20 ++ 44 files changed, 2034 insertions(+), 69 deletions(-) create mode 100644 ccm-sci-publications/src/META-INF/services/com.arsdigita.cms.scipublications.exporter.ris.RisConverter create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/package-info.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/package-info.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/AbstractRisConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInCollectedVolumeConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInJournalConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/CollectedVolumeConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ExpertiseConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/GreyLiteratureConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/InProceedingsConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/InternetArticleConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/MonographConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ProceedingsConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/PublicationConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/PublicationWithPublisherConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ReviewConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisBuilder.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisConverters.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisExporter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisFields.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisTypes.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/UnsupportedCcmTypeException.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/WorkingPaperConverter.java create mode 100644 ccm-sci-publications/src/com/arsdigita/cms/scipublications/package-info.java diff --git a/ccm-sci-publications/src/META-INF/services/com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter b/ccm-sci-publications/src/META-INF/services/com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter index eb234126a..bc2c5bffb 100644 --- a/ccm-sci-publications/src/META-INF/services/com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter +++ b/ccm-sci-publications/src/META-INF/services/com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter @@ -1 +1,2 @@ - com.arsdigita.cms.scipublications.exporter.bibtex.BibTeXExporter \ No newline at end of file + com.arsdigita.cms.scipublications.exporter.bibtex.BibTeXExporter + com.arsdigita.cms.scipublications.exporter.ris.RisExporter \ No newline at end of file diff --git a/ccm-sci-publications/src/META-INF/services/com.arsdigita.cms.scipublications.exporter.ris.RisConverter b/ccm-sci-publications/src/META-INF/services/com.arsdigita.cms.scipublications.exporter.ris.RisConverter new file mode 100644 index 000000000..5fc2e0163 --- /dev/null +++ b/ccm-sci-publications/src/META-INF/services/com.arsdigita.cms.scipublications.exporter.ris.RisConverter @@ -0,0 +1,13 @@ +com.arsdigita.cms.scipublications.exporter.ris.ArticleInCollectedVolumeConverter +com.arsdigita.cms.scipublications.exporter.ris.ArticleInJournalConverter +com.arsdigita.cms.scipublications.exporter.ris.CollectedVolumeConverter +com.arsdigita.cms.scipublications.exporter.ris.ExpertiseConverter +com.arsdigita.cms.scipublications.exporter.ris.GreyLiteratureConverter +com.arsdigita.cms.scipublications.exporter.ris.InProceedingsConverter +com.arsdigita.cms.scipublications.exporter.ris.InternetArticleConverter +com.arsdigita.cms.scipublications.exporter.ris.MonographConverter +com.arsdigita.cms.scipublications.exporter.ris.ProceedingsConverter +com.arsdigita.cms.scipublications.exporter.ris.PublicationConverter +com.arsdigita.cms.scipublications.exporter.ris.PublicationWithPublisherConverter +com.arsdigita.cms.scipublications.exporter.ris.ReviewConverter +com.arsdigita.cms.scipublications.exporter.ris.WorkingPaperConverter \ No newline at end of file diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublications.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublications.java index e18364e25..93cbe0685 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublications.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublications.java @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ package com.arsdigita.cms.scipublications; import com.arsdigita.domain.DataObjectNotFoundException; @@ -7,18 +26,25 @@ import com.arsdigita.web.Application; import java.math.BigDecimal; /** + * This application provides the main entry point for all functions of + * the SciPublications module. The application will be mounted at + * /ccm/scipubliations/. The functions are accessed using + * an additional URL fragment. For example, if you want to access the + * export function, you will use the URL + * /ccm/scipublications/export/. * * @author Jens Pelzetter */ public class SciPublications extends Application { - public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.scipublications.SciPublications"; + public static final String BASE_DATA_OBJECT_TYPE = + "com.arsdigita.cms.scipublications.SciPublications"; - public SciPublications(DataObject dobj) { + public SciPublications(DataObject dobj) { super(dobj); } - public SciPublications(OID oid) throws DataObjectNotFoundException{ + public SciPublications(OID oid) throws DataObjectNotFoundException { super(oid); } @@ -30,5 +56,4 @@ public class SciPublications extends Application { public String getServletPath() { return "/scipublications/"; } - } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsLoader.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsLoader.java index deec5dc0f..52dc5c273 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsLoader.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsLoader.java @@ -49,6 +49,7 @@ public class SciPublicationsLoader extends PackageLoader { ApplicationType type = setup.run(); type.save(); + //Install the application and mount the app at 'scipublications'. if (!Application.isInstalled( SciPublications.BASE_DATA_OBJECT_TYPE, "/scipublications/")) { Application app = Application.createApplication(type, diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsServlet.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsServlet.java index b3073b686..140bae10e 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsServlet.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsServlet.java @@ -1,6 +1,24 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ package com.arsdigita.cms.scipublications; -import com.arsdigita.categorization.Categorization; import com.arsdigita.categorization.CategorizedCollection; import com.arsdigita.categorization.Category; import com.arsdigita.cms.ContentBundle; @@ -24,6 +42,43 @@ import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; /** + *

+ * The SciPublicationsServlet processes the + * {@link HttpServletRequest} and calls the requested actions. + * The available actions are: + *

+ *
+ *
export
+ *
+ *

+ * The export action exports content items of the type + * {@link Publication} in several formats, like BibTeX or RIS. + * The export action has the following query parameters: + *

+ *
+ *
format
+ *
Specifies the format which is used to export the publications.
+ *
publication
+ *
Specifies the publication(s) to export using the ID(s) of the + * publications. + * This parameter can occur more + * than one time. In this case, all publications specified by the parameters + * will be exported as a single file in specified format
+ *
category
+ *
Specifies a category using the OID of the category. If this + * parameter is present, all publications in the category and the subcategories + * of the category will exported as a single file in the specified format.
+ *
+ *

+ * The format argument is mandatory. Also their must be either one + * or more publication parameters or a category + * parameter. If the URL is not valid, the Servlet will respond with the + * BAD_REQUEST (400) HTTP status code. If one of the specified publications or + * the specified category can't be found, the Servlet will respond with the + * NOT_FOUND (404) HTTP status code. + *

+ *
+ *
* * @author Jens Pelzetter */ @@ -64,12 +119,9 @@ public class SciPublicationsServlet extends BaseApplicationServlet { logger.debug(String.format("path = %s", path)); + //Displays a text/plain page with a message. if (path.isEmpty()) { logger.debug("pathInfo is null, responding with default..."); - /*response.setContentType("application/text"); - response.setHeader("Content-Disposition", - "attachment; filename=ccm-publication-exporter.txt"); - response.getWriter().append("This is the sci-publication-exporter");*/ response.setContentType("text/plain"); response.getWriter().append("Please choose an application."); @@ -83,6 +135,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet { parameters = request.getParameterMap(); + //Get the format parameter if (parameters.containsKey("format")) { if (parameters.get("format").length == 1) { format = parameters.get("format")[0]; @@ -105,6 +158,9 @@ public class SciPublicationsServlet extends BaseApplicationServlet { } if (parameters.containsKey("category")) { + /* If the category parameter is present, retrieve the + * specified category and exports all publications in it. + */ Publication publication; SciPublicationsExporter exporter; String categoryIdStr; @@ -151,6 +207,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet { logger.debug(String.format("Category: %s", category.getName())); + //Get the exporter for the specified format. exporter = SciPublicationsExporters.getInstance(). getExporterForFormat( format); @@ -165,6 +222,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet { return; } + //Get the category. objects = category.getObjects(ACSObject.BASE_DATA_OBJECT_TYPE); logger.debug(String.format("Category contains %d objects.", objects.size())); @@ -172,9 +230,12 @@ public class SciPublicationsServlet extends BaseApplicationServlet { 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 { @@ -182,22 +243,30 @@ public class SciPublicationsServlet extends BaseApplicationServlet { 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'); + //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.bib", - category.getName())); + String.format("attachment; filename=%s.%s", + category.getName(), + exporter.getSupportedFormat(). + getFileExtension())); return; } else if (parameters.containsKey("publication")) { @@ -215,6 +284,8 @@ public class SciPublicationsServlet extends BaseApplicationServlet { return; } + //Retrieve the ids of the publication(s) to export from the + //request. BigDecimal publicationId; publicationIds = new ArrayList(); for (int i = 0; i < publications.length; i++) { @@ -234,6 +305,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet { publicationIds.add(publicationId); } + //Export the publictions. exportPublications(format, publicationIds, response); } else { @@ -247,6 +319,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet { } } else { + //Respond with 404 when the requested action is unknown. logger.warn(String.format("Unknown pathinfo '%s', " + "responding with 404...", path)); @@ -255,12 +328,21 @@ public class SciPublicationsServlet extends BaseApplicationServlet { } } + /** + * Helper method for exporting publications specified by a list of IDs. + * + * @param format The format to use. + * @param publicationIds The IDs of the publications to export + * @param response The {@link HttpServletResponse} to use + * @throws IOException Thrown by some methods called by this method. + */ private void exportPublications(final String format, final List publicationIds, final HttpServletResponse response) throws IOException { SciPublicationsExporter exporter; + //Get the exporter for the specified format. exporter = SciPublicationsExporters.getInstance().getExporterForFormat( format); @@ -276,26 +358,24 @@ public class SciPublicationsServlet extends BaseApplicationServlet { return; - - } + //Set the MimeType type of the response. response.setContentType(exporter.getSupportedFormat().getMimeType(). getBaseType()); Publication publication = null; String publicationName = "publication"; - for (BigDecimal publicationId : publicationIds) { try { + //Get the publication publication = new Publication(publicationId); logger.debug(String.format("OID of publication: %s", publication.getOID())); + //Specialize the publication publication = (Publication) DomainObjectFactory.newInstance(publication. getOID()); - - } catch (DataObjectNotFoundException ex) { logger.warn(String.format("No publication found for id '%s'.", publicationId.toPlainString()), ex); @@ -310,23 +390,31 @@ public class SciPublicationsServlet extends BaseApplicationServlet { logger.debug(String.format("Publication is of type: %s", publication.getClass().getName())); + //Write the exported publication data to the response. response.getWriter().append(exporter.exportPublication(publication)); - response.getWriter().append('\n'); + //response.getWriter().append('\n'); publicationName = publication.getName(); } - + //Force the browser to show a download dialog. if (publicationIds.size() == 1) { + //If only one publication is exported, use the name (URL) of the + //publication as filename. response.setHeader("Content-Disposition", - String.format("attachment; filename=%s.bib", - publicationName)); - - + String.format("attachment; filename=%s.%s", + publicationName, + exporter.getSupportedFormat(). + getFileExtension())); } else { + //If more than one publication is exported, use 'publications' as + //filename. response.setHeader("Content-Disposition", - "attachment; filename=publications.bib"); + String.format( + "attachment; filename=publications.%s", + exporter.getSupportedFormat(). + getFileExtension())); } } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/PublicationFormat.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/PublicationFormat.java index aa60b81a0..dc7f1dce7 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/PublicationFormat.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/PublicationFormat.java @@ -1,15 +1,45 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ package com.arsdigita.cms.scipublications.exporter; import javax.activation.MimeType; /** + * Describes the format provided by an implementation of + * {@link SciPublicationsExporter}. * - * @author jensp + * @author Jens Pelzetter */ public class PublicationFormat { + /** + * Name of the format. + */ private String name; + /** + * MimeType to use for files of the format. + */ private MimeType mimeType; + /** + * File extension for files of the format. + */ private String fileExtension; public PublicationFormat() { diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporter.java index d97cb9950..8974852eb 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporter.java @@ -1,15 +1,45 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ package com.arsdigita.cms.scipublications.exporter; import com.arsdigita.cms.contenttypes.Publication; /** + * This interface describes the methods provided by all publication exporters. * - * @author jensp + * @author Jens Pelzetter */ public interface SciPublicationsExporter { + /** + * + * @return A description of the export format provided by this exporter. + */ PublicationFormat getSupportedFormat(); + /** + * Exports an publication to the format provided by this exporter. + * + * @param publication The publication to export. + * @return The data of the publication in the provided export format. + */ String exportPublication(Publication publication); } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporters.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporters.java index 418e31790..87b8cddb5 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporters.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporters.java @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ package com.arsdigita.cms.scipublications.exporter; import java.util.ArrayList; @@ -8,22 +27,36 @@ import java.util.ServiceLoader; import org.apache.log4j.Logger; /** + * This class provides access to implementations of the + * {@link SciPublicationsExporter} interface. It is implemented as a Singleton. * - * @author jensp + * @author Jens Pelzetter */ public final class SciPublicationsExporters { private static final Logger logger = Logger.getLogger( SciPublicationsExporters.class); + /** + * Association of the format and the responsible exporters. + */ private Map exporters = new HashMap(); + /** + * The one and only instance of this class. The pattern here ensures that + * the instance is created at the first access, but not earlier. + */ private static class Instance { private static final SciPublicationsExporters INSTANCE = new SciPublicationsExporters(); } + /** + * Creates the instance. Uses the {@link ServiceLoader} to find all available + * implementations of {@link SciPublicationsExporter} and puts them into + * the {@link #exporters} map. + */ private SciPublicationsExporters() { logger.debug("Creating SciPublicationsExporter instance..."); ServiceLoader exporterServices; @@ -42,14 +75,28 @@ public final class SciPublicationsExporters { logger.debug(String.format("Found %d exporters.", exporters.size())); } + /** + * @return The instance of this class. + */ public static SciPublicationsExporters getInstance() { return Instance.INSTANCE; } + /** + * Retrieves the exporter for the specified format. + * + * @param format The format which should be supported by the exporter. + * @return The exporter for the specified format, or null, if + * there is no exporter which supports the specified format. + */ public SciPublicationsExporter getExporterForFormat(final String format) { return exporters.get(format); } + /** + * + * @return A list of all supported export formats. + */ public List getSupportedFormats() { List supportedFormats; diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/BibTeXExporter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/BibTeXExporter.java index 1cd33254b..7b7381353 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/BibTeXExporter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/BibTeXExporter.java @@ -1,16 +1,40 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ package com.arsdigita.cms.scipublications.exporter.bibtex; import com.arsdigita.cms.contenttypes.Publication; import com.arsdigita.cms.scipublications.exporter.PublicationFormat; import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter; +import com.arsdigita.cms.scipublications.exporter.bibtex.converters.BibTeXConverter; import com.arsdigita.cms.scipublications.exporter.bibtex.converters.BibTeXConverters; import javax.activation.MimeType; import javax.activation.MimeTypeParseException; import org.apache.log4j.Logger; /** + * An exporter for the BibTeX format. The actual conversion between the CCM + * publication content types and the BibTeX format is done by the converters + * in the com.arsdigita.cms.scipublications.exporter.bibtex which + * are implementation the {@link BibTeXConverter} interface. * - * @author jensp + * @author Jens Pelzetter */ public class BibTeXExporter implements SciPublicationsExporter { diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/builders/AbstractBibTeXBuilder.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/builders/AbstractBibTeXBuilder.java index 4cf445c67..5bc29e4a9 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/builders/AbstractBibTeXBuilder.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/builders/AbstractBibTeXBuilder.java @@ -81,7 +81,7 @@ public abstract class AbstractBibTeXBuilder implements BibTeXBuilder { builder); } - builder.append('}'); + builder.append("}\n"); return builder.toString(); } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/AbstractBibTeXConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/AbstractBibTeXConverter.java index 178fc482c..e0e7b679f 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/AbstractBibTeXConverter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/AbstractBibTeXConverter.java @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ package com.arsdigita.cms.scipublications.exporter.bibtex.converters; import com.arsdigita.cms.contenttypes.AuthorshipCollection; @@ -10,13 +29,21 @@ import com.arsdigita.cms.scipublications.exporter.bibtex.builders.BibTeXField; import com.arsdigita.cms.scipublications.exporter.bibtex.builders.UnsupportedFieldException; /** + * An abstract implementation of the {@link BibTeXConverter} providing common + * functionality for all converters. To create the BibTeX data, implementations + * of the {@link BibTeXBuilder} interface are used. * - * @author jensp + * @author Jens Pelzetter */ public abstract class AbstractBibTeXConverter implements BibTeXConverter { private BibTeXBuilder bibTeXBuilder; + /** + * Convert the authors of a publication to BibTeX. + * + * @param publication The publication to use. + */ protected void convertAuthors(final Publication publication) { AuthorshipCollection authors; @@ -32,11 +59,24 @@ public abstract class AbstractBibTeXConverter implements BibTeXConverter { } } + /** + * Convert the title of a publication to BibTeX. + * + * @param publication The publication to use. + * @throws UnsupportedFieldException If the title field is not supported by + * the BibTeX type. + */ protected void convertTitle(final Publication publication) throws UnsupportedFieldException { getBibTeXBuilder().setField(BibTeXField.TITLE, publication.getTitle()); } + /** + * Converts the year of publication to BibTeX. + * + * @param publication + * @throws UnsupportedFieldException + */ protected void convertYear(final Publication publication) throws UnsupportedFieldException { if (publication.getYearOfPublication() != null) { @@ -46,6 +86,12 @@ public abstract class AbstractBibTeXConverter implements BibTeXConverter { } } + /** + * Converts the publisher to BibTeX. + * + * @param publication + * @throws UnsupportedFieldException + */ protected void convertPublisher(final PublicationWithPublisher publication) throws UnsupportedFieldException { if (publication.getPublisher() != null) { @@ -66,6 +112,12 @@ public abstract class AbstractBibTeXConverter implements BibTeXConverter { } } + /** + * Convert the ISBN to BibTeX. + * + * @param publication + * @throws UnsupportedFieldException + */ protected void convertISBN(final PublicationWithPublisher publication) throws UnsupportedFieldException { if (publication.getISBN() != null) { @@ -74,6 +126,12 @@ public abstract class AbstractBibTeXConverter implements BibTeXConverter { } } + /** + * Convert the volume to BibTeX. + * + * @param publication + * @throws UnsupportedFieldException + */ protected void convertVolume(final PublicationWithPublisher publication) throws UnsupportedFieldException { if (publication.getVolume() != null) { @@ -82,6 +140,12 @@ public abstract class AbstractBibTeXConverter implements BibTeXConverter { } } + /** + * Convert the edition to BibTeX. + * + * @param publication + * @throws UnsupportedFieldException + */ protected void convertEdition(final PublicationWithPublisher publication) throws UnsupportedFieldException { if (publication.getEdition() != null) { @@ -90,10 +154,15 @@ public abstract class AbstractBibTeXConverter implements BibTeXConverter { } } + /** + * Convert the series to BibTeX. + * + * @param publication + * @throws UnsupportedFieldException + */ protected void convertSeries(final Publication publication) throws UnsupportedFieldException { - SeriesCollection seriesColl = - publication.getSeries(); + SeriesCollection seriesColl = publication.getSeries(); if ((seriesColl != null) && (seriesColl.size() > 0)) { seriesColl.next(); @@ -105,6 +174,12 @@ public abstract class AbstractBibTeXConverter implements BibTeXConverter { } } + /** + * Retrieves to BibTeX builder for the converter. Uses the implementation + * of {@link #getBibTeXType()} for get the BibTeX type. + * + * @return The BibTeX builder for the converter. + */ protected BibTeXBuilder getBibTeXBuilder() { if (bibTeXBuilder == null) { bibTeXBuilder = BibTeXBuilders.getInstance(). @@ -114,5 +189,9 @@ public abstract class AbstractBibTeXConverter implements BibTeXConverter { return bibTeXBuilder; } + /** + * + * @return The BibTeX type to use for building the BibTeX data. + */ protected abstract String getBibTeXType(); } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ArticleInCollectedVolumeConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ArticleInCollectedVolumeConverter.java index b5f5b5592..fd25579bf 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ArticleInCollectedVolumeConverter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ArticleInCollectedVolumeConverter.java @@ -54,6 +54,10 @@ public class ArticleInCollectedVolumeConverter extends AbstractBibTeXConverter { if (article.getCollectedVolume().getPublisher() == null) { builder.setField(BibTeXField.PUBLISHER, ""); + } else { + builder.setField(BibTeXField.PUBLISHER, + article.getCollectedVolume().getPublisher(). + getTitle()); } if (article.getCollectedVolume().getVolume() != null) { @@ -61,6 +65,12 @@ public class ArticleInCollectedVolumeConverter extends AbstractBibTeXConverter { article.getCollectedVolume().getVolume(). toString()); } + + if (article.getCollectedVolume().getEdition() != null) { + builder.setField(BibTeXField.EDITION, + article.getCollectedVolume().getEdition()); + } + SeriesCollection seriesColl = article.getCollectedVolume().getSeries(); if ((seriesColl != null) && (seriesColl.size() > 0)) { @@ -72,13 +82,8 @@ public class ArticleInCollectedVolumeConverter extends AbstractBibTeXConverter { seriesColl.close(); } - } else { - builder.setField(BibTeXField.PUBLISHER, - article.getCollectedVolume().getPublisher(). - getTitle()); } - if (article.getChapter() != null) { builder.setField(BibTeXField.CHAPTER, article.getChapter()); } @@ -90,10 +95,7 @@ public class ArticleInCollectedVolumeConverter extends AbstractBibTeXConverter { article.getPagesTo())); } - if (article.getCollectedVolume().getEdition() != null) { - builder.setField(BibTeXField.EDITION, - article.getCollectedVolume().getEdition()); - } + } catch (UnsupportedFieldException ex) { logger.warn("Tried to set unsupported BibTeX field while " + "converting a publication"); diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverter.java index 0e190cdd8..93cabbf9e 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverter.java @@ -1,15 +1,45 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ package com.arsdigita.cms.scipublications.exporter.bibtex.converters; import com.arsdigita.cms.contenttypes.Publication; /** + * Interface for the BibTeX converters. * - * @param - * @author jensp + * @author Jens Pelzetter */ public interface BibTeXConverter { + /** + * Converts a publication. + * + * @param publication The publication to convert. + * @return The data of the publication converted to BibTeX. + * @throws UnsupportedCcmTypeException If the provided publication is of + * a type which is not supported by this converter. + */ String convert(Publication publication); + /** + * @return The CCM publication type supported by this converter. + */ String getCcmType(); } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverters.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverters.java index bcd29277a..4ee289b76 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverters.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverters.java @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ package com.arsdigita.cms.scipublications.exporter.bibtex.converters; import com.arsdigita.cms.contenttypes.Publication; @@ -5,29 +24,36 @@ import com.arsdigita.cms.contenttypes.PublicationWithPublisher; import java.util.HashMap; import java.util.Map; import java.util.ServiceLoader; -import java.util.logging.Level; import org.apache.log4j.Logger; /** + * Provides easy access to all available BibTeX converters. * - * @author jensp + * @author Jens Pelzetter */ public class BibTeXConverters { - private static final Logger logger = Logger.getLogger(BibTeXConverters.class); - + private static final Logger logger = + Logger.getLogger(BibTeXConverters.class); + /** + * Associates the available converters with their supported CCM types. + */ private Map converters = new HashMap(); + /** + * Finds all available {@link BibTeXConverter}s and puts them into the + * map. + */ private BibTeXConverters() { logger.debug("Loading BibTeX converters..."); ServiceLoader converterServices; converterServices = ServiceLoader.load(BibTeXConverter.class); - for(BibTeXConverter converter : converterServices) { + for (BibTeXConverter converter : converterServices) { logger.debug(String.format("Found converter for CCM type '%s'...", - converter.getCcmType())); + converter.getCcmType())); converters.put(converter.getCcmType(), converter); } logger.debug(String.format("Found %d converters.", converters.size())); @@ -38,33 +64,48 @@ public class BibTeXConverters { private static BibTeXConverters INSTANCE = new BibTeXConverters(); } + /** + * @return The instance of this class. + */ public static BibTeXConverters getInstance() { return Instance.INSTANCE; } + /** + * Converts the provided publication to BibTeX using the responsible + * converter. If no converter is found, the + * {@link PublicationWithPublisherConverter} or the + * {@link PublicationConverter} are used, depending one the base type of + * the publication. + * + * @param publication The publication to convert. + * @return The publication converted to BibTeX. + */ public String convert(final Publication publication) { try { BibTeXConverter converter; logger.debug(String.format("Trying to find converter for type '%s'.", publication.getClass().getName())); + //Get the responsible converter converter = converters.get(publication.getClass().getName()); if (converter == null) { logger.debug("No converter found..."); if (publication instanceof PublicationWithPublisher) { - logger.debug("Publication is a PublicationWithPublisher, using" + - "converter for this type."); + logger.debug("Publication is a PublicationWithPublisher, using" + + "converter for this type."); converter = converters.get(PublicationWithPublisher.class.getName()); } else { - logger.debug("Publication is a Publication, using" + - "converter for this type."); + logger.debug("Publication is a Publication, using" + + "converter for this type."); converter = converters.get(Publication.class.getName()); } } + //Create an new instance of this converter. converter = converter.getClass().newInstance(); + //Run the converter. return converter.convert(publication); - } catch (InstantiationException ex) { logger.warn("Failed to instaniate BibTeX converter.", ex); return null; diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ExpertiseConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ExpertiseConverter.java index 5773d96d7..042d525c9 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ExpertiseConverter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ExpertiseConverter.java @@ -12,7 +12,8 @@ import org.apache.log4j.Logger; */ public class ExpertiseConverter extends AbstractBibTeXConverter { - private static final Logger logger = Logger.getLogger(ExpertiseConverter.class); + private static final Logger logger = Logger.getLogger( + ExpertiseConverter.class); @Override protected String getBibTeXType() { @@ -23,7 +24,7 @@ public class ExpertiseConverter extends AbstractBibTeXConverter { BibTeXBuilder builder; Expertise expertise; - if (!(publication instanceof Expertise)) { + if (!(publication instanceof Expertise)) { throw new UnsupportedCcmTypeException( String.format("The ExpertiseConverter only " + "supports publication types which are of the" @@ -39,11 +40,11 @@ public class ExpertiseConverter extends AbstractBibTeXConverter { expertise = (Expertise) publication; - convertAuthors(publication); + convertAuthors(publication); builder = getBibTeXBuilder(); try { convertTitle(publication); - convertYear(publication); + convertYear(publication); } catch (UnsupportedFieldException ex) { logger.warn("Tried to set unsupported BibTeX field while " + "converting a publication"); @@ -55,5 +56,4 @@ public class ExpertiseConverter extends AbstractBibTeXConverter { public String getCcmType() { return Expertise.class.getName(); } - } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/GreyLiteratureConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/GreyLiteratureConverter.java index 76f63c95a..27e30779e 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/GreyLiteratureConverter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/GreyLiteratureConverter.java @@ -12,7 +12,8 @@ import org.apache.log4j.Logger; */ public class GreyLiteratureConverter extends AbstractBibTeXConverter { - private static final Logger logger = Logger.getLogger(GreyLiteratureConverter.class); + private static final Logger logger = Logger.getLogger( + GreyLiteratureConverter.class); @Override protected String getBibTeXType() { @@ -23,7 +24,7 @@ public class GreyLiteratureConverter extends AbstractBibTeXConverter { BibTeXBuilder builder; GreyLiterature greyLiterature; - if (!(publication instanceof GreyLiterature)) { + if (!(publication instanceof GreyLiterature)) { throw new UnsupportedCcmTypeException( String.format("The GreyLiteratureConverter only " + "supports publication types which are of the" @@ -39,7 +40,7 @@ public class GreyLiteratureConverter extends AbstractBibTeXConverter { greyLiterature = (GreyLiterature) publication; - convertAuthors(publication); + convertAuthors(publication); builder = getBibTeXBuilder(); try { convertTitle(publication); @@ -55,5 +56,4 @@ public class GreyLiteratureConverter extends AbstractBibTeXConverter { public String getCcmType() { return GreyLiterature.class.getName(); } - } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/InProceedingsConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/InProceedingsConverter.java index 1d807bba6..9e7032174 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/InProceedingsConverter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/InProceedingsConverter.java @@ -3,7 +3,6 @@ package com.arsdigita.cms.scipublications.exporter.bibtex.converters; import com.arsdigita.cms.contenttypes.InProceedings; import com.arsdigita.cms.contenttypes.Proceedings; import com.arsdigita.cms.contenttypes.Publication; -import com.arsdigita.cms.contenttypes.SeriesCollection; import com.arsdigita.cms.scipublications.exporter.bibtex.builders.BibTeXBuilder; import com.arsdigita.cms.scipublications.exporter.bibtex.builders.BibTeXField; import com.arsdigita.cms.scipublications.exporter.bibtex.builders.UnsupportedFieldException; @@ -67,7 +66,7 @@ public class InProceedingsConverter extends AbstractBibTeXConverter { proceedings.getTitle()); convertVolume(proceedings); - convertSeries(publication); + convertSeries(proceedings); if (proceedings.getOrganizerOfConference() != null) { builder.setField(BibTeXField.ORGANIZATION, diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/InternetArticleConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/InternetArticleConverter.java index 5352fb796..c7ea94199 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/InternetArticleConverter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/InternetArticleConverter.java @@ -3,7 +3,6 @@ package com.arsdigita.cms.scipublications.exporter.bibtex.converters; import com.arsdigita.cms.contenttypes.InternetArticle; import com.arsdigita.cms.contenttypes.Publication; import com.arsdigita.cms.scipublications.exporter.bibtex.builders.BibTeXBuilder; -import com.arsdigita.cms.scipublications.exporter.bibtex.builders.BibTeXField; import com.arsdigita.cms.scipublications.exporter.bibtex.builders.UnsupportedFieldException; import org.apache.log4j.Logger; diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/MonographConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/MonographConverter.java index a9080b04d..fb30bac55 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/MonographConverter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/MonographConverter.java @@ -46,7 +46,7 @@ public class MonographConverter extends AbstractBibTeXConverter { convertEdition(monograph); } catch (UnsupportedFieldException ex) { logger.warn("Tried to set unsupported BibTeX field while " - + "converting a publication"); + + "converting a publication", ex); } return getBibTeXBuilder().toBibTeX(); diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/PublicationConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/PublicationConverter.java index 2ad8b69bd..5696f35ad 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/PublicationConverter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/PublicationConverter.java @@ -21,7 +21,7 @@ public class PublicationConverter extends AbstractBibTeXConverter { convertYear(publication); } catch (UnsupportedFieldException ex) { logger.warn("Tried to set unsupported BibTeX field while " - + "converting a publication"); + + "converting a publication", ex); } return getBibTeXBuilder().toBibTeX(); diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/package-info.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/package-info.java new file mode 100644 index 000000000..58987398f --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/package-info.java @@ -0,0 +1,5 @@ +/** + * Provides the converters for are converting the CCM publication content types + * to BibTeX. + */ +package com.arsdigita.cms.scipublications.exporter.bibtex.converters; diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/package-info.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/package-info.java new file mode 100644 index 000000000..0d2c4a02e --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/package-info.java @@ -0,0 +1,5 @@ +/** + * The com.arsdigita.cms.scipublications.exporter.bibtex package + * provides an exporter for the BibTeX format. + */ +package com.arsdigita.cms.scipublications.exporter.bibtex; diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/AbstractRisConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/AbstractRisConverter.java new file mode 100644 index 000000000..3a98dfc73 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/AbstractRisConverter.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.AuthorshipCollection; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.PublicationWithPublisher; +import com.arsdigita.cms.contenttypes.SeriesCollection; + +/** + * An abstract base implementation of the {@link RisConverter} interface + * providing common functionality. + * + * @author Jens Pelzetter + */ +public abstract class AbstractRisConverter implements RisConverter { + + private RisBuilder risBuilder = new RisBuilder(); + + protected void convertAuthors(final Publication publication) { + AuthorshipCollection authors; + + authors = publication.getAuthors(); + if (authors != null) { + while (authors.next()) { + if (authors.isEditor()) { + getRisBuilder().addField(RisFields.AU, + String.format("%s,%s", + authors.getAuthor(). + getSurname(), + authors.getAuthor(). + getGivenName())); + } else { + getRisBuilder().addField(RisFields.ED, + String.format("%s,%s", + authors.getAuthor(). + getSurname(), + authors.getAuthor(). + getGivenName())); + } + } + } + } + + protected void convertTitle(final Publication publication) { + getRisBuilder().addField(RisFields.TI, + publication.getTitle()); + } + + protected void convertYear(final Publication publication) { + getRisBuilder().addField(RisFields.PY, + String.format("%d///", publication. + getYearOfPublication())); + } + + protected void convertPublisher(final PublicationWithPublisher publication) { + if (publication.getPublisher() != null) { + if ((publication.getPublisher().getPlace() != null) + && !(publication.getPublisher().getPlace().isEmpty())) { + getRisBuilder().addField(RisFields.CY, + publication.getPublisher().getPlace()); + } + + getRisBuilder().addField(RisFields.PB, + publication.getPublisher().getTitle()); + } + } + + protected void convertISBN(final PublicationWithPublisher publication) { + if (publication.getISBN() != null) { + getRisBuilder().addField(RisFields.SN, + publication.getISBN()); + } + } + + protected void convertVolume(final PublicationWithPublisher publication) { + if (publication.getVolume() != null) { + getRisBuilder().addField(RisFields.VL, + publication.getVolume().toString()); + } + } + + protected void convertEdition(final PublicationWithPublisher publication) { + if (publication.getEdition() != null) { + getRisBuilder().addField(RisFields.ET, + publication.getEdition()); + } + } + + protected void convertSeries(final Publication publication) { + SeriesCollection seriesColl = publication.getSeries(); + if ((seriesColl != null) && (seriesColl.size() > 0)) { + + seriesColl.next(); + + getRisBuilder().addField(RisFields.T3, + seriesColl.getSeries().getTitle()); + + seriesColl.close(); + } + } + + protected RisBuilder getRisBuilder() { + return risBuilder; + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInCollectedVolumeConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInCollectedVolumeConverter.java new file mode 100644 index 000000000..ebae2457f --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInCollectedVolumeConverter.java @@ -0,0 +1,55 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.ArticleInCollectedVolume; +import com.arsdigita.cms.contenttypes.Publication; + +/** + * + * @author jensp + */ +public class ArticleInCollectedVolumeConverter extends AbstractRisConverter { + + public String convert(final Publication publication) { + ArticleInCollectedVolume article; + + if (!(publication instanceof ArticleInCollectedVolume)) { + throw new UnsupportedCcmTypeException( + String.format("The ArticleInCollectedVolumeConverter only " + + "supports publication types which are of the" + + "type ArticleInCollectedVolume or which are " + + "extending " + + "ArticleInCollectedVolume. The " + + "provided publication is of type '%s' which " + + "is not of type " + + "ArticleInCollectedVolume and does not " + + "extends ArticleInCollectedVolume.", + publication.getClass().getName())); + } + + article = (ArticleInCollectedVolume) publication; + + getRisBuilder().setType(RisTypes.CHAP); + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + if (article.getCollectedVolume() != null) { + getRisBuilder().addField(RisFields.BT, + article.getCollectedVolume().getTitle()); + + } + + if (article.getPagesFrom() != null) { + getRisBuilder().addField(RisFields.SP, + article.getPagesFrom().toString()); + getRisBuilder().addField(RisFields.EP, + article.getPagesTo().toString()); + } + + return getRisBuilder().toRis(); + } + + public String getCcmType() { + return ArticleInCollectedVolume.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInJournalConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInJournalConverter.java new file mode 100644 index 000000000..f1be92dd4 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInJournalConverter.java @@ -0,0 +1,61 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.ArticleInJournal; +import com.arsdigita.cms.contenttypes.Publication; + +/** + * + * @author Jens Pelzetter + */ +public class ArticleInJournalConverter extends AbstractRisConverter { + + @Override + public String convert(final Publication publication) { + ArticleInJournal article; + + if (!(publication instanceof ArticleInJournal)) { + throw new UnsupportedCcmTypeException( + String.format("The ArticleInJournalConverter only " + + "supports publication types which are of the" + + "type ArticleInJournal or which are " + + "extending " + + "ArticleInJournal. The " + + "provided publication is of type '%s' which " + + "is not of type " + + "ArticleInJournal and does not " + + "extends ArticleInJournal.", + publication.getClass().getName())); + } + + article = (ArticleInJournal) publication; + + getRisBuilder().setType(RisTypes.MGZN); + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + if (article.getJournal() != null) { + getRisBuilder().addField(RisFields.JF, + article.getJournal().getTitle()); + } + + if (article.getVolume() != null) { + getRisBuilder().addField(RisFields.VL, + article.getVolume().toString()); + } + + if (article.getPagesFrom() != null) { + getRisBuilder().addField(RisFields.SP, + article.getPagesFrom().toString()); + getRisBuilder().addField(RisFields.EP, + article.getPagesTo().toString()); + } + + return getRisBuilder().toRis(); + } + + @Override + public String getCcmType() { + return ArticleInJournalConverter.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/CollectedVolumeConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/CollectedVolumeConverter.java new file mode 100644 index 000000000..4214df785 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/CollectedVolumeConverter.java @@ -0,0 +1,46 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.CollectedVolume; +import com.arsdigita.cms.contenttypes.Publication; + +/** + * + * @author Jens Pelzetter + */ +public class CollectedVolumeConverter extends AbstractRisConverter { + + @Override + public String convert(final Publication publication) { + CollectedVolume collectedVolume; + + if (!(publication instanceof CollectedVolume)) { + throw new UnsupportedCcmTypeException( + String.format("The PublicationWithPublicationConverter only " + + "supports publication types which are " + + "extending CollectedVolume. The " + + "provided publication is of type '%s' which " + + "does not extends " + + "CollectedVolume.", + publication.getClass().getName())); + } + + collectedVolume = (CollectedVolume) publication; + + getRisBuilder().setType(RisTypes.BOOK); + convertAuthors(publication); + + convertTitle(publication); + convertYear(publication); + + convertPublisher(collectedVolume); + convertISBN(collectedVolume); + convertEdition(collectedVolume); + + return getRisBuilder().toRis(); + } + + @Override + public String getCcmType() { + return CollectedVolume.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ExpertiseConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ExpertiseConverter.java new file mode 100644 index 000000000..6f5f9a246 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ExpertiseConverter.java @@ -0,0 +1,44 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.Expertise; +import com.arsdigita.cms.contenttypes.Publication; + +/** + * + * @author Jens Pelzetter + */ +public class ExpertiseConverter extends AbstractRisConverter { + + @Override + public String convert(final Publication publication) { + Expertise expertise; + + if (!(publication instanceof Expertise)) { + throw new UnsupportedCcmTypeException( + String.format("The ExpertiseConverter only " + + "supports publication types which are of the" + + "type Expertise or which are " + + "extending " + + "Expertise. The " + + "provided publication is of type '%s' which " + + "is not of type " + + "Expertise and does not " + + "extends Expertise.", + publication.getClass().getName())); + } + + expertise = (Expertise) publication; + + getRisBuilder().setType(RisTypes.GEN); + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + return getRisBuilder().toRis(); + } + + @Override + public String getCcmType() { + return Expertise.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/GreyLiteratureConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/GreyLiteratureConverter.java new file mode 100644 index 000000000..334b5f353 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/GreyLiteratureConverter.java @@ -0,0 +1,44 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.GreyLiterature; +import com.arsdigita.cms.contenttypes.Publication; + +/** + * + * @author Jens Pelzetter + */ +public class GreyLiteratureConverter extends AbstractRisConverter { + + @Override + public String convert(final Publication publication) { + GreyLiterature greyLiterature; + + if (!(publication instanceof GreyLiterature)) { + throw new UnsupportedCcmTypeException( + String.format("The GreyLiteratureConverter only " + + "supports publication types which are of the" + + "type GreyLiterature or which are " + + "extending " + + "GreyLiterature. The " + + "provided publication is of type '%s' which " + + "is not of type " + + "GreyLiterature and does not " + + "extends GreyLiterature.", + publication.getClass().getName())); + } + + greyLiterature = (GreyLiterature) publication; + + getRisBuilder().setType(RisTypes.GEN); + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + return getRisBuilder().toRis(); + } + + @Override + public String getCcmType() { + return GreyLiterature.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/InProceedingsConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/InProceedingsConverter.java new file mode 100644 index 000000000..c0e2bd146 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/InProceedingsConverter.java @@ -0,0 +1,65 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.InProceedings; +import com.arsdigita.cms.contenttypes.Proceedings; +import com.arsdigita.cms.contenttypes.Publication; + +/** + * + * @author Jens Pelzetter + */ +public class InProceedingsConverter extends AbstractRisConverter { + + @Override + public String convert(final Publication publication) { + InProceedings inProceedings; + + if (!(publication instanceof InProceedings)) { + throw new UnsupportedCcmTypeException( + String.format("The InProceedingsConverter only " + + "supports publication types which are of the" + + "type InProceedings or which are " + + "extending " + + "InProceedings. The " + + "provided publication is of type '%s' which " + + "is not of type " + + "InProceedings and does not " + + "extends InProceedings.", + publication.getClass().getName())); + } + + inProceedings = (InProceedings) publication; + + getRisBuilder().setType(RisTypes.GEN); + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + if (inProceedings.getPagesFrom() != null) { + getRisBuilder().addField(RisFields.SP, + inProceedings.getPagesFrom().toString()); + getRisBuilder().addField(RisFields.EP, + inProceedings.getPagesTo().toString()); + } + + if(inProceedings.getProceedings() != null) { + Proceedings proceedings; + + proceedings = inProceedings.getProceedings(); + + getRisBuilder().addField(RisFields.BT, + proceedings.getTitle()); + + convertVolume(proceedings); + convertSeries(proceedings); + convertPublisher(proceedings); + } + + return getRisBuilder().toString(); + } + + @Override + public String getCcmType() { + return InProceedings.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/InternetArticleConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/InternetArticleConverter.java new file mode 100644 index 000000000..11f8fb02a --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/InternetArticleConverter.java @@ -0,0 +1,44 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.InternetArticle; +import com.arsdigita.cms.contenttypes.Publication; + +/** + * + * @author Jens Pelzetter + */ +public class InternetArticleConverter extends AbstractRisConverter { + + @Override + public String convert(final Publication publication) { + InternetArticle article; + + if (!(publication instanceof InternetArticle)) { + throw new UnsupportedCcmTypeException( + String.format("The InternetArticleConverter only " + + "supports publication types which are of the" + + "type InternetArticle or which are " + + "extending " + + "InternetArticle. The " + + "provided publication is of type '%s' which " + + "is not of type " + + "InternetArticle and does not " + + "extends InternetArticle.", + publication.getClass().getName())); + } + + article = (InternetArticle) publication; + + getRisBuilder().setType(RisTypes.GEN); + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + return getRisBuilder().toRis(); + } + + @Override + public String getCcmType() { + return InternetArticle.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/MonographConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/MonographConverter.java new file mode 100644 index 000000000..3731d3678 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/MonographConverter.java @@ -0,0 +1,46 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.Monograph; +import com.arsdigita.cms.contenttypes.Publication; + +/** + * + * @author Jens Pelzetter + */ +public class MonographConverter extends AbstractRisConverter { + + @Override + public String convert(final Publication publication) { + Monograph monograph; + + if (!(publication instanceof Monograph)) { + throw new UnsupportedCcmTypeException( + String.format("The MonographConverter only " + + "supports publication types which are of the" + + "type Monograph or which are extending " + + "Monograh. The " + + "provided publication is of type '%s' which " + + "is not of type Monograph and does not " + + "extends Monograph.", + publication.getClass().getName())); + } + + monograph = (Monograph) publication; + + getRisBuilder().setType(RisTypes.BOOK); + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + convertPublisher(monograph); + convertISBN(monograph); + convertEdition(monograph); + + return getRisBuilder().toRis(); + } + + @Override + public String getCcmType() { + return Monograph.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ProceedingsConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ProceedingsConverter.java new file mode 100644 index 000000000..1138477a8 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ProceedingsConverter.java @@ -0,0 +1,49 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.Proceedings; +import com.arsdigita.cms.contenttypes.Publication; + +/** + * + * @author jensp + */ +public class ProceedingsConverter extends AbstractRisConverter { + + @Override + public String convert(final Publication publication) { + Proceedings proceedings; + + if (!(publication instanceof Proceedings)) { + throw new UnsupportedCcmTypeException( + String.format("The ProceedingsConverter only " + + "supports publication types which are of the" + + "type Proceedings or which are " + + "extending " + + "Proceedings. The " + + "provided publication is of type '%s' which " + + "is not of type " + + "Proceedings and does not " + + "extends Proceedings.", + publication.getClass().getName())); + } + + proceedings = (Proceedings) publication; + + getRisBuilder().setType(RisTypes.CONF); + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + convertVolume(proceedings); + convertSeries(publication); + convertPublisher(proceedings); + + + return getRisBuilder().toRis(); + } + + @Override + public String getCcmType() { + return Proceedings.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/PublicationConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/PublicationConverter.java new file mode 100644 index 000000000..25dff76c8 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/PublicationConverter.java @@ -0,0 +1,23 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.Publication; + +/** + * + * @author Jens Pelzetter + */ +public class PublicationConverter extends AbstractRisConverter { + + public String convert(final Publication publication) { + getRisBuilder().setType(RisTypes.GEN); + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + return getRisBuilder().toRis(); + } + + public String getCcmType() { + return Publication.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/PublicationWithPublisherConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/PublicationWithPublisherConverter.java new file mode 100644 index 000000000..8e15f6ee7 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/PublicationWithPublisherConverter.java @@ -0,0 +1,43 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.PublicationWithPublisher; + +/** + * + * @author Jens Pelzetter + */ +public class PublicationWithPublisherConverter extends AbstractRisConverter { + + public String convert(final Publication publication) { + PublicationWithPublisher _publication; + + if (!(publication instanceof PublicationWithPublisher)) { + throw new UnsupportedCcmTypeException( + String.format("The PublicationWithPublicationConverter only " + + "supports publication types which are " + + "extending PublicationWithPublisher. The " + + "provided publication is of type '%s' which " + + "does not extends " + + "PublicationWithPublisher.", + publication.getClass().getName())); + } + + _publication = (PublicationWithPublisher) publication; + + getRisBuilder().setType(RisTypes.GEN); + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + convertPublisher(_publication); + convertISBN(_publication); + convertEdition(_publication); + + return getRisBuilder().toRis(); + } + + public String getCcmType() { + return PublicationWithPublisher.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ReviewConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ReviewConverter.java new file mode 100644 index 000000000..b8ddc30be --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ReviewConverter.java @@ -0,0 +1,15 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.Review; + +/** + * + * @author Jens Pelzetter + */ +public class ReviewConverter extends ArticleInJournalConverter { + + @Override + public String getCcmType() { + return Review.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisBuilder.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisBuilder.java new file mode 100644 index 000000000..de453acaa --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisBuilder.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.ris; + +import java.util.EnumMap; +import java.util.Map; + +/** + * Build an reference in RIS format. + * + * @author Jens Pelzetter + */ +public class RisBuilder { + + /** + * Type of the reference + */ + private RisTypes type; + /** + * Fields of the reference. + */ + private Map fields = new EnumMap( + RisFields.class); + + public RisBuilder() { + } + + /** + * Sets the type of the reference. + * + * @param type Valid RIS type + */ + public void setType(final RisTypes type) { + this.type = type; + } + + /** + * Adds a field to the reference. + * + * @param field The name of the field. + * @param value The value of the field. + */ + public void addField(final RisFields field, final String value) { + fields.put(field, value); + } + + /** + * Creates the RIS string. + * + * @return The reference in the RIS format. + */ + public String toRis() { + StringBuilder builder; + + builder = new StringBuilder(); + + appendField("TY", type.name(), builder); + for (Map.Entry field : fields.entrySet()) { + appendField(field.getKey().name(), + field.getValue(), + builder); + } + appendField("ER", "", builder); + + return builder.toString(); + } + + /** + * Helper method for adding a field. + * + * @param name The name of the field. + * @param value The value of the field. + * @param builder The {@link StringBuilder} to use. + */ + private void appendField(final String name, + final String value, + final StringBuilder builder) { + builder.append(name); + builder.append(" - "); + builder.append(value); + builder.append("\r\n"); + } + + @Override + public String toString() { + return toRis(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisConverter.java new file mode 100644 index 000000000..12d5a42c7 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisConverter.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.Publication; + +/** + * Interface for the RIS converters + * + * @author Jens Pelzetter + */ +public interface RisConverter { + + /** + * Converts a publication. + * + * @param publication The publication to convert. + * @return The data of the publication converted to RIS. + * @throws UnsupportedCcmTypeException If the provided publication is of + * a type which is not supported by this converter. + */ + String convert(Publication publication); + + /** + * @return The CCM publication type supported by this converter. + */ + String getCcmType(); + +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisConverters.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisConverters.java new file mode 100644 index 000000000..ca78511f1 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisConverters.java @@ -0,0 +1,80 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.PublicationWithPublisher; +import java.util.HashMap; +import java.util.Map; +import java.util.ServiceLoader; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class RisConverters { + + private static final Logger logger = Logger.getLogger(RisConverters.class); + /** + * Associates the available converters with their supported CCM types. + */ + private Map converters = + new HashMap(); + + private RisConverters() { + logger.debug("Loading RIS converters..."); + ServiceLoader converterServices; + + converterServices = ServiceLoader.load(RisConverter.class); + + for (RisConverter converter : converterServices) { + logger.debug(String.format("Found converter for CCM type '%s'...", + converter.getCcmType())); + converters.put(converter.getCcmType(), converter); + } + logger.debug(String.format("Found %d converters.", converters.size())); + } + + private static class Instance { + + private static RisConverters INSTANCE = new RisConverters(); + } + + public static RisConverters getInstance() { + return Instance.INSTANCE; + } + + public String convert(final Publication publication) { + try { + RisConverter converter; + logger.debug(String.format("Trying to find converter for type '%s'.", + publication.getClass().getName())); + //Get the responsible converter + converter = converters.get(publication.getClass().getName()); + if (converter == null) { + logger.debug("No converter found..."); + if (publication instanceof PublicationWithPublisher) { + logger.debug("Publication is a PublicationWithPublisher, using" + + "converter for this type."); + converter = + converters.get(PublicationWithPublisher.class.getName()); + } else { + logger.debug("Publication is a Publication, using" + + "converter for this type."); + converter = + converters.get(Publication.class.getName()); + } + } + //Create an new instance of this converter. + converter = converter.getClass().newInstance(); + //Run the converter. + return converter.convert(publication); + + } catch (InstantiationException ex) { + logger.warn("Failed to instaniate RIS converter.", ex); + return null; + } catch (IllegalAccessException ex) { + logger.warn("Failed to instaniate RIS converter.", ex); + return null; + } + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisExporter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisExporter.java new file mode 100644 index 000000000..a5b0fcd7a --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisExporter.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.scipublications.exporter.PublicationFormat; +import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter; +import javax.activation.MimeType; +import javax.activation.MimeTypeParseException; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class RisExporter implements SciPublicationsExporter { + + private static final Logger logger = Logger.getLogger(RisExporter.class); + + public PublicationFormat getSupportedFormat() { + try { + return new PublicationFormat("RIS", + new MimeType("text", "x-ris"), + "ris"); + } catch(MimeTypeParseException ex) { + logger.warn("Failed to create MimeType for PublicationFormat." + + "Using null mimetype instead. Cause: ", ex); + return new PublicationFormat("RIS", + null, + "ris"); + } + } + + public String exportPublication(final Publication publication) { + return RisConverters.getInstance().convert(publication); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisFields.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisFields.java new file mode 100644 index 000000000..ef44a4f41 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisFields.java @@ -0,0 +1,335 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.ris; + +/** + *

+ * Fields supported by RIS for describing a publication, excluding the + * fields TY (type of reference) and ER (end of + * reference). These fields are automatically set by the converters. + *

+ *

+ * The descriptions of the fields or tags as they are called in the RIS + * specification are copied from the specification + *

+ * + * @author Jens Pelzetter + */ +public enum RisFields { + + /** + * Reference ID. According to the specification not used by reference + * managers. + */ + ID, + /** + * Title Primary. Note that the BT tag maps to this field only for + * Whole Book and Unpublished Work references. This field can contain + * alphanumeric characters; there is no practical length limit to this + * field. + */ + T1, + /** + * @see #T1 + */ + TI, + /** + * @see #T1 + * @see #T2 + */ + CT, + /** + * @see #T1 + * @see #T2 + */ + BT, + /** + *

+ * Author Primary. Each author must be on a separate line, preceded by this + * tag. Each reference can contain + * unlimited author fields, and can contain up to 255 characters for each + * field. The author name must be in the following syntax: + *

+ *
+     * Lastname,Firstname,Suffix
+     * 
+ *

+ * For Firstname, you can use full names, initials, or both. The format for + * the author’s first name is as follows: + *

+ *
+     * Phillips,A.J.
+     * Phillips,Albert John
+     * Phillips,Albert
+     * 
+ *
+ *
Lastname
+ *
Any string of letters, spaces, and hyphens
+ *
Firstname
+ *
Any string of letters, spaces, and hyphens
+ *
Initial
+ *
Any single letter followed by a period
+ *
Full Name
+ *
Any string of letters, spaces, and hyphens
+ *
Suffix
+ *
Jr/Sr/II/III/MD etc. (Phillips,A.J.,Sr.); use of the suffix is + * optional
+ *
+ */ + A1, + /** + * @see #A1 + */ + AU, + /** + *

+ * Date Primary. This date must be in the following format: + *

+ *
+     * YYYY/MM/DD/other info
+     * 
+ *

+ * The year, month and day fields are all numeric. The other info field can + * be any string of letters, spaces and hyphens. Note that each specific + * date information is optional, however the slashes (“/”) are not. For + * example, if you just had the year and + * other info, then the output + * would look like: + *

+ *
+     * “1993///Spring.”
+     * 
+ */ + Y1, + /** + * @see #Y1 + */ + PY, + /** + * Notes. These are free text fields and can contain + * alphanumeric characters; there is no practical length limit to this + * field. + */ + N1, + /** + * @see #N1 + */ + AB, + /** + * Keywords. Each keyword or phrase must be on its own line, preceded by + * this tag. A keyword can consist of multiple words (phrases) and can be + * up to + * 255 characters long. There can unlimited keywords in a reference. + */ + KW, + /** + *

+ * Reprint status. This optional field can contain one of three status + * notes. Each must be in uppercase, and the date after “ON REQUEST” must + * be in + * USA format, in parentheses: (MM/DD/YY). If this field is blank in your + * downloaded text file, the Import function assumes the reprint status is + * “NOT IN FILE.” + *

+ *

The three options are:

+ *
+ *
IN FILE
+ *
This is for references that you have a physical copy of in your + * files.
+ *
NOT IN FILE
+ *
This is for references that you do not have physical copies of in + * your files.
+ *
ON REQUEST (mm/dd/yy)
+ *
This means that you have sent for a reprint of the reference; + * the date is the date on which the reprint was requested (in mm/dd/yy + * format).
+ *
+ */ + RP, + /** + * Start page number; an alphanumeric string, there is no practical length + * limit to this field. + */ + SP, + /** + * Ending page number, as above. + * @see #SP + */ + EP, + /** + * Periodical name: full format. This is an alphanumeric field of up to + * 255 characters. + */ + JF, + /** + * Periodical name: standard abbreviation. This is the 362 Appendix C—RIS + * Format Specifications + */ + JO, + /** + * periodical in which the article was (or is to be, in the case of in- + * press references) published. This is an alphanumeric field of up to 255 + * characters. If possible, periodical names should be abbreviated in the + * Index Medicus style, with periods after the abbreviations. If this is + * not possible (your large bibliography file in your wordprocessor has no + * periods after abbreviations), you can use the “RIS Format (Adds periods)” + * Import filter definition. This definition uses the Periodical Word + * Dictionary. + */ + JA, + /** + * Periodical name: user abbreviation 1. This is an alphanumeric field of + * up to 255 characters. + */ + J1, + /** + * Periodical name: user abbreviation 2. This is an alphanumeric field of + * up to 255 characters. + */ + J2, + /** + * Volume number. This is an optional field, there is no practical length + * limit to this field. + */ + VL, + /** + * Title Secondary. Note that the BT tag maps to this field for all + * reference types except for Whole Book and Unpublished Work + * references. This field can contain alphanumeric characters; there is no + * practical length limit to this field. + */ + T2, + /** + * Author Secondary. Each author must be on a separate line, preceded by + * this tag. Each reference can contain unlimited author + * fields. The author name must be in the correct syntax (refer to A1 and AU + * fields). This author name can be up to 255 characters long. + * @see #A1 + */ + A2, + /** + * @see #A2 + */ + ED, + /** + * Issue. This is an alphanumeric field, there is no practical + * length limit to this field. + */ + IS, + /** + * @see #IS + */ + CP, + /** + * City of publication; this is an alphanumeric field; there is no + * practical length limit to this field. + */ + CY, + /** + * Publisher; this is an alphanumeric field; there is no practical length + * limit to this field. + */ + PB, + /** + * Title Series. This field can contain alphanumeric characters; there is + * no practical length limit to this field. + */ + T3, + /** + * Author Series. Each author must be on a separate line, preceded by + * this tag. Each reference can unlimited author fields. The author name must be + * in the correct syntax (refer to A1 and AU fields). Each author name can be up + * to 255 characters long. + */ + A3, + /** + * Abstract. This is a free text field and can contain alphanumeric + * characters; there is no practical length limit to this field. + */ + N2, + /** + * ISSN/ISBN. This field can contain alphanumeric characters. There is no + * practical length limit to this field. + */ + SN, + /** + * Availability. This field can contain alphanumeric characters. There is + * no practical length limit to this field. + */ + AV, + /** + * Date Secondary. (Refer to Y1 and PY fields). + * @see #Y1 + * @see #PY + */ + Y2, + /** + * Miscellaneous 1. This field can contain alphanumeric characters. There + * is no practical length limit to this field. + */ + M1, + /** + * Miscellaneous 2. This field can contain alphanumeric characters. There + is no practical length limit to this field. + */ + M2, + /** + * Miscellaneous 3. This field can contain alphanumeric characters. There + * is no practical length limit to this field. + */ + M3, + /** + * Address. This is a free text field and contain alphanumeric + * characters; there is no practical length limit to this field. + */ + AD, + /** + * Web/URL. There is no practical length limit to this field. URL + * addresses can be entered individually, one per tag or multiple addresses can + * be entered on one line using a semi-colon as a separator. + */ + UR, + /** + * Link to PDF. There is no practical length limit to this field. URL + * addresses can be entered individually, one per tag or multiple addresses can + * be entered on one line using a semi-colon as a separator. + */ + L1, + /** + * Link to Full-text. There is no practical length limit to this field. + * URL addresses can be entered Reference Manager User’s Guide 365 individually, + * one per tag or multiple addresses can be entered on one line using a semi- + * colon as a separator. + */ + L2, + /** + * Related Records. There is no practical length limit to this field. + */ + L3, + /** + * Images. There is no practical length limit to this field. + */ + L4, + /** + * Edition. Not found in the specification, but used but by some other + * exports. + */ + ET +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisTypes.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisTypes.java new file mode 100644 index 000000000..e0c62750b --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisTypes.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2010 Jens Pelzetter, + * for the Center of Social Politics of the University of Bremen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.ris; + +/** + * Reference types supported by the RIS format. + * + * @author Jens Pelzetter + */ +public enum RisTypes { + + /** + * Abstract + */ + ABST, + /** + * Audiovisual material + */ + ADVS, + /** + * Art Work + */ + ART, + /** + * Bill/Resolution + */ + BILL, + /** + * Book, Whole + */ + BOOK, + /** + * Case + */ + CASE, + /** + * Book chapter + */ + CHAP, + /** + * Computer program + */ + COMP, + /** + * Conference proceedings + */ + CONF, + /** + * Catalog + */ + CTLG, + /** + * Data file + */ + DATA, + /** + * Electronic citation + */ + ELEC, + /** + * Generic + */ + GEN, + /** + * Hearing + */ + HEAR, + /** + * Internet Communication + */ + ICOMM, + /** + * In Press + */ + INPR, + /** + * Journal (full) + */ + JFULL, + /** + * Journal + */ + JOUR, + /** + * Map + */ + MAP, + /** + * Magazine article + */ + MGZN, + /** + * Motion picture + */ + MPCT, + /** + * Music score + */ + MUSIC, + /** + * Newspaper + */ + NEWS, + /** + * Pamphlet + */ + PAMP, + /** + * Patent + */ + PAT, + /** + * Personal communication + */ + PCOMM, + /** + * Report + */ + RPRT, + /** + * Serial (Book, Monograph) + */ + SER, + /** + * Slide + */ + SLIDE, + /** + * Sound recording + */ + SOUND, + /** + * Statute + */ + STAT, + /** + * Thesis/Dissertation + */ + THES, + /** + * Unenacted bill/resoution + */ + UNBILL, + /** + * Unpublished work + */ + UNPB, + /** + * Video recording + */ + VIDEO +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/UnsupportedCcmTypeException.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/UnsupportedCcmTypeException.java new file mode 100644 index 000000000..723600a8d --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/UnsupportedCcmTypeException.java @@ -0,0 +1,34 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.scipublications.exporter.bibtex.converters.*; + +/** + * + * @author jensp + */ +public class UnsupportedCcmTypeException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance of UnsupportedCcmType without detail message. + */ + public UnsupportedCcmTypeException() { + } + + /** + * Constructs an instance of UnsupportedCcmType with the specified detail message. + * @param msg the detail message. + */ + public UnsupportedCcmTypeException(final String msg) { + super(msg); + } + + public UnsupportedCcmTypeException(final Throwable cause) { + super(cause); + } + + public UnsupportedCcmTypeException(final String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/WorkingPaperConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/WorkingPaperConverter.java new file mode 100644 index 000000000..70dae7bc2 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/WorkingPaperConverter.java @@ -0,0 +1,45 @@ +package com.arsdigita.cms.scipublications.exporter.ris; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.WorkingPaper; + +/** + * + * @author Jens Pelzetter + */ +public class WorkingPaperConverter extends AbstractRisConverter { + + @Override + public String convert(final Publication publication) { + WorkingPaper workingPaper; + + if (!(publication instanceof WorkingPaper)) { + throw new UnsupportedCcmTypeException( + String.format("The WorkingPaperConverter only " + + "supports publication types which are of the" + + "type WorkingPaper or which are " + + "extending " + + "WorkingPaper. The " + + "provided publication is of type '%s' which " + + "is not of type " + + "WorkingPaper and does not " + + "extends WorkingPaper.", + publication.getClass().getName())); + } + + workingPaper = (WorkingPaper) publication; + + getRisBuilder().setType(RisTypes.UNPB); + + convertAuthors(publication); + convertTitle(publication); + convertYear(publication); + + return getRisBuilder().toRis(); + } + + @Override + public String getCcmType() { + return WorkingPaper.class.getName(); + } +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/package-info.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/package-info.java new file mode 100644 index 000000000..b1f7aed89 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/package-info.java @@ -0,0 +1,20 @@ +/** + *

+ * The SciPublications package provides several functions for working + * with the Publication content types provided by the ccm-sci-publications + * module. + *

+ *

+ * This includes exporters for reference management software and imports + * from such formats. Examples are BibTeX and RIS. + *

+ *

+ * The entry point for all functions is provided by the + * SciPublications + * application and the SciPublicationsServlet. The application + * makes heavy use of the {@link ServiceLoader} class which was introduced in + * Java 1.6. + *

+ * + */ +package com.arsdigita.cms.scipublications;