Trunk sollte jetzt wieder kompilieren.
git-svn-id: https://svn.libreccm.org/ccm/trunk@732 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
df79984150
commit
4156e06a6f
|
|
@ -46,25 +46,10 @@ public class BibTeXExporter implements SciPublicationsExporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String exportPublication(final Publication publication) {
|
public String exportPublication(final Publication publication) {
|
||||||
BibTeXBuilder builder;
|
|
||||||
|
|
||||||
|
|
||||||
builder = BibTeXBuilders.getInstance().
|
|
||||||
getBibTeXBuilderForCcmPublicationtType(publication.getClass().
|
|
||||||
getName());
|
|
||||||
|
|
||||||
if ((builder == null) && publication instanceof PublicationWithPublisher) {
|
throw new UnsupportedOperationException("Not implemented yet.");
|
||||||
builder = BibTeXBuilders.getInstance().
|
|
||||||
getBibTeXBuilderForCcmPublicationtType(
|
|
||||||
PublicationWithPublisher.class.getName());
|
|
||||||
} else {
|
|
||||||
builder = BibTeXBuilders.getInstance().
|
|
||||||
getBibTeXBuilderForCcmPublicationtType(Publication.class.
|
|
||||||
getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return builder.toBibTeX();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public class BibTeXBuilders {
|
||||||
return Instance.INSTANCE;
|
return Instance.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BibTeXBuilder getBibTeXBuilderForCcmPublicationtType(final String type) {
|
public BibTeXBuilder getBibTeXBuilderForType(final String type) {
|
||||||
return builders.get(type);
|
return builders.get(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
package com.arsdigita.cms.scipublications.exporter.bibtex.converters;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.contenttypes.AuthorshipCollection;
|
||||||
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
|
import com.arsdigita.cms.contenttypes.PublicationWithPublisher;
|
||||||
|
import com.arsdigita.cms.scipublications.exporter.bibtex.builders.BibTeXBuilder;
|
||||||
|
import com.arsdigita.cms.scipublications.exporter.bibtex.builders.BibTeXBuilders;
|
||||||
|
import com.arsdigita.cms.scipublications.exporter.bibtex.builders.BibTeXField;
|
||||||
|
import com.arsdigita.cms.scipublications.exporter.bibtex.builders.UnsupportedFieldException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jensp
|
||||||
|
*/
|
||||||
|
public abstract class AbstractBibTeXConverter implements BibTeXConverter {
|
||||||
|
|
||||||
|
private BibTeXBuilder bibTeXBuilder;
|
||||||
|
|
||||||
|
protected void convertAuthors(final Publication publication) {
|
||||||
|
AuthorshipCollection authors;
|
||||||
|
|
||||||
|
authors = publication.getAuthors();
|
||||||
|
if (authors != null) {
|
||||||
|
while (authors.next()) {
|
||||||
|
if (authors.isEditor()) {
|
||||||
|
getBibTeXBuilder().addEditor(authors.getAuthor());
|
||||||
|
} else {
|
||||||
|
getBibTeXBuilder().addAuthor(authors.getAuthor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void convertTitle(final Publication publication)
|
||||||
|
throws UnsupportedFieldException {
|
||||||
|
getBibTeXBuilder().setField(BibTeXField.TITLE, publication.getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void convertYear(final Publication publication)
|
||||||
|
throws UnsupportedFieldException {
|
||||||
|
if (publication.getYearOfPublication() != null) {
|
||||||
|
getBibTeXBuilder().setField(BibTeXField.YEAR,
|
||||||
|
publication.getYearOfPublication().
|
||||||
|
toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void convertPublisher(final PublicationWithPublisher publication)
|
||||||
|
throws UnsupportedFieldException {
|
||||||
|
if (publication.getPublisher() != null) {
|
||||||
|
getBibTeXBuilder().setField(BibTeXField.PUBLISHER,
|
||||||
|
publication.getPublisher().getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void convertISBN(final PublicationWithPublisher publication)
|
||||||
|
throws UnsupportedFieldException {
|
||||||
|
if (publication.getISBN() != null) {
|
||||||
|
getBibTeXBuilder().setField(BibTeXField.ISBN,
|
||||||
|
publication.getISBN());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void convertVolume(final PublicationWithPublisher publication)
|
||||||
|
throws UnsupportedFieldException {
|
||||||
|
if (publication.getVolume() != null) {
|
||||||
|
getBibTeXBuilder().setField(BibTeXField.VOLUME,
|
||||||
|
publication.getVolume().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void convertEdition(final PublicationWithPublisher publication)
|
||||||
|
throws UnsupportedFieldException {
|
||||||
|
if (publication.getEdition() != null) {
|
||||||
|
getBibTeXBuilder().setField(BibTeXField.EDITION,
|
||||||
|
publication.getEdition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BibTeXBuilder getBibTeXBuilder() {
|
||||||
|
if (bibTeXBuilder == null) {
|
||||||
|
bibTeXBuilder = BibTeXBuilders.getInstance().getBibTeXBuilderForType(
|
||||||
|
getBibTeXType());
|
||||||
|
}
|
||||||
|
|
||||||
|
return bibTeXBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getBibTeXType();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
package com.arsdigita.cms.scipublications.exporter.bibtex.converters;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
|
import com.arsdigita.cms.contenttypes.ArticleInCollectedVolume;
|
||||||
|
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;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jensp
|
||||||
|
*/
|
||||||
|
public class ArticleInCollectedVolumeConverter extends AbstractBibTeXConverter {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(
|
||||||
|
ArticleInCollectedVolumeConverter.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getBibTeXType() {
|
||||||
|
return "incollection";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String convert(final Publication publication) {
|
||||||
|
ArticleInCollectedVolume article;
|
||||||
|
BibTeXBuilder builder;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
convertAuthors(publication);
|
||||||
|
builder = getBibTeXBuilder();
|
||||||
|
try {
|
||||||
|
convertTitle(publication);
|
||||||
|
convertYear(publication);
|
||||||
|
|
||||||
|
builder.setField(BibTeXField.BOOKTITLE,
|
||||||
|
article.getCollectedVolume().getTitle());
|
||||||
|
if (article.getCollectedVolume().getPublisher() == null) {
|
||||||
|
builder.setField(BibTeXField.PUBLISHER, "");
|
||||||
|
} else {
|
||||||
|
builder.setField(BibTeXField.PUBLISHER,
|
||||||
|
article.getCollectedVolume().getPublisher().
|
||||||
|
getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (article.getCollectedVolume().getVolume() != null) {
|
||||||
|
builder.setField(BibTeXField.VOLUME,
|
||||||
|
article.getCollectedVolume().getVolume().
|
||||||
|
toString());
|
||||||
|
}
|
||||||
|
SeriesCollection seriesColl =
|
||||||
|
article.getCollectedVolume().getSeries();
|
||||||
|
if ((seriesColl != null) && (seriesColl.size() > 0)) {
|
||||||
|
|
||||||
|
seriesColl.next();
|
||||||
|
|
||||||
|
builder.setField(BibTeXField.SERIES,
|
||||||
|
seriesColl.getSeries().getTitle());
|
||||||
|
|
||||||
|
seriesColl.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (article.getChapter() != null) {
|
||||||
|
builder.setField(BibTeXField.CHAPTER, article.getChapter());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (article.getPagesFrom() != null) {
|
||||||
|
builder.setField(BibTeXField.PAGES,
|
||||||
|
String.format("%s - %s",
|
||||||
|
article.getPagesFrom(),
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.toBibTeX();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCcmType() {
|
||||||
|
return ArticleInCollectedVolume.class.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.arsdigita.cms.scipublications.exporter.bibtex.converters;
|
package com.arsdigita.cms.scipublications.exporter.bibtex.converters;
|
||||||
|
|
||||||
import com.arsdigita.cms.contenttypes.Publication;
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
|
import com.arsdigita.cms.contenttypes.PublicationWithPublisher;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -11,13 +12,13 @@ import java.util.Map;
|
||||||
public class BibTeXConverters {
|
public class BibTeXConverters {
|
||||||
|
|
||||||
private Map<String, BibTeXConverter> converters =
|
private Map<String, BibTeXConverter> converters =
|
||||||
new HashMap<String, BibTeXConverter>();
|
new HashMap<String, BibTeXConverter>();
|
||||||
|
|
||||||
private BibTeXConverters() {
|
private BibTeXConverters() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Instance {
|
private static class Instance {
|
||||||
|
|
||||||
private static BibTeXConverters INSTANCE = new BibTeXConverters();
|
private static BibTeXConverters INSTANCE = new BibTeXConverters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +31,16 @@ public class BibTeXConverters {
|
||||||
|
|
||||||
converter = converters.get(publication.getClass().getName());
|
converter = converters.get(publication.getClass().getName());
|
||||||
|
|
||||||
|
if (converter == null) {
|
||||||
|
if (publication instanceof PublicationWithPublisher) {
|
||||||
|
converter = converters.get(PublicationWithPublisher.class.
|
||||||
|
getName());
|
||||||
|
} else {
|
||||||
|
converter = converters.get(Publication.class.getName());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return converter.convert(publication);
|
return converter.convert(publication);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.arsdigita.cms.scipublications.exporter.bibtex.converters;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
|
import com.arsdigita.cms.contenttypes.Monograph;
|
||||||
|
import com.arsdigita.cms.scipublications.exporter.bibtex.builders.UnsupportedFieldException;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jensp
|
||||||
|
*/
|
||||||
|
public class MonographConverter extends AbstractBibTeXConverter {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(
|
||||||
|
MonographConverter.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getBibTeXType() {
|
||||||
|
return "book";
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
convertAuthors(publication);
|
||||||
|
try {
|
||||||
|
convertTitle(publication);
|
||||||
|
convertYear(publication);
|
||||||
|
|
||||||
|
convertPublisher(monograph);
|
||||||
|
convertISBN(monograph);
|
||||||
|
convertEdition(monograph);
|
||||||
|
} catch (UnsupportedFieldException ex) {
|
||||||
|
logger.warn("Tried to set unsupported BibTeX field while "
|
||||||
|
+ "converting a publication");
|
||||||
|
}
|
||||||
|
|
||||||
|
return getBibTeXBuilder().toBibTeX();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCcmType() {
|
||||||
|
return Monograph.class.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.arsdigita.cms.scipublications.exporter.bibtex.converters;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
|
import com.arsdigita.cms.scipublications.exporter.bibtex.builders.UnsupportedFieldException;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jensp
|
||||||
|
*/
|
||||||
|
public class PublicationConverter extends AbstractBibTeXConverter {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(
|
||||||
|
PublicationConverter.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convert(final Publication publication) {
|
||||||
|
convertAuthors(publication);
|
||||||
|
try {
|
||||||
|
convertTitle(publication);
|
||||||
|
convertYear(publication);
|
||||||
|
} catch (UnsupportedFieldException ex) {
|
||||||
|
logger.warn("Tried to set unsupported BibTeX field while "
|
||||||
|
+ "converting a publication");
|
||||||
|
}
|
||||||
|
|
||||||
|
return getBibTeXBuilder().toBibTeX();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBibTeXType() {
|
||||||
|
return "misc";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCcmType() {
|
||||||
|
return Publication.class.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.arsdigita.cms.scipublications.exporter.bibtex.converters;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
|
import com.arsdigita.cms.contenttypes.PublicationWithPublisher;
|
||||||
|
import com.arsdigita.cms.scipublications.exporter.bibtex.builders.UnsupportedFieldException;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jensp
|
||||||
|
*/
|
||||||
|
public class PublicationWithPublisherConverter extends AbstractBibTeXConverter {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(
|
||||||
|
PublicationWithPublisherConverter.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getBibTeXType() {
|
||||||
|
return "misc";
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
convertAuthors(publication);
|
||||||
|
try {
|
||||||
|
convertTitle(publication);
|
||||||
|
convertYear(publication);
|
||||||
|
|
||||||
|
convertPublisher(_publication);
|
||||||
|
convertISBN(_publication);
|
||||||
|
convertEdition(_publication);
|
||||||
|
} catch (UnsupportedFieldException ex) {
|
||||||
|
logger.warn("Tried to set unsupported BibTeX field while "
|
||||||
|
+ "converting a publication");
|
||||||
|
}
|
||||||
|
|
||||||
|
return getBibTeXBuilder().toBibTeX();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCcmType() {
|
||||||
|
return PublicationWithPublisher.class.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package 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 <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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue