Erste Vorbereitungen für Exporter für Publikationen
git-svn-id: https://svn.libreccm.org/ccm/trunk@1864 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
1f5f36b7a0
commit
8e5ca115bd
|
|
@ -12,7 +12,7 @@ import com.arsdigita.cms.contenttypes.PublicationGenericOrganizationalsUnitColle
|
||||||
import com.arsdigita.cms.contenttypes.Series;
|
import com.arsdigita.cms.contenttypes.Series;
|
||||||
import com.arsdigita.cms.contenttypes.SeriesCollection;
|
import com.arsdigita.cms.contenttypes.SeriesCollection;
|
||||||
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
|
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
|
||||||
import com.arsdigita.cms.scipublications.exporter.PublicationFormat;
|
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
||||||
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporters;
|
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporters;
|
||||||
import com.arsdigita.globalization.GlobalizationHelper;
|
import com.arsdigita.globalization.GlobalizationHelper;
|
||||||
import com.arsdigita.xml.Element;
|
import com.arsdigita.xml.Element;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010 Jens Pelzetter,
|
* Copyright (c) 2010 Jens Pelzetter, ScientificCMS.org Team
|
||||||
* for the Center of Social Politics of the University of Bremen
|
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public License
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
|
@ -20,11 +19,13 @@
|
||||||
package com.arsdigita.cms.scipublications.exporter;
|
package com.arsdigita.cms.scipublications.exporter;
|
||||||
|
|
||||||
import com.arsdigita.cms.contenttypes.Publication;
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
|
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface describes the methods provided by all publication exporters.
|
* This interface describes the methods provided by all publication exporters.
|
||||||
*
|
*
|
||||||
* @author Jens Pelzetter
|
* @author Jens Pelzetter
|
||||||
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public interface SciPublicationsExporter {
|
public interface SciPublicationsExporter {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010 Jens Pelzetter,
|
* Copyright (c) 2010 Jens Pelzetter, ScientificCMS.org team
|
||||||
* for the Center of Social Politics of the University of Bremen
|
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public License
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
|
@ -19,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.scipublications.exporter;
|
package com.arsdigita.cms.scipublications.exporter;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -31,6 +31,7 @@ import org.apache.log4j.Logger;
|
||||||
* {@link SciPublicationsExporter} interface. It is implemented as a Singleton.
|
* {@link SciPublicationsExporter} interface. It is implemented as a Singleton.
|
||||||
*
|
*
|
||||||
* @author Jens Pelzetter
|
* @author Jens Pelzetter
|
||||||
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public final class SciPublicationsExporters {
|
public final class SciPublicationsExporters {
|
||||||
|
|
||||||
|
|
@ -67,10 +68,8 @@ public final class SciPublicationsExporters {
|
||||||
|
|
||||||
for (SciPublicationsExporter exporter : exporterServices) {
|
for (SciPublicationsExporter exporter : exporterServices) {
|
||||||
logger.debug(String.format("Found exporter for format '%s'...",
|
logger.debug(String.format("Found exporter for format '%s'...",
|
||||||
exporter.getSupportedFormat().getName().
|
exporter.getSupportedFormat().getName().toLowerCase()));
|
||||||
toLowerCase()));
|
exporters.put(exporter.getSupportedFormat().getName().toLowerCase(), exporter);
|
||||||
exporters.put(exporter.getSupportedFormat().getName().toLowerCase(),
|
|
||||||
exporter);
|
|
||||||
}
|
}
|
||||||
logger.debug(String.format("Found %d exporters.", exporters.size()));
|
logger.debug(String.format("Found %d exporters.", exporters.size()));
|
||||||
}
|
}
|
||||||
|
|
@ -102,11 +101,11 @@ public final class SciPublicationsExporters {
|
||||||
|
|
||||||
supportedFormats = new ArrayList<PublicationFormat>();
|
supportedFormats = new ArrayList<PublicationFormat>();
|
||||||
|
|
||||||
for (Map.Entry<String, SciPublicationsExporter> entry : exporters.
|
for (Map.Entry<String, SciPublicationsExporter> entry : exporters.entrySet()) {
|
||||||
entrySet()) {
|
|
||||||
supportedFormats.add(entry.getValue().getSupportedFormat());
|
supportedFormats.add(entry.getValue().getSupportedFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
return supportedFormats;
|
return supportedFormats;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
package com.arsdigita.cms.scipublications.exporter.bibtex;
|
package com.arsdigita.cms.scipublications.exporter.bibtex;
|
||||||
|
|
||||||
import com.arsdigita.cms.contenttypes.Publication;
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
import com.arsdigita.cms.scipublications.exporter.PublicationFormat;
|
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
||||||
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
|
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
|
||||||
import com.arsdigita.cms.scipublications.exporter.bibtex.converters.BibTeXConverter;
|
import com.arsdigita.cms.scipublications.exporter.bibtex.converters.BibTeXConverter;
|
||||||
import com.arsdigita.cms.scipublications.exporter.bibtex.converters.BibTeXConverters;
|
import com.arsdigita.cms.scipublications.exporter.bibtex.converters.BibTeXConverters;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
package com.arsdigita.cms.scipublications.exporter.ris;
|
package com.arsdigita.cms.scipublications.exporter.ris;
|
||||||
|
|
||||||
import com.arsdigita.cms.contenttypes.Publication;
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
import com.arsdigita.cms.scipublications.exporter.PublicationFormat;
|
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
||||||
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
|
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
|
||||||
import javax.activation.MimeType;
|
import javax.activation.MimeType;
|
||||||
import javax.activation.MimeTypeParseException;
|
import javax.activation.MimeTypeParseException;
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.scipublications.exporter;
|
package com.arsdigita.cms.scipublications.imexporter;
|
||||||
|
|
||||||
import javax.activation.MimeType;
|
import javax.activation.MimeType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the format provided by an implementation of
|
* Describes the format provided by an implementation of
|
||||||
* {@link SciPublicationsExporter}.
|
* {@link SciPublicationsExporter} or {@link SciPublicationsImporter}.
|
||||||
*
|
*
|
||||||
* @author Jens Pelzetter
|
* @author Jens Pelzetter
|
||||||
*/
|
*/
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012 Jens Pelzetter, ScientificCMS.org team
|
||||||
|
*
|
||||||
|
* 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.importer;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for publication importers
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public interface SciPublicationsImporter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Description of the format supported by the importer implementation.
|
||||||
|
*/
|
||||||
|
PublicationFormat getSupportedFormat();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the provided string and creates publications from the string.
|
||||||
|
*
|
||||||
|
* @param publications The string conaining the publications in the format supported by this importer
|
||||||
|
* @param pretend If set to {@link true} no publications will be created. This can be used for debugging purposes
|
||||||
|
* or to check an file containing publications
|
||||||
|
* @return A report describing what the importer has done
|
||||||
|
*/
|
||||||
|
String importPublications(String publications, boolean pretend);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.arsdigita.cms.scipublications.importer;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
|
||||||
|
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides access to the available implementations of the {@link SciPublicationsImporter} interface.
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class SciPublicationsImporters {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(SciPublicationsImporters.class);
|
||||||
|
/**
|
||||||
|
* Asscociation of the format the responsible importer.
|
||||||
|
*/
|
||||||
|
private Map<String, SciPublicationsImporter> importers = new HashMap<String, SciPublicationsImporter>();
|
||||||
|
|
||||||
|
private static class Instance {
|
||||||
|
|
||||||
|
private static final SciPublicationsImporters INSTANCE = new SciPublicationsImporters();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the instance. Uses the {@link ServiceLoader} to find all avaiable implementations of
|
||||||
|
* {@link SciPublicationsImporters} and puts them into the {@link #importers} map.
|
||||||
|
*/
|
||||||
|
private SciPublicationsImporters() {
|
||||||
|
logger.debug("Creating SciPublicationsImporter instance...");
|
||||||
|
final ServiceLoader<SciPublicationsImporter> importerServices;
|
||||||
|
|
||||||
|
logger.debug("Loading all available implementations of the SciPublicationsImporter interface...");
|
||||||
|
importerServices = ServiceLoader.load(SciPublicationsImporter.class);
|
||||||
|
|
||||||
|
for (SciPublicationsImporter importer : importerServices) {
|
||||||
|
logger.debug(String.format("Found importer for format '%s'...",
|
||||||
|
importer.getSupportedFormat().getName().toLowerCase()));
|
||||||
|
importers.put(importer.getSupportedFormat().getName().toLowerCase(), importer);
|
||||||
|
}
|
||||||
|
logger.debug(String.format("Found %d importers.", importers.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SciPublicationsImporters getInstance() {
|
||||||
|
return Instance.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the importer for the specified format.
|
||||||
|
*
|
||||||
|
* @param format The format which should be supported by the importer.
|
||||||
|
* @return The importer for the specified format, or <code>null</code> if there is no export which supports the
|
||||||
|
* specified format.
|
||||||
|
*/
|
||||||
|
public SciPublicationsImporter getImporterForFormat(final String format) {
|
||||||
|
return importers.get(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return A list of all supported export formats.
|
||||||
|
*/
|
||||||
|
public List<PublicationFormat> getSupportedFormats() {
|
||||||
|
List<PublicationFormat> supportedFormats;
|
||||||
|
|
||||||
|
supportedFormats = new ArrayList<PublicationFormat>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, SciPublicationsImporter> entry : importers.entrySet()) {
|
||||||
|
supportedFormats.add(entry.getValue().getSupportedFormat());
|
||||||
|
}
|
||||||
|
|
||||||
|
return supportedFormats;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue