Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docbook 5 support #4319

Merged
merged 20 commits into from
Nov 25, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ..jabref-v4.x
Submodule ..jabref-v4.x added at 6dcf43
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
4 changes: 4 additions & 0 deletions src/main/resources/resource/layout/docbook5.begin.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<bibliography xmlns="http://docbook.org/ns/docbook" version="5.1"
xmlns:xlink="http://www.w3.org/1999/xlink">
<title/>
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>
22 changes: 22 additions & 0 deletions src/main/resources/resource/layout/docbook5.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<biblioentry xreflabel="\format[Authors(3,LastName,EtAl= et al.)]{\author} (\year)" xml:id="\bibtexkey">
<authorgroup>
\begin{author} \format[CreateDocBook5Authors]{\author} \end{author}
\begin{editor} \format[CreateDocBook5Editors]{\editor} \end{editor}
</authorgroup>
<citetitle pubwork="article">\format[XMLChars,RemoveLatexCommands]{\title}</citetitle>
\begin{journal} <citetitle pubwork="journal">\format[XMLChars]{\journal}</citetitle>\end{journal}
\begin{publisher} <publisher>
<publishername>\format[XMLChars]{\publisher}</publishername>
</publisher>\end{publisher}
\begin{volume} <volumenum>\volume</volumenum> \end{volume}
\begin{edition} <edition>\format[XMLChars,RemoveLatexCommands]{\edition}</edition> \end{edition}
\begin{pages} <artpagenums>\format[FormatPagesForXML]{\pages}</artpagenums> \end{pages}
\begin{year} <pubdate>\year</pubdate> \end{year}
\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{abstract} <abstract>
<para>\format[XMLChars,RemoveLatexCommands]{\abstract}
</para>
</abstract>\end{abstract}
</biblioentry>

11 changes: 11 additions & 0 deletions src/main/resources/resource/layout/docbook5.mastersthesis.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<biblioentry xreflabel="\bibtexkey" id="\bibtexkey">
<authorgroup>
\begin{author} \format[CreateDocBook5Authors]{\author} \end{author}
</authorgroup>
<citetitle pubwork="manuscript">\format[XMLChars,RemoveLatexCommands]{\title}</citetitle>
\begin{school} <publisher>
<publishername>\format[XMLChars]{\school}</publishername>
</publisher>\end{school}
\begin{year} <pubdate>\year</pubdate> \end{year}
\begin{url} <bibliomisc><ulink url="\format[XMLChars]{\url}">\format[XMLChars]{\url}</ulink></bibliomisc>\end{url}
</biblioentry>