CSV Exporter for publications

git-svn-id: https://svn.libreccm.org/ccm/trunk@2543 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2014-02-28 08:46:00 +00:00
parent 3984e532d9
commit 175e24a95b
30 changed files with 1642 additions and 7 deletions

View File

@ -462,12 +462,49 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
exportPublications(format, publicationIds, response); exportPublications(format, publicationIds, response);
} else { } else {
LOGGER.warn("Export action needs either a publication id or a " // LOGGER.warn("Export action needs either a publication id or a "
+ "term id. Neither was found in the query parameters." // + "term id. Neither was found in the query parameters."
+ "Responding with BAD_REQUEST status."); // + "Responding with BAD_REQUEST status.");
response.sendError(HttpServletResponse.SC_BAD_REQUEST, // response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"The export action needs either a publication id or " // "The export action needs either a publication id or "
+ "a term id. Neither was found in the query parameters."); // + "a term id. Neither was found in the query parameters.");
//Otherwise, export all publications
final DataCollection publications = SessionManager.getSession().retrieve(
Publication.BASE_DATA_OBJECT_TYPE);
if (Kernel.getConfig().languageIndependentItems()) {
final FilterFactory filterFactory = publications.getFilterFactory();
final Filter filter = filterFactory.or().
addFilter(filterFactory.equals("language", GlobalizationHelper.
getNegotiatedLocale().getLanguage())).
addFilter(filterFactory.and().
addFilter(
filterFactory.equals("language",
GlobalizationHelper.LANG_INDEPENDENT)).
addFilter(filterFactory.notIn("parent",
"com.arsdigita.navigation.getParentIDsOfMatchedItems").
set("language", GlobalizationHelper.
getNegotiatedLocale().getLanguage())));
publications.addFilter(filter);
} else {
publications.addEqualsFilter("language",
GlobalizationHelper.
getNegotiatedLocale().getLanguage());
}
publications.addOrder("yearOfPublication desc");
publications.addOrder("authorsStr");
publications.addOrder("title");
final List<BigDecimal> publicationIds =
new ArrayList<BigDecimal>();
while(publications.next()) {
publicationIds.add((BigDecimal) publications.get("id"));
}
exportPublications(format, publicationIds, response);
} }
} else { } else {
@ -520,6 +557,10 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
String publicationName = "publication"; String publicationName = "publication";
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
if (exporter.getPreamble() != null) {
result.append(exporter.getPreamble());
}
for (BigDecimal publicationId : publicationIds) { for (BigDecimal publicationId : publicationIds) {
try { try {
//Get the publication //Get the publication

View File

@ -42,5 +42,11 @@ public interface SciPublicationsExporter {
* @return The data of the publication in the provided export format. * @return The data of the publication in the provided export format.
*/ */
String exportPublication(Publication publication); String exportPublication(Publication publication);
/**
* @return If the format requires some sort of preamble this method should return it.
* If the format needs no preamble the method must return null.
*/
String getPreamble();
} }

View File

@ -59,4 +59,9 @@ public class BibTeXExporter implements SciPublicationsExporter {
public String exportPublication(final Publication publication) { public String exportPublication(final Publication publication) {
return BibTeXConverters.getInstance().convert(publication); return BibTeXConverters.getInstance().convert(publication);
} }
@Override
public String getPreamble() {
return null;
}
} }

View File

@ -22,7 +22,6 @@ import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.PublicationWithPublisher; import com.arsdigita.cms.contenttypes.PublicationWithPublisher;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.ServiceLoader;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**

View File

@ -59,4 +59,9 @@ public class RisExporter implements SciPublicationsExporter {
public String exportPublication(final Publication publication) { public String exportPublication(final Publication publication) {
return RisConverters.getInstance().convert(publication); return RisConverters.getInstance().convert(publication);
} }
@Override
public String getPreamble() {
return null;
}
} }

View File

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<ccm:application xmlns:ccm="http://ccm.redhat.com/ccm-project"
name="ccm-sci-publicationscsvexporter"
version="6.6.0"
release="1"
webapp="ROOT">
<ccm:dependencies>
<ccm:requires name="ccm-core" version="6.6.0" relation="ge"/>
<ccm:requires name="ccm-cms" version="6.6.6" relation="ge"/>
<ccm:requires name="ccm-sci-publications" version="6.6.3" relation="ge"/>
</ccm:dependencies>
<ccm:directories>
<ccm:directory name="src"/>
</ccm:directories>
<ccm:contacts>
<ccm:contact uri="http://www.scientificcms.org" type="website"/>
<ccm:contact uri="mailto:info@scientificcms.org" type="support"/>
</ccm:contacts>
<ccm:description>
Importer for Publications using a CSV file. Only used for internal purposes
at the University of Bremen.
</ccm:description>
</ccm:application>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>
<config class="com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConfig" storage="ccm-sci-publications/csvexporter.properties"/>
</registry>

View File

@ -0,0 +1,14 @@
<load>
<requires>
<table name="inits"/>
<table name="acs_objects"/>
<table name="cms_items"/>
<table name="ct_publications"/>
<initializer class="com.arsdigita.cms.Initializer"/>
<initializer class="com.arsdigita.cms.contenttypes.PublicationInitializer"/>
</requires>
<provides>
<initializer class="com.arsdigita.cms.scipublications.exporter.csv.Initializer"/>
</provides>
</load>

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.ArticleInCollectedVolume;
import com.arsdigita.cms.contenttypes.CollectedVolume;
import com.arsdigita.cms.contenttypes.Publication;
import java.util.Map;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class ArticleInCollectedVolumeConverter extends PublicationConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
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 PubliccationWithPublisher.",
publication.getClass().getName()));
}
final ArticleInCollectedVolume article = (ArticleInCollectedVolume) publication;
final Map<CsvExporterConstants, String> values = super.convert(publication);
values.put(PAGES_FROM, convertIntegerValue(article.getPagesFrom()));
values.put(PAGES_TO, convertIntegerValue(article.getPagesTo()));
values.put(CHAPTER, article.getChapter());
if (article.getCollectedVolume() != null) {
final CollectedVolume collectedVolume = article.getCollectedVolume();
values.put(COLLECTED_VOLUME, collectedVolume.getTitle());
values.put(COLLECTED_VOLUME_EDITORS, convertAuthors(collectedVolume.getAuthors()));
}
return values;
}
@Override
public String getCCMType() {
return ArticleInCollectedVolume.class.getName();
}
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.ArticleInJournal;
import com.arsdigita.cms.contenttypes.Publication;
import java.util.Map;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class ArticleInJournalConverter extends PublicationConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
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 PubliccationWithPublisher.",
publication.getClass().getName()));
}
final ArticleInJournal article = (ArticleInJournal) publication;
final Map<CsvExporterConstants, String> values = super.convert(publication);
values.put(VOLUME_OF_JOURNAL, convertIntegerValue(article.getVolume()));
values.put(ISSUE_OF_JOURNAL, article.getIssue());
values.put(PAGES_FROM, convertIntegerValue(article.getPagesFrom()));
values.put(PAGES_TO, convertIntegerValue(article.getPagesTo()));
values.put(PUBLICATION_DATE, convertDateValue(article.getPublicationDate()));
if (article.getJournal() != null) {
values.put(JOURNAL, article.getJournal().getTitle());
values.put(JOURNAL_SYMBOL, article.getJournal().getSymbol());
values.put(ISSN, article.getJournal().getISSN());
}
return values;
}
@Override
public String getCCMType() {
return ArticleInJournal.class.getName();
}
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.CollectedVolume;
import com.arsdigita.cms.contenttypes.Publication;
import java.util.Map;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class CollectedVolumeConverter extends PublicationWithPublisherConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
if (!(publication instanceof CollectedVolume)) {
throw new UnsupportedCcmTypeException(
String.format("The CollectedVolumeConverter only "
+ "supports publication types which are of the"
+ "type CollectedVolume or which are extending "
+ "CollectedVolume. The "
+ "provided publication is of type '%s' which "
+ "is not of type CollectedVolume and does not "
+ "extends PubliccationWithPublisher.",
publication.getClass().getName()));
}
final CollectedVolume collectedVolume = (CollectedVolume) publication;
return super.convert(publication);
}
@Override
public String getCCMType() {
return CollectedVolume.class.getName();
}
}

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.Publication;
import java.util.Map;
/**
* Interface for the converter classes which are transforming publication objects into a CSV line.
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public interface CsvConverter {
/**
* Converts a publication to CSV.
*
* @param publication The publication to convert.
* @return The values for the CSV line. They are returned as a map, where each entry is
* a column in the CSV line. For the key the values from {@link CsvExporterConstants} are used.
*/
Map<CsvExporterConstants, String> convert(Publication publication);
/**
*
*
* @return The CCM publication type supported by this converter.
*/
String getCCMType();
}

View File

@ -0,0 +1,97 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.PublicationWithPublisher;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
/**
* Registry for the available {@link CsvConverter} implementations.
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class CsvConverters {
private static final Logger LOGGER = Logger.getLogger(CsvConverters.class);
private final Map<String, CsvConverter> converters = new HashMap<String, CsvConverter>();
private CsvConverters() {
//Nothing
}
private static class Instance {
private final static CsvConverters INSTANCE = new CsvConverters();
}
public static CsvConverters getInstance() {
return Instance.INSTANCE;
}
public static void register(final CsvConverter converter) {
getInstance().registerConverter(converter);
}
public void registerConverter(final CsvConverter converter) {
converters.put(converter.getCCMType(), converter);
}
public Map<CsvExporterConstants, String> convert(final Publication publication) {
try {
CsvConverter converter;
LOGGER.debug(String.format("Trying to find converter for type '%s'.",
publication.getClass().getName()));
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());
}
}
if (converter == null) {
LOGGER.error(String.format("Converter is null. This should not happen. Publication "
+ "to convert is of type '%s'.", publication.getClass().getName()));
}
converter = converter.getClass().newInstance();
return converter.convert(publication);
} catch (InstantiationException ex) {
LOGGER.warn("Failed to instaniate CSV converter.", ex);
return null;
} catch (IllegalAccessException ex) {
LOGGER.warn("Failed to instaniate CSV converter.", ex);
return null;
}
}
}

View File

@ -0,0 +1,98 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
import java.util.Map;
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class CsvExporter implements SciPublicationsExporter {
private final static Logger LOGGER = Logger.getLogger(CsvExporter.class);
private final static CsvExporterConfig CONFIG = new CsvExporterConfig();
@Override
public PublicationFormat getSupportedFormat() {
try {
return new PublicationFormat("CSV",
new MimeType("text", "csv"),
"csv");
} catch (MimeTypeParseException ex) {
LOGGER.warn("Failed to create MimeType for PublicationFormat."
+ "Using null mimetype instead. Cause: ", ex);
return new PublicationFormat("CSV",
null,
"csv");
}
}
@Override
public String exportPublication(final Publication publication) {
final Map<CsvExporterConstants, String> line = CsvConverters.getInstance().convert(
publication);
final String[] columns = CONFIG.getColumns().split(",");
final String separator = CONFIG.getSeparator();
final StringBuilder builder = new StringBuilder();
String value;
for (String token : columns) {
value = line.get(CsvExporterConstants.valueOf(token));
if ((value == null) || value.isEmpty()) {
builder.append(" ");
} else {
builder.append(value);
}
builder.append(separator);
}
builder.append("\n");
return builder.toString();
}
@Override
public String getPreamble() {
final String[] columns = CONFIG.getColumns().split(",");
final String separator = CONFIG.getSeparator();
final StringBuilder builder = new StringBuilder();
for(String column : columns) {
builder.append(column);
builder.append(separator);
}
builder.append("\n");
return builder.toString();
}
}

View File

@ -0,0 +1,100 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.StringParameter;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class CsvExporterConfig extends AbstractConfig {
private Parameter columns;
private Parameter separator;
public CsvExporterConfig() {
super();
separator = new StringParameter("com.arsdigita.cms.scipublications.exporter.csv.separator",
Parameter.REQUIRED,
"\t");
columns = new StringParameter("com.arsdigita.cms.scipublications.exporter.csv.columns",
Parameter.REQUIRED,
PUBLICATION_ID + "," +
PUBLICATION_TYPE + "," +
AUTHORS + "," +
YEAR + "," +
YEAR_FIRST_PUBLISHED + "," +
TITLE + "," +
PUBLISHER + "," +
PLACE + "," +
EDITION + "," +
ABSTRACT + "," +
MISC + "," +
LANGUAGE_OF_PUBLICATION + "," +
REVIEWED + "," +
VOLUME + "," +
NUMBER + "," +
NUMBER_OF_VOLUMES + "," +
NUMBER_OF_PAGES + "," +
VOLUME_OF_JOURNAL + "," +
ISSUE_OF_JOURNAL + "," +
JOURNAL + "," +
JOURNAL_SYMBOL + "," +
CHAPTER + "," +
PUBLICATION_DATE + "," +
COLLECTED_VOLUME + "," +
COLLECTED_VOLUME_EDITORS + "," +
CONFERENCE + "," +
CONFERENCE_PLACE + "," +
CONFERENCE_DATE_FROM + "," +
CONFERENCE_DATE_TO + "," +
IN_SERIES + "," +
VOLUME_OF_SERIES + "," +
EDITOR_OF_SERIES + "," +
ORGANISATION + "," +
URL + "," +
ISBN + "," +
ISSN + "," +
URN + "," +
DOI + "," +
LAST_ACCESS + ",");
register(columns);
register(separator);
loadInfo();
}
public String getColumns() {
return (String) get(columns);
}
public String getSeparator() {
return (String) get(separator);
}
}

View File

@ -0,0 +1,9 @@
com.arsdigita.cms.scipublications.exporter.csv.separator.title = CSV Exporter Separator
com.arsdigita.cms.scipublications.exporter.csv.separator.purpose = Separator used in CSV file between columns
com.arsdigita.cms.scipublications.exporter.csv.separator.example = |
com.arsdigita.cms.scipublications.exporter.csv.separator.format = [String]
com.arsdigita.cms.scipublications.exporter.csv.columns.title = CSV Columns
com.arsdigita.cms.scipublications.exporter.csv.columns.purpose = Columns to include into the CSV file. Also defines the order of the columns.
com.arsdigita.cms.scipublications.exporter.csv.columns.example =
com.arsdigita.cms.scipublications.exporter.csv.columns.format = [String]

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
/**
* Constants used in for CSV Exporter, most of them are the field names used in the maps from which
* which the CSV lines are created.
*
* The constants are ordered alphabetically.
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public enum CsvExporterConstants {
ABSTRACT,
AUTHORS,
CHAPTER,
COLLECTED_VOLUME,
COLLECTED_VOLUME_EDITORS,
CONFERENCE,
CONFERENCE_DATE_FROM,
CONFERENCE_DATE_TO,
CONFERENCE_PLACE,
DOI,
EDITION,
EDITOR_OF_SERIES,
IN_SERIES,
ISBN,
ISSN,
ISSUE_OF_JOURNAL,
JOURNAL,
JOURNAL_SYMBOL,
LANGUAGE_OF_PUBLICATION,
LAST_ACCESS,
MISC,
NUMBER,
NUMBER_OF_VOLUMES,
NUMBER_OF_PAGES,
ORGANISATION,
PAGES_FROM,
PAGES_TO,
PLACE,
PUBLICATION_DATE,
PUBLICATION_ID,
PUBLICATION_TYPE,
PUBLISHER,
REVIEWED,
YEAR,
YEAR_FIRST_PUBLISHED,
TITLE,
URL,
URN,
VOLUME,
VOLUME_OF_JOURNAL,
VOLUME_OF_SERIES
}

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.Expertise;
import java.util.Map;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class ExpertiseConverter extends PublicationConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
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 PubliccationWithPublisher.",
publication.getClass().getName()));
}
final Expertise expertise = (Expertise) publication;
final Map<CsvExporterConstants, String> values = super.convert(publication);
values.put(PLACE, expertise.getPlace());
values.put(NUMBER_OF_PAGES, convertIntegerValue(expertise.getNumberOfPages()));
if (expertise.getOrganization() != null) {
values.put(ORGANISATION, expertise.getOrganization().getTitle());
}
return values;
}
@Override
public String getCCMType() {
return Expertise.class.getName();
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.GreyLiterature;
import com.arsdigita.cms.contenttypes.Publication;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
import java.util.Map;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class GreyLiteratureConverter extends UnPublishedConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
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 PubliccationWithPublisher.",
publication.getClass().getName()));
}
final GreyLiterature greyLiterature = (GreyLiterature) publication;
final Map<CsvExporterConstants, String> values = super.convert(publication);
values.put(PAGES_FROM, convertIntegerValue(greyLiterature.getPagesFrom()));
values.put(PAGES_TO, convertIntegerValue(greyLiterature.getPagesTo()));
return values;
}
@Override
public String getCCMType() {
return GreyLiterature.class.getName();
}
}

View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.InProceedings;
import com.arsdigita.cms.contenttypes.Publication;
import java.util.Map;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class InProceedingsConverter extends PublicationConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
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 PubliccationWithPublisher.",
publication.getClass().getName()));
}
final InProceedings inProceedings = (InProceedings) publication;
final Map<CsvExporterConstants, String> values = super.convert(publication);
values.put(PAGES_FROM, convertIntegerValue(inProceedings.getPagesFrom()));
values.put(PAGES_TO, convertIntegerValue(inProceedings.getPagesTo()));
if (inProceedings.getProceedings() != null) {
values.put(COLLECTED_VOLUME, inProceedings.getProceedings().getTitle());
values.put(COLLECTED_VOLUME_EDITORS, convertAuthors(inProceedings.getProceedings().
getAuthors()));
values.put(CONFERENCE, inProceedings.getProceedings().getNameOfConference());
values.put(CONFERENCE_PLACE, inProceedings.getProceedings().getPlaceOfConference());
values.put(CONFERENCE_DATE_FROM, convertDateValue(inProceedings.getProceedings().
getDateFromOfConference()));
values.put(CONFERENCE_DATE_TO, convertDateValue(inProceedings.getProceedings().
getDateToOfConference()));
}
return values;
}
@Override
public String getCCMType() {
return InProceedings.class.getName();
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporters;
import com.arsdigita.db.DbHelper;
import com.arsdigita.persistence.pdl.ManifestSource;
import com.arsdigita.persistence.pdl.NameFilter;
import com.arsdigita.runtime.CompoundInitializer;
import com.arsdigita.runtime.DomainInitEvent;
import com.arsdigita.runtime.PDLInitializer;
import com.arsdigita.runtime.RuntimeConfig;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class Initializer extends CompoundInitializer {
public Initializer() {
super();
final String url = RuntimeConfig.getConfig().getJDBCURL();
final int database = DbHelper.getDatabaseFromURL(url);
add(new PDLInitializer(new ManifestSource("empty.pdl.mf",
new NameFilter((DbHelper.getDatabaseSuffix(
database)), "pdl"))));
}
@Override
public void init(final DomainInitEvent event) {
super.init(event);
SciPublicationsExporters.register(new CsvExporter());
CsvConverters.register(new ArticleInCollectedVolumeConverter());
CsvConverters.register(new ArticleInJournalConverter());
CsvConverters.register(new CollectedVolumeConverter());
CsvConverters.register(new ExpertiseConverter());
CsvConverters.register(new GreyLiteratureConverter());
CsvConverters.register(new InProceedingsConverter());
CsvConverters.register(new InternetArticleConverter());
CsvConverters.register(new MonographConverter());
CsvConverters.register(new ProceedingsConverter());
CsvConverters.register(new PublicationConverter());
CsvConverters.register(new PublicationWithPublisherConverter());
CsvConverters.register(new ReviewConverter());
CsvConverters.register(new UnPublishedConverter());
CsvConverters.register(new WorkingPaperConverter());
}
}

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.InternetArticle;
import com.arsdigita.cms.contenttypes.Publication;
import java.util.Map;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class InternetArticleConverter extends PublicationConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
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 PubliccationWithPublisher.",
publication.getClass().getName()));
}
final InternetArticle article = (InternetArticle) publication;
final Map<CsvExporterConstants, String> values = super.convert(publication);
values.put(PLACE, article.getPlace());
values.put(NUMBER, article.getNumber());
values.put(NUMBER_OF_PAGES, convertIntegerValue(article.getNumberOfPages()));
values.put(EDITION, article.getEdition());
values.put(ISSN, article.getISSN());
values.put(LAST_ACCESS, convertDateValue(article.getLastAccessed()));
values.put(PUBLICATION_DATE, convertDateValue(article.getPublicationDate()));
values.put(URL, article.getUrl());
values.put(URN, article.getUrn());
values.put(DOI, article.getDoi());
return values;
}
@Override
public String getCCMType() {
return InternetArticle.class.getName();
}
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.Monograph;
import com.arsdigita.cms.contenttypes.Publication;
import java.util.Map;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class MonographConverter extends PublicationWithPublisherConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
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 "
+ "Monograph. The "
+ "provided publication is of type '%s' which "
+ "is not of type Monograph and does not "
+ "extends PubliccationWithPublisher.",
publication.getClass().getName()));
}
final Map<CsvExporterConstants, String> values = super.convert(publication);
return values;
}
@Override
public String getCCMType() {
return Monograph.class.getName();
}
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.Proceedings;
import com.arsdigita.cms.contenttypes.Publication;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
import java.util.Map;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class ProceedingsConverter extends PublicationWithPublisherConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
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 PubliccationWithPublisher.",
publication.getClass().getName()));
}
final Map<CsvExporterConstants, String> values = super.convert(publication);
final Proceedings proceedings = (Proceedings) publication;
values.put(CONFERENCE, proceedings.getNameOfConference());
values.put(CONFERENCE_PLACE, proceedings.getPlaceOfConference());
values.put(CONFERENCE_DATE_FROM, convertDateValue(proceedings.getDateFromOfConference()));
values.put(CONFERENCE_DATE_TO, convertDateValue(proceedings.getDateToOfConference()));
return values;
}
@Override
public String getCCMType() {
return Proceedings.class.getName();
}
}

View File

@ -0,0 +1,109 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.AuthorshipCollection;
import com.arsdigita.cms.contenttypes.Publication;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
import java.util.Calendar;
import java.util.Date;
import java.util.EnumMap;
import java.util.Map;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class PublicationConverter implements CsvConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
if (publication == null) {
throw new IllegalArgumentException("Can't convert null values");
}
final Map<CsvExporterConstants, String> values = new EnumMap<CsvExporterConstants, String>(
CsvExporterConstants.class);
values.put(PUBLICATION_ID, publication.getID().toString());
values.put(PUBLICATION_TYPE, publication.getClass().getName());
values.put(TITLE, publication.getTitle());
values.put(YEAR, convertIntegerValue(publication.getYearOfPublication()));
values.put(YEAR_FIRST_PUBLISHED, convertIntegerValue(publication.getYearFirstPublished()));
values.put(LANGUAGE_OF_PUBLICATION, publication.getLanguageOfPublication());
values.put(REVIEWED, convertBooleanValue(publication.getReviewed()));
values.put(AUTHORS, convertAuthors(publication.getAuthors()));
return values;
}
protected String convertAuthors(final AuthorshipCollection authors) {
final StringBuilder authorsCol = new StringBuilder();
while (authors.next()) {
authorsCol.append(authors.getSurname());
if (authors.getGivenName() != null) {
authorsCol.append(", ");
authorsCol.append(authors.getGivenName());
}
authorsCol.append(';');
}
return authorsCol.toString();
}
protected String convertIntegerValue(final Integer value) {
if (value == null) {
return "";
} else {
return value.toString();
}
}
protected String convertBooleanValue(final Boolean value) {
if (value == null) {
return "";
} else {
return value.toString();
}
}
protected String convertDateValue(final Date value) {
if (value == null) {
return "";
} else {
final Calendar calender = Calendar.getInstance();
calender.setTime(value);
return String.format("%d-%d-%d", calender.get(Calendar.YEAR),
calender.get(Calendar.MONTH),
calender.get(Calendar.DAY_OF_MONTH));
}
}
@Override
public String getCCMType() {
return Publication.class.getName();
}
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.PublicationWithPublisher;
import java.util.Map;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class PublicationWithPublisherConverter extends PublicationConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
if (!(publication instanceof PublicationWithPublisher)) {
throw new UnsupportedCcmTypeException(
String.format("The PublicationWithPublisherConverter only "
+ "supports publication types which are of the"
+ "type PublicationWithPublisher or which are extending "
+ "PublicationWithPublisher. The "
+ "provided publication is of type '%s' which "
+ "is not of type PublicationWithPublisher and does not "
+ "extends PubliccationWithPublisher.",
publication.getClass().getName()));
}
final PublicationWithPublisher publicationWithPublisher
= (PublicationWithPublisher) publication;
final Map<CsvExporterConstants, String> values = super.convert(publication);
values.put(ISBN, publicationWithPublisher.getISBN());
values.put(VOLUME, convertIntegerValue(publicationWithPublisher.getVolume()));
values.put(NUMBER_OF_VOLUMES, convertIntegerValue(publicationWithPublisher.
getNumberOfVolumes()));
values.put(NUMBER_OF_PAGES, convertIntegerValue(
publicationWithPublisher.getNumberOfPages()));
values.put(EDITION, publicationWithPublisher.getEdition());
if (publicationWithPublisher.getPublisher() != null) {
values.put(PLACE, publicationWithPublisher.getPublisher().getPlace());
values.put(PUBLISHER, publicationWithPublisher.getPublisher().getPublisherName());
}
return values;
}
@Override
public String getCCMType() {
return PublicationWithPublisher.class.getName();
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.Review;
import java.util.Map;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class ReviewConverter extends ArticleInJournalConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
if (!(publication instanceof Review)) {
throw new UnsupportedCcmTypeException(
String.format("The ReviewConverter only "
+ "supports publication types which are of the"
+ "type Review or which are extending "
+ "Review. The "
+ "provided publication is of type '%s' which "
+ "is not of type Review and does not "
+ "extends PubliccationWithPublisher.",
publication.getClass().getName()));
}
return super.convert(publication);
}
@Override
public String getCCMType() {
return Review.class.getName();
}
}

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.UnPublished;
import java.util.Map;
import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class UnPublishedConverter extends PublicationConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
if (!(publication instanceof UnPublished)) {
throw new UnsupportedCcmTypeException(
String.format("The UnPublishedConverter only "
+ "supports publication types which are of the"
+ "type UnPublished or which are extending "
+ "UnPublished. The "
+ "provided publication is of type '%s' which "
+ "is not of type UnPublished and does not "
+ "extends PubliccationWithPublisher.",
publication.getClass().getName()));
}
final UnPublished unPublished = (UnPublished) publication;
final Map<CsvExporterConstants, String> values = super.convert(publication);
values.put(PLACE, unPublished.getPlace());
values.put(NUMBER, unPublished.getNumber());
values.put(NUMBER_OF_PAGES, convertIntegerValue(unPublished.getNumberOfPages()));
if (unPublished.getOrganization() != null) {
values.put(ORGANISATION, unPublished.getOrganization().getTitle());
}
return values;
}
@Override
public String getCCMType() {
return UnPublished.class.getName();
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class UnsupportedCcmTypeException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* Creates a new instance of <code>UnsupportedCcmType</code> without detail message.
*/
public UnsupportedCcmTypeException() {
}
/**
* Constructs an instance of <code>UnsupportedCcmType</code> 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);
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2014 Jens Pelzetter
*
* 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.csv;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.WorkingPaper;
import java.util.Map;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class WorkingPaperConverter extends UnPublishedConverter {
@Override
public Map<CsvExporterConstants, String> convert(final Publication publication) {
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 PubliccationWithPublisher.",
publication.getClass().getName()));
}
return super.convert(publication);
}
@Override
public String getCCMType() {
return WorkingPaper.class.getName();
}
}