Skip to content

Commit

Permalink
Add docbook 5 support (#4319)
Browse files Browse the repository at this point in the history
* Add docbook 5 support
Renamed to docbook 5 export
removed old layout files

* rename old docbook to docbook 4
use lastName only in docbook5
use new docbook template
favor composition over inheritance
add docbook version enum

* fix wrong method name in masterthesis for docbook4

* add test for docbook5

* split format in separate files

* remove submodule accidentaly commited

* fix variable ordr

* fix tests

* fix checkstyle

* Update docbook5 layout fiels

* fix tests

* Use FullName instead of NoInitials
User lower case formatter for \entrytype

* lastname instead of fullname

* update to latest version of docbook layout files provided
convert tab character to spaces

* fix test
  • Loading branch information
Siedlerchr authored Nov 25, 2018
1 parent 742cfce commit 9213e3c
Show file tree
Hide file tree
Showing 25 changed files with 524 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/logic/exporter/ExporterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static ExporterFactory create(Map<String, TemplateExporter> customFormats
// Initialize build-in exporters
exporters.add(new TemplateExporter("HTML", "html", "html", null, StandardFileType.HTML, layoutPreferences, savePreferences));
exporters.add(new TemplateExporter(Localization.lang("Simple HTML"), "simplehtml", "simplehtml", null, StandardFileType.HTML, layoutPreferences, savePreferences));
exporters.add(new TemplateExporter("DocBook 4.4", "docbook", "docbook", null, StandardFileType.XML, layoutPreferences, savePreferences));
exporters.add(new TemplateExporter("DocBook 5.1", "docbook5", "docbook5", null, StandardFileType.XML, layoutPreferences, savePreferences));
exporters.add(new TemplateExporter("DocBook 4", "docbook4", "docbook4", null, StandardFileType.XML, layoutPreferences, savePreferences));
exporters.add(new TemplateExporter("DIN 1505", "din1505", "din1505winword", "din1505", StandardFileType.RTF, layoutPreferences, savePreferences));
exporters.add(new TemplateExporter("BibO RDF", "bibordf", "bibordf", null, StandardFileType.RDF, layoutPreferences, savePreferences));
exporters.add(new TemplateExporter(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs", StandardFileType.HTML, layoutPreferences, savePreferences));
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/org/jabref/logic/layout/LayoutEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import org.jabref.logic.layout.format.Authors;
import org.jabref.logic.layout.format.CompositeFormat;
import org.jabref.logic.layout.format.CreateBibORDFAuthors;
import org.jabref.logic.layout.format.CreateDocBookAuthors;
import org.jabref.logic.layout.format.CreateDocBookEditors;
import org.jabref.logic.layout.format.CreateDocBook4Authors;
import org.jabref.logic.layout.format.CreateDocBook4Editors;
import org.jabref.logic.layout.format.CreateDocBook5Authors;
import org.jabref.logic.layout.format.CreateDocBook5Editors;
import org.jabref.logic.layout.format.CurrentDate;
import org.jabref.logic.layout.format.DOICheck;
import org.jabref.logic.layout.format.DOIStrip;
Expand Down Expand Up @@ -444,10 +446,14 @@ private LayoutFormatter getLayoutFormatterByName(String name) throws Exception {
return new CompositeFormat();
case "CreateBibORDFAuthors":
return new CreateBibORDFAuthors();
case "CreateDocBookAuthors":
return new CreateDocBookAuthors();
case "CreateDocBookEditors":
return new CreateDocBookEditors();
case "CreateDocBook4Authors":
return new CreateDocBook4Authors();
case "CreateDocBook4Editors":
return new CreateDocBook4Editors();
case "CreateDocBook5Authors":
return new CreateDocBook5Authors();
case "CreateDocBook5Editors":
return new CreateDocBook5Editors();
case "CurrentDate":
return new CurrentDate();
case "DateFormatter":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jabref.logic.layout.format;

import org.jabref.logic.layout.LayoutFormatter;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.FieldName;

/**
* Create DocBook authors formatter.
*/
public class CreateDocBook4Authors implements LayoutFormatter {

@Override
public String format(String fieldText) {
StringBuilder sb = new StringBuilder(100);
AuthorList al = AuthorList.parse(fieldText);
DocBookAuthorFormatter formatter = new DocBookAuthorFormatter();
formatter.addBody(sb, al, FieldName.AUTHOR, DocBookVersion.DOCBOOK_4);
return sb.toString();

}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package org.jabref.logic.layout.format;

import org.jabref.logic.layout.LayoutFormatter;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.FieldName;

/**
* Create DocBook editors formatter.
* Create DocBook4 editors formatter.
*/
public class CreateDocBookEditors extends CreateDocBookAuthors {
public class CreateDocBook4Editors implements LayoutFormatter {

@Override
public String format(String fieldText) {
// <editor><firstname>L.</firstname><surname>Xue</surname></editor>
StringBuilder sb = new StringBuilder(100);
AuthorList al = AuthorList.parse(fieldText);
addBody(sb, al, FieldName.EDITOR);
DocBookAuthorFormatter formatter = new DocBookAuthorFormatter();
formatter.addBody(sb, al, FieldName.EDITOR, DocBookVersion.DOCBOOK_4);
return sb.toString();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jabref.logic.layout.format;

import org.jabref.logic.layout.LayoutFormatter;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.FieldName;

/**
* Create DocBook5 authors formatter
*/
public class CreateDocBook5Authors implements LayoutFormatter {

@Override
public String format(String fieldText) {

StringBuilder sb = new StringBuilder(100);
AuthorList al = AuthorList.parse(fieldText);

DocBookAuthorFormatter authorFormatter = new DocBookAuthorFormatter();
authorFormatter.addBody(sb, al, FieldName.AUTHOR, DocBookVersion.DOCBOOK_5);
return sb.toString();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.jabref.logic.layout.format;

import org.jabref.logic.layout.LayoutFormatter;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.FieldName;

/**
* Create DocBook editors formatter.
*/
public class CreateDocBook5Editors implements LayoutFormatter {

@Override
public String format(String fieldText) {
// <editor><personname><firstname>L.</firstname><surname>Xue</surname></personname></editor>
StringBuilder sb = new StringBuilder(100);
AuthorList al = AuthorList.parse(fieldText);
DocBookAuthorFormatter formatter = new DocBookAuthorFormatter();
formatter.addBody(sb, al, FieldName.EDITOR, DocBookVersion.DOCBOOK_5);
return sb.toString();

}

}
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package org.jabref.logic.layout.format;

import org.jabref.logic.layout.LayoutFormatter;
import org.jabref.model.entry.Author;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.FieldName;

/**
* Create DocBook authors formatter.
* DocBook author formatter for both version 4 and 5
*
*/
public class CreateDocBookAuthors implements LayoutFormatter {
public class DocBookAuthorFormatter {

private static final XMLChars XML_CHARS = new XMLChars();

@Override
public String format(String fieldText) {

StringBuilder sb = new StringBuilder(100);

AuthorList al = AuthorList.parse(fieldText);

addBody(sb, al, FieldName.AUTHOR);
return sb.toString();

}

public void addBody(StringBuilder sb, AuthorList al, String tagName) {
/**
*
* @param sb {@link StringBuilder}
* @param al {@link AuthorList}
* @param tagName Editor or author field/tag
* @param version @link {@link DocBookVersion}
*/
public void addBody(StringBuilder sb, AuthorList al, String tagName, DocBookVersion version) {
for (int i = 0; i < al.getNumberOfAuthors(); i++) {
sb.append('<').append(tagName).append('>');
if (version == DocBookVersion.DOCBOOK_5) {
sb.append("<personname>");
}
Author a = al.getAuthor(i);
a.getFirst().filter(first -> !first.isEmpty()).ifPresent(first -> sb.append("<firstname>")
.append(CreateDocBookAuthors.XML_CHARS.format(first)).append("</firstname>"));
.append(XML_CHARS.format(first)).append("</firstname>"));
a.getVon().filter(von -> !von.isEmpty()).ifPresent(von -> sb.append("<othername>")
.append(CreateDocBookAuthors.XML_CHARS.format(von)).append("</othername>"));
.append(XML_CHARS.format(von)).append("</othername>"));
a.getLast().filter(last -> !last.isEmpty()).ifPresent(last -> {
sb.append("<surname>").append(CreateDocBookAuthors.XML_CHARS.format(last));
sb.append("<surname>").append(XML_CHARS.format(last));
a.getJr().filter(jr -> !jr.isEmpty())
.ifPresent(jr -> sb.append(' ').append(CreateDocBookAuthors.XML_CHARS.format(jr)));
.ifPresent(jr -> sb.append(' ').append(XML_CHARS.format(jr)));
sb.append("</surname>");
if (version == DocBookVersion.DOCBOOK_5) {
sb.append("</personname>");
}
});

if (i < (al.getNumberOfAuthors() - 1)) {
Expand All @@ -46,5 +46,4 @@ public void addBody(StringBuilder sb, AuthorList al, String tagName) {
}
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.jabref.logic.layout.format;

public enum DocBookVersion {
DOCBOOK_4,
DOCBOOK_5
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<biblioentry xreflabel="\bibtexkey" id="\bibtexkey">
<authorgroup>
\begin{author} \format[CreateDocBookAuthors]{\author} \end{author}
\begin{editor} \format[CreateDocBookEditors]{\editor} \end{editor}
\begin{author} \format[CreateDocBook4Authors]{\author} \end{author}
\begin{editor} \format[CreateDocBook4Editors]{\editor} \end{editor}
</authorgroup>
<citetitle pubwork="article">\format[XMLChars,RemoveLatexCommands]{\title}</citetitle>
\begin{journal} <citetitle pubwork="journal">\format[XMLChars]{\journal}</citetitle>\end{journal}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<biblioentry xreflabel="\bibtexkey" id="\bibtexkey">
<authorgroup>
\begin{author} \format[CreateDocBookAuthors]{\author} \end{author}
\begin{author} \format[CreateDocBook4Authors]{\author} \end{author}
</authorgroup>
<citetitle pubwork="manuscript">\format[XMLChars,RemoveLatexCommands]{\title}</citetitle>
\begin{school} <publisher>
Expand Down
36 changes: 36 additions & 0 deletions src/main/resources/resource/layout/docbook5.article.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<biblioentry xreflabel="\format[Authors(3,LastName,EtAl= et al.)]{\author} (\year)" xml:id="\bibtexkey">
<authorgroup>
<!--AUTHORS-->
\begin{author} \format[CreateDocBook5Authors]{\author} \end{author}
<!--EDITORS-->
\begin{editor} \format[CreateDocBook5Editors]{\editor} \end{editor}
</authorgroup>
<!--TITLE-->
\begin{title} <citetitle pubwork="article">\format[XMLChars,RemoveLatexCommands]{\title}</citetitle> \end{title}

<!--JOURNAL, Vol, Pages, Year-->
\begin{journal}
<biblioset relation="journal">\n
\begin{volume} <volumenum>\volume</volumenum> \end{volume}
\begin{pages} <artpagenums>\format[FormatPagesForXML]{\pages}</artpagenums> \end{pages}
\begin{year} <pubdate>\year</pubdate> \end{year}
\end{journal}

<!-- IDENTIFIERS-->
\begin{url}
<bibliomisc><link xlink:href="\format[XMLChars]{\url}">\format[XMLChars]{\url}</link></bibliomisc>
\end{url}
\begin{doi}
<biblioid class="doi">\format[XMLChars]{\doi}</biblioid>
\end{doi}
\begin{isbn}
<biblioid class="isbn">\format[XMLChars]{\isbn}</biblioid>
\end{isbn}

<!--ABSTRACT-->
\begin{abstract}
<abstract>
<para>\format[XMLChars,RemoveLatexCommands]{\abstract}</para>
</abstract>
\end{abstract}
</biblioentry>
7 changes: 7 additions & 0 deletions src/main/resources/resource/layout/docbook5.begin.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<?xml-model href="http://docbook.org/xml/5.1/rng/docbook.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://docbook.org/xml/5.1/sch/docbook.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<bibliography version="5.1" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ns="http://docbook.org/ns/docbook">
40 changes: 40 additions & 0 deletions src/main/resources/resource/layout/docbook5.book.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<biblioentry xreflabel="\format[Authors(3,LastName,EtAl= et al.)]{\author} (\year)" xml:id="\bibtexkey">
<authorgroup>
<!--AUTHORS-->
\begin{author} \format[CreateDocBook5Authors]{\author} \end{author}
<!--EDITORS-->
\begin{editor} \format[CreateDocBook5Editors]{\editor} \end{editor}
</authorgroup>
<!--TITLE-->
\begin{title} <citetitle pubwork="book">\format[XMLChars,RemoveLatexCommands]{\title}</citetitle> \end{title}

<!--BOOK booktitle, edition, (pages), publisher-->
<biblioset relation="book">\n
\begin{booktitle}<booktitle>\format[XMLChars,RemoveLatexCommands]{\booktitle}</booktitle>\end{booktitle}
\begin{edition}<edition>\format[XMLChars,RemoveLatexCommands]{\edition}</edition>\end{edition}
\begin{year}<pubdate>\year</pubdate>\end{year}
\begin{pages}<artpagenums>\format[FormatPagesForXML]{\pages}</artpagenums> \end{pages}
\begin{publisher}<publisher>\end{publisher}
<publishername>\publisher</publishername>
<address>\address</address>
\begin{publisher}</publisher>\end{publisher}
</biblioset>


<!-- IDENTIFIERS-->
\begin{url}
<bibliomisc><link xlink:href="\format[XMLChars]{\url}">\format[XMLChars]{\url}</link></bibliomisc>
\end{url}
\begin{doi}
<biblioid class="doi">\format[XMLChars]{\doi}</biblioid>
\end{doi}
\begin{isbn}
<biblioid class="isbn">\format[XMLChars]{\isbn}</biblioid>
\end{isbn}
<!--ABSTRACT-->
\begin{abstract}
<abstract>
<para>\format[XMLChars,RemoveLatexCommands]{\abstract}</para>
</abstract>
\end{abstract}
</biblioentry>
26 changes: 26 additions & 0 deletions src/main/resources/resource/layout/docbook5.booklet.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<biblioentry xreflabel="\format[Authors(3,LastName,EtAl= et al.)]{\author} (\year)" xml:id="\bibtexkey">
<authorgroup>
<!--AUTHORS-->
\begin{author}\format[CreateDocBook5Authors]{\author}\end{author}
<!--EDITORS-->
\begin{editor}\format[CreateDocBook5Editors]{\editor}\end{editor}
</authorgroup>
<!--TITLE-->
\begin{title}<citetitle pubwork="book">\format[XMLChars,RemoveLatexCommands]{\title}</citetitle> \end{title}
<!--Booklet booktitle, year, howpublished, publisher -->
<biblioset relation="book">\n
\begin{booktitle}<title>\format[XMLChars,RemoveLatexCommands]{\booktitle}</title>\end{booktitle}
\begin{year}<pubdate>\year</pubdate>\end{year}
\begin{howpublished}<bibliomisc role="howpublished">\howpublished</bibliomisc>\end{howpublished}
\begin{publisher}<publisher>\end{publisher}
\begin{publisher}<publishername>\format[XMLChars]{\publisher}</publishername> \end{publisher}
\begin{location}\begin{address}<address>\location</address>\end{address}\end{location}
\begin{publisher}</publisher>\end{publisher}
</biblioset>
<!-- IDENTIFIERS-->
\begin{url}<bibliomisc><link xlink:href="\format[XMLChars]{\url}">\format[XMLChars]{\url}</link></bibliomisc>\end{url}
\begin{doi}<biblioid class="doi">\format[XMLChars]{\doi}</biblioid>\end{doi}
\begin{isbn}<biblioid class="isbn">\format[XMLChars]{\isbn}</biblioid>\end{isbn}
<!--ABSTRACT-->
\begin{abstract}<abstract><para>\format[XMLChars,RemoveLatexCommands]{\abstract}</para></abstract>\end{abstract}
</biblioentry>
30 changes: 30 additions & 0 deletions src/main/resources/resource/layout/docbook5.collection.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<biblioentry xreflabel="\format[Authors(3,LastName,EtAl= et al.)]{\editor} (\year)" xml:id="\bibtexkey">
<authorgroup>
<!--EDITORS-->
\begin{editor}\format[CreateDocBook5Editors]{\editor}\end{editor}
</authorgroup>
<!--TITLE-->
\begin{title}<citetitle pubwork="book">\format[XMLChars,RemoveLatexCommands]{\title}</citetitle> \end{title}
<!--Collection booktitle, edition, series, (pages), publisher-->
<biblioset relation="book">\n
\begin{booktitle}<title>\format[XMLChars,RemoveLatexCommands]{\booktitle}</title>\end{booktitle}
\begin{edition}<edition>\format[XMLChars,RemoveLatexCommands]{\edition}</edition>\end{edition}
\begin{year}<pubdate>\year</pubdate>\end{year}
\begin{volume}<volumenum>\volume</volumenum> \end{volume}
\begin{chapter}<bibliomisc role="secnum">\chapter</bibliomisc> \end{chapter}
\begin{pages}<artpagenums>\format[FormatPagesForXML]{\pages}</artpagenums> \end{pages}
\begin{publisher}<publisher>\end{publisher}
\begin{publisher}<publishername>\format[XMLChars]{\publisher}</publishername> \end{publisher}
\begin{location}\begin{address}<address>\location</address>\end{address}\end{location}
\begin{publisher}</publisher>\end{publisher}
</biblioset>
\begin{series}<bibliomisc role="seriestitle">\format[XMLChars,RemoveLatexCommands]{\series}</bibliomisc>\end{series}
\begin{series}\begin{editora}<bibliomisc role="serieseditor">\format[XMLChars,RemoveLatexCommands]{\editora}</bibliomisc>\end{editora}\end{series}

<!-- IDENTIFIERS-->
\begin{url}<bibliomisc><link xlink:href="\format[XMLChars]{\url}">\format[XMLChars]{\url}</link></bibliomisc>\end{url}
\begin{doi}<biblioid class="doi">\format[XMLChars]{\doi}</biblioid>\end{doi}
\begin{isbn}<biblioid class="isbn">\format[XMLChars]{\isbn}</biblioid>\end{isbn}
<!--ABSTRACT-->
\begin{abstract}<abstract><para>\format[XMLChars,RemoveLatexCommands]{\abstract}</para></abstract>\end{abstract}
</biblioentry>
1 change: 1 addition & 0 deletions src/main/resources/resource/layout/docbook5.end.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
</bibliography>
Loading

0 comments on commit 9213e3c

Please sign in to comment.