#7597, #7893, #7895, #7898: Updated DMP template file (h2020.docx) for export | Added Dataset template file (h2020_dataset.docx) for export | Updated indentation on exported docs.
1. h2020.docx, h2020_dataset.docx: Updated DMP template & Added Dataset template. 2. application.properties, application-devel.properties, application-production.properties, application-staging.properties: Added property for dataset template file path configuration.h2020datasettemplate=documents/h2020_dataset.docx 3. ConfigLoader.java: Added method XWPFDocument getDatasetDocument(); 4. DefaultConfigLoader.java: Added fiedls and methods for loading Dataset template (h2020_dataset.docx). 5. DataManagementPlanManager.java, DatasetManager.java, , HtmlToWorldBuilder.java, WordBuilder.java: Updated header/footer/first page in exports for DMPs and Datasets | Updated indentation in exports.
This commit is contained in:
parent
9b4c7aeb6f
commit
a2228a5fb6
|
@ -1190,7 +1190,17 @@ public class DataManagementPlanManager {
|
||||||
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
|
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
|
||||||
throw new UnauthorisedException();
|
throw new UnauthorisedException();
|
||||||
|
|
||||||
wordBuilder.fillFirstPage(dmpEntity, document);
|
wordBuilder.fillFirstPage(dmpEntity, null, document);
|
||||||
|
|
||||||
|
// int powered_pos = document.getParagraphs().size() - 3;
|
||||||
|
int powered_pos = wordBuilder.findPosOfPoweredBy(document);
|
||||||
|
XWPFParagraph powered_par = null;
|
||||||
|
XWPFParagraph argos_img_par = null;
|
||||||
|
if(powered_pos != -1) {
|
||||||
|
powered_par = document.getParagraphArray(powered_pos);
|
||||||
|
argos_img_par = document.getParagraphArray(powered_pos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// // DMP info on top of the document.
|
// // DMP info on top of the document.
|
||||||
// wordBuilder.addParagraphContent("Data Management Plan Information", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
// wordBuilder.addParagraphContent("Data Management Plan Information", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||||
|
@ -1252,7 +1262,7 @@ public class DataManagementPlanManager {
|
||||||
// Custom style for the Dataset title.
|
// Custom style for the Dataset title.
|
||||||
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||||
XWPFParagraph datasetLabelParagraph = document.createParagraph();
|
XWPFParagraph datasetLabelParagraph = document.createParagraph();
|
||||||
datasetLabelParagraph.setStyle("Heading2");
|
// datasetLabelParagraph.setStyle("Heading2");
|
||||||
datasetLabelParagraph.setSpacingBetween(1.0);
|
datasetLabelParagraph.setSpacingBetween(1.0);
|
||||||
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
|
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
|
||||||
runDatasetTitle1.setText("Title: ");
|
runDatasetTitle1.setText("Title: ");
|
||||||
|
@ -1261,12 +1271,12 @@ public class DataManagementPlanManager {
|
||||||
//runDatasetTitle1.setFontSize(12);
|
//runDatasetTitle1.setFontSize(12);
|
||||||
XWPFRun runDatasetTitle = datasetLabelParagraph.createRun();
|
XWPFRun runDatasetTitle = datasetLabelParagraph.createRun();
|
||||||
runDatasetTitle.setText(datasetEntity.getLabel());
|
runDatasetTitle.setText(datasetEntity.getLabel());
|
||||||
//runDatasetTitle.setColor("2E75B6");
|
runDatasetTitle.setColor("116a78");
|
||||||
//runDatasetTitle.setBold(true);
|
//runDatasetTitle.setBold(true);
|
||||||
//runDatasetTitle.setFontSize(12);
|
//runDatasetTitle.setFontSize(12);
|
||||||
|
|
||||||
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
||||||
datasetTemplateParagraph.setStyle("Heading3");
|
// datasetTemplateParagraph.setStyle("Heading3");
|
||||||
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
||||||
runDatasetTemplate1.setText("Template: ");
|
runDatasetTemplate1.setText("Template: ");
|
||||||
runDatasetTemplate1.setColor("000000");
|
runDatasetTemplate1.setColor("000000");
|
||||||
|
@ -1274,7 +1284,7 @@ public class DataManagementPlanManager {
|
||||||
//runDatasetTemplate1.setFontSize(12);
|
//runDatasetTemplate1.setFontSize(12);
|
||||||
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
|
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
|
||||||
runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
|
runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
|
||||||
//runDatasetTemplate.setColor("2E75B6");
|
runDatasetTemplate.setColor("116a78");
|
||||||
//runDatasetTemplate.setBold(true);
|
//runDatasetTemplate.setBold(true);
|
||||||
//runDatasetTemplate.setFontSize(12);
|
//runDatasetTemplate.setFontSize(12);
|
||||||
|
|
||||||
|
@ -1315,11 +1325,11 @@ public class DataManagementPlanManager {
|
||||||
// }*/
|
// }*/
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
|
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0);
|
||||||
|
|
||||||
// Dataset Description custom style.
|
// Dataset Description custom style.
|
||||||
XWPFParagraph datasetDescriptionParagraph = document.createParagraph();
|
XWPFParagraph datasetDescriptionParagraph = document.createParagraph();
|
||||||
datasetDescriptionParagraph.setStyle("Heading3");
|
datasetDescriptionParagraph.setStyle("Heading4");
|
||||||
datasetDescriptionParagraph.setSpacingBetween(1.5);
|
datasetDescriptionParagraph.setSpacingBetween(1.5);
|
||||||
XWPFRun datasetDescriptionRun = datasetDescriptionParagraph.createRun();
|
XWPFRun datasetDescriptionRun = datasetDescriptionParagraph.createRun();
|
||||||
datasetDescriptionRun.setText("Dataset Description");
|
datasetDescriptionRun.setText("Dataset Description");
|
||||||
|
@ -1345,7 +1355,20 @@ public class DataManagementPlanManager {
|
||||||
// document.removeBodyElement(0);
|
// document.removeBodyElement(0);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
wordBuilder.fillFooter(dmpEntity, document);
|
|
||||||
|
if(powered_pos != -1) {
|
||||||
|
document.getLastParagraph().setPageBreak(false);
|
||||||
|
document.createParagraph();
|
||||||
|
document.setParagraph(powered_par, document.getParagraphs().size() - 1);
|
||||||
|
|
||||||
|
document.createParagraph();
|
||||||
|
document.setParagraph(argos_img_par, document.getParagraphs().size() - 1);
|
||||||
|
|
||||||
|
document.removeBodyElement(powered_pos + 1);
|
||||||
|
document.removeBodyElement(powered_pos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
wordBuilder.fillFooter(dmpEntity, document, false);
|
||||||
|
|
||||||
String fileName = "DMP_" + dmpEntity.getGrant().getLabel();
|
String fileName = "DMP_" + dmpEntity.getGrant().getLabel();
|
||||||
if (versioned) {
|
if (versioned) {
|
||||||
|
|
|
@ -396,29 +396,45 @@ public class DatasetManager {
|
||||||
return pagedDatasetProfile;
|
return pagedDatasetProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private XWPFDocument getWordDocument(ConfigLoader configLoader, eu.eudat.data.entities.Dataset datasetEntity, VisibilityRuleService visibilityRuleService) throws IOException {
|
private XWPFDocument getWordDocument(ConfigLoader configLoader, eu.eudat.data.entities.Dataset datasetEntity, VisibilityRuleService visibilityRuleService, Principal principal) throws IOException {
|
||||||
WordBuilder wordBuilder = new WordBuilder(this.environment);
|
WordBuilder wordBuilder = new WordBuilder(this.environment);
|
||||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||||
XWPFDocument document = configLoader.getDocument();
|
XWPFDocument document = configLoader.getDatasetDocument();
|
||||||
|
|
||||||
wordBuilder.addParagraphContent(datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
eu.eudat.data.entities.DMP dmpEntity = datasetEntity.getDmp();
|
||||||
|
|
||||||
|
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
|
||||||
|
throw new UnauthorisedException();
|
||||||
|
|
||||||
|
wordBuilder.fillFirstPage(dmpEntity, datasetEntity, document);
|
||||||
|
wordBuilder.fillFooter(dmpEntity, document, true);
|
||||||
|
|
||||||
|
int powered_pos = wordBuilder.findPosOfPoweredBy(document);
|
||||||
|
XWPFParagraph powered_par = null;
|
||||||
|
XWPFParagraph argos_img_par = null;
|
||||||
|
if(powered_pos != -1) {
|
||||||
|
powered_par = document.getParagraphArray(powered_pos);
|
||||||
|
argos_img_par = document.getParagraphArray(powered_pos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// wordBuilder.addParagraphContent(datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||||
|
|
||||||
// Space below Dataset title.
|
// Space below Dataset title.
|
||||||
XWPFParagraph parBreakDataset = document.createParagraph();
|
// XWPFParagraph parBreakDataset = document.createParagraph();
|
||||||
|
//
|
||||||
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
// XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
||||||
datasetTemplateParagraph.setStyle("Heading2");
|
// datasetTemplateParagraph.setStyle("Heading2");
|
||||||
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
// XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
||||||
runDatasetTemplate1.setText("Template: ");
|
// runDatasetTemplate1.setText("Template: ");
|
||||||
runDatasetTemplate1.setBold(true);
|
// runDatasetTemplate1.setBold(true);
|
||||||
runDatasetTemplate1.setFontSize(12);
|
// runDatasetTemplate1.setFontSize(12);
|
||||||
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
|
// XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
|
||||||
runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
|
// runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
|
||||||
runDatasetTemplate.setColor("2E75B6");
|
// runDatasetTemplate.setColor("2E75B6");
|
||||||
runDatasetTemplate.setBold(true);
|
// runDatasetTemplate.setBold(true);
|
||||||
runDatasetTemplate.setFontSize(12);
|
// runDatasetTemplate.setFontSize(12);
|
||||||
|
//
|
||||||
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
|
// wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
|
||||||
|
|
||||||
/*XWPFParagraph externalReferencesParagraph = document.createParagraph();
|
/*XWPFParagraph externalReferencesParagraph = document.createParagraph();
|
||||||
externalReferencesParagraph.setStyle("Heading2");
|
externalReferencesParagraph.setStyle("Heading2");
|
||||||
|
@ -460,7 +476,7 @@ public class DatasetManager {
|
||||||
properties = jObject.toMap();
|
properties = jObject.toMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
// wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||||
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
|
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
|
||||||
visibilityRuleService.setProperties(properties);
|
visibilityRuleService.setProperties(properties);
|
||||||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||||
|
@ -469,8 +485,20 @@ public class DatasetManager {
|
||||||
// File exportFile = new File(label + ".docx");
|
// File exportFile = new File(label + ".docx");
|
||||||
|
|
||||||
// Removes the top empty headings.
|
// Removes the top empty headings.
|
||||||
for (int i = 0; i < 6; i++) {
|
// for (int i = 0; i < 6; i++) {
|
||||||
document.removeBodyElement(0);
|
// document.removeBodyElement(0);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if(powered_pos != -1) {
|
||||||
|
document.getLastParagraph().setPageBreak(false);
|
||||||
|
document.createParagraph();
|
||||||
|
document.setParagraph(powered_par, document.getParagraphs().size() - 1);
|
||||||
|
|
||||||
|
document.createParagraph();
|
||||||
|
document.setParagraph(argos_img_par, document.getParagraphs().size() - 1);
|
||||||
|
|
||||||
|
document.removeBodyElement(powered_pos + 1);
|
||||||
|
document.removeBodyElement(powered_pos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
|
@ -493,7 +521,7 @@ public class DatasetManager {
|
||||||
properties = jObject.toMap();
|
properties = jObject.toMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0);
|
||||||
visibilityRuleService.setProperties(properties);
|
visibilityRuleService.setProperties(properties);
|
||||||
visibilityRuleService.buildVisibilityContext(dataset.getDatasetProfileDefinition().getRules());
|
visibilityRuleService.buildVisibilityContext(dataset.getDatasetProfileDefinition().getRules());
|
||||||
wordBuilder.build(document, dataset.getDatasetProfileDefinition(), visibilityRuleService);
|
wordBuilder.build(document, dataset.getDatasetProfileDefinition(), visibilityRuleService);
|
||||||
|
@ -521,7 +549,7 @@ public class DatasetManager {
|
||||||
exportEnvelope.setFilename(label + ".docx");
|
exportEnvelope.setFilename(label + ".docx");
|
||||||
String uuid = UUID.randomUUID().toString();
|
String uuid = UUID.randomUUID().toString();
|
||||||
File exportFile = new File(this.environment.getProperty("temp.temp") + uuid + ".docx");
|
File exportFile = new File(this.environment.getProperty("temp.temp") + uuid + ".docx");
|
||||||
XWPFDocument document = getWordDocument(configLoader, datasetEntity, visibilityRuleService);
|
XWPFDocument document = getWordDocument(configLoader, datasetEntity, visibilityRuleService, principal);
|
||||||
FileOutputStream out = new FileOutputStream(exportFile);
|
FileOutputStream out = new FileOutputStream(exportFile);
|
||||||
document.write(out);
|
document.write(out);
|
||||||
out.close();
|
out.close();
|
||||||
|
|
|
@ -12,6 +12,7 @@ public interface ConfigLoader {
|
||||||
ExternalUrls getExternalUrls();
|
ExternalUrls getExternalUrls();
|
||||||
List<String> getRdaProperties();
|
List<String> getRdaProperties();
|
||||||
XWPFDocument getDocument();
|
XWPFDocument getDocument();
|
||||||
|
XWPFDocument getDatasetDocument();
|
||||||
ConfigurableProviders getConfigurableProviders();
|
ConfigurableProviders getConfigurableProviders();
|
||||||
Map<String, String> getKeyToSourceMap();
|
Map<String, String> getKeyToSourceMap();
|
||||||
List<DOIFunder> getDOIFunders();
|
List<DOIFunder> getDOIFunders();
|
||||||
|
|
|
@ -38,6 +38,7 @@ public class DefaultConfigLoader implements ConfigLoader {
|
||||||
private ExternalUrls externalUrls;
|
private ExternalUrls externalUrls;
|
||||||
private List<String> rdaProperties;
|
private List<String> rdaProperties;
|
||||||
private XWPFDocument document;
|
private XWPFDocument document;
|
||||||
|
private XWPFDocument datasetDocument;
|
||||||
private ConfigurableProviders configurableProviders;
|
private ConfigurableProviders configurableProviders;
|
||||||
private Map<String, String> keyToSourceMap;
|
private Map<String, String> keyToSourceMap;
|
||||||
private List<DOIFunder> doiFunders = new ArrayList<>();
|
private List<DOIFunder> doiFunders = new ArrayList<>();
|
||||||
|
@ -103,6 +104,24 @@ public class DefaultConfigLoader implements ConfigLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setDatasetDocument() {
|
||||||
|
String filePath = environment.getProperty("configuration.h2020datasettemplate");
|
||||||
|
logger.info("Loaded also config file: " + filePath);
|
||||||
|
InputStream is = null;
|
||||||
|
try {
|
||||||
|
is = getStreamFromPath(filePath);
|
||||||
|
this.datasetDocument = new XWPFDocument(is);
|
||||||
|
} catch (IOException | NullPointerException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (is != null) is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.warn("Warning: Could not close a stream after reading from file: " + filePath, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setConfigurableProviders() {
|
private void setConfigurableProviders() {
|
||||||
String filePath = environment.getProperty("configuration.configurable_login_providers");
|
String filePath = environment.getProperty("configuration.configurable_login_providers");
|
||||||
logger.info("Loaded also config file: " + filePath);
|
logger.info("Loaded also config file: " + filePath);
|
||||||
|
@ -183,6 +202,11 @@ public class DefaultConfigLoader implements ConfigLoader {
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XWPFDocument getDatasetDocument() {
|
||||||
|
this.setDatasetDocument();
|
||||||
|
return datasetDocument;
|
||||||
|
}
|
||||||
|
|
||||||
public ConfigurableProviders getConfigurableProviders() {
|
public ConfigurableProviders getConfigurableProviders() {
|
||||||
if (configurableProviders == null) {
|
if (configurableProviders == null) {
|
||||||
configurableProviders = new ConfigurableProviders();
|
configurableProviders = new ConfigurableProviders();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.eudat.logic.utilities.documents.word;
|
package eu.eudat.logic.utilities.documents.word;
|
||||||
|
|
||||||
import org.apache.poi.xwpf.usermodel.*;
|
import org.apache.poi.xwpf.usermodel.*;
|
||||||
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Node;
|
import org.jsoup.nodes.Node;
|
||||||
import org.jsoup.nodes.TextNode;
|
import org.jsoup.nodes.TextNode;
|
||||||
|
@ -22,15 +23,17 @@ public class HtmlToWorldBuilder implements NodeVisitor {
|
||||||
private XWPFNumbering numbering;
|
private XWPFNumbering numbering;
|
||||||
private Queue<BigInteger> abstractNumId;
|
private Queue<BigInteger> abstractNumId;
|
||||||
private BigInteger numberingLevel;
|
private BigInteger numberingLevel;
|
||||||
|
private XmlCursor cursor;
|
||||||
|
|
||||||
public static HtmlToWorldBuilder convert(XWPFDocument document, Document htmlDocument, float indentation) {
|
public static HtmlToWorldBuilder convert(XWPFDocument document, Document htmlDocument, float indentation) {
|
||||||
XWPFParagraph paragraph = document.createParagraph();
|
XWPFParagraph paragraph = document.createParagraph();
|
||||||
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(paragraph, indentation);
|
paragraph.setIndentFromLeft(Math.round(400 * indentation));
|
||||||
|
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(paragraph, indentation, null);
|
||||||
NodeTraversor.traverse(htmlToWorldBuilder, htmlDocument);
|
NodeTraversor.traverse(htmlToWorldBuilder, htmlDocument);
|
||||||
return htmlToWorldBuilder;
|
return htmlToWorldBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HtmlToWorldBuilder(XWPFParagraph paragraph, float indentation) {
|
public HtmlToWorldBuilder(XWPFParagraph paragraph, float indentation, XmlCursor cursor) {
|
||||||
this.paragraph = paragraph;
|
this.paragraph = paragraph;
|
||||||
this.run = this.paragraph.createRun();
|
this.run = this.paragraph.createRun();
|
||||||
this.dumpRun = false;
|
this.dumpRun = false;
|
||||||
|
@ -40,6 +43,7 @@ public class HtmlToWorldBuilder implements NodeVisitor {
|
||||||
this.abstractNumId = new ArrayDeque<>();
|
this.abstractNumId = new ArrayDeque<>();
|
||||||
this.numberingLevel = BigInteger.valueOf(-1);
|
this.numberingLevel = BigInteger.valueOf(-1);
|
||||||
this.setDefaultIndentation();
|
this.setDefaultIndentation();
|
||||||
|
this.cursor = cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -96,7 +100,13 @@ public class HtmlToWorldBuilder implements NodeVisitor {
|
||||||
break;
|
break;
|
||||||
case "div":
|
case "div":
|
||||||
case "p":
|
case "p":
|
||||||
|
if(this.cursor != null) {
|
||||||
|
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
|
||||||
|
this.cursor = this.paragraph.getCTP().newCursor();
|
||||||
|
this.cursor.toNextSibling();
|
||||||
|
} else {
|
||||||
this.paragraph = this.paragraph.getDocument().createParagraph();
|
this.paragraph = this.paragraph.getDocument().createParagraph();
|
||||||
|
}
|
||||||
this.run = this.paragraph.createRun();
|
this.run = this.paragraph.createRun();
|
||||||
this.isIdentationUsed = false;
|
this.isIdentationUsed = false;
|
||||||
this.setDefaultIndentation();
|
this.setDefaultIndentation();
|
||||||
|
@ -108,10 +118,15 @@ public class HtmlToWorldBuilder implements NodeVisitor {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "blockquote":
|
case "blockquote":
|
||||||
|
if(this.cursor != null) {
|
||||||
|
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
|
||||||
|
this.cursor = this.paragraph.getCTP().newCursor();
|
||||||
|
} else {
|
||||||
this.paragraph = this.paragraph.getDocument().createParagraph();
|
this.paragraph = this.paragraph.getDocument().createParagraph();
|
||||||
|
}
|
||||||
this.run = this.paragraph.createRun();
|
this.run = this.paragraph.createRun();
|
||||||
if (stringBooleanEntry.getValue()) {
|
if (stringBooleanEntry.getValue()) {
|
||||||
this.paragraph.setIndentationLeft(720);
|
this.paragraph.setIndentationLeft(400);
|
||||||
} else {
|
} else {
|
||||||
this.isIdentationUsed = false;
|
this.isIdentationUsed = false;
|
||||||
this.setDefaultIndentation();
|
this.setDefaultIndentation();
|
||||||
|
@ -120,8 +135,13 @@ public class HtmlToWorldBuilder implements NodeVisitor {
|
||||||
case "ul":
|
case "ul":
|
||||||
if (stringBooleanEntry.getValue()) {
|
if (stringBooleanEntry.getValue()) {
|
||||||
createNumbering(STNumberFormat.BULLET);
|
createNumbering(STNumberFormat.BULLET);
|
||||||
|
} else {
|
||||||
|
if(this.cursor != null) {
|
||||||
|
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
|
||||||
|
this.cursor = this.paragraph.getCTP().newCursor();
|
||||||
} else {
|
} else {
|
||||||
this.paragraph = this.paragraph.getDocument().createParagraph();
|
this.paragraph = this.paragraph.getDocument().createParagraph();
|
||||||
|
}
|
||||||
this.run = this.paragraph.createRun();
|
this.run = this.paragraph.createRun();
|
||||||
this.isIdentationUsed = false;
|
this.isIdentationUsed = false;
|
||||||
this.setDefaultIndentation();
|
this.setDefaultIndentation();
|
||||||
|
@ -132,8 +152,13 @@ public class HtmlToWorldBuilder implements NodeVisitor {
|
||||||
case "ol":
|
case "ol":
|
||||||
if (stringBooleanEntry.getValue()) {
|
if (stringBooleanEntry.getValue()) {
|
||||||
createNumbering(STNumberFormat.DECIMAL);
|
createNumbering(STNumberFormat.DECIMAL);
|
||||||
|
} else {
|
||||||
|
if(this.cursor != null) {
|
||||||
|
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
|
||||||
|
this.cursor = this.paragraph.getCTP().newCursor();
|
||||||
} else {
|
} else {
|
||||||
this.paragraph = this.paragraph.getDocument().createParagraph();
|
this.paragraph = this.paragraph.getDocument().createParagraph();
|
||||||
|
}
|
||||||
this.run = this.paragraph.createRun();
|
this.run = this.paragraph.createRun();
|
||||||
this.isIdentationUsed = false;
|
this.isIdentationUsed = false;
|
||||||
this.setDefaultIndentation();
|
this.setDefaultIndentation();
|
||||||
|
@ -143,8 +168,14 @@ public class HtmlToWorldBuilder implements NodeVisitor {
|
||||||
break;
|
break;
|
||||||
case "li":
|
case "li":
|
||||||
if (stringBooleanEntry.getValue()) {
|
if (stringBooleanEntry.getValue()) {
|
||||||
|
if(this.cursor != null) {
|
||||||
|
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
|
||||||
|
this.cursor = this.paragraph.getCTP().newCursor();
|
||||||
|
} else {
|
||||||
this.paragraph = this.paragraph.getDocument().createParagraph();
|
this.paragraph = this.paragraph.getDocument().createParagraph();
|
||||||
this.paragraph.setIndentationLeft(Math.round(indentation * 720) * (numberingLevel.intValue() + 1));
|
}
|
||||||
|
// this.paragraph.setIndentationLeft(Math.round(indentation * 720) * (numberingLevel.intValue() + 1));
|
||||||
|
this.paragraph.setIndentFromLeft(Math.round(numberingLevel.intValue() * 400 + this.indentation*400));
|
||||||
this.run = this.paragraph.createRun();
|
this.run = this.paragraph.createRun();
|
||||||
this.paragraph.setNumID(((ArrayDeque<BigInteger>)abstractNumId).getLast());
|
this.paragraph.setNumID(((ArrayDeque<BigInteger>)abstractNumId).getLast());
|
||||||
}
|
}
|
||||||
|
@ -238,7 +269,8 @@ public class HtmlToWorldBuilder implements NodeVisitor {
|
||||||
|
|
||||||
private void setDefaultIndentation() {
|
private void setDefaultIndentation() {
|
||||||
if (!isIdentationUsed) {
|
if (!isIdentationUsed) {
|
||||||
this.paragraph.setIndentationLeft(Math.round(indentation * 720.0F));
|
// this.paragraph.setIndentationLeft(Math.round(indentation * 720.0F));
|
||||||
|
this.paragraph.setIndentFromLeft(Math.round(indentation * 400));
|
||||||
this.isIdentationUsed = true;
|
this.isIdentationUsed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.data.entities.DMP;
|
import eu.eudat.data.entities.DMP;
|
||||||
|
import eu.eudat.data.entities.Dataset;
|
||||||
import eu.eudat.data.entities.Organisation;
|
import eu.eudat.data.entities.Organisation;
|
||||||
import eu.eudat.data.entities.Researcher;
|
import eu.eudat.data.entities.Researcher;
|
||||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||||
|
@ -19,10 +20,12 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
import org.apache.poi.xwpf.usermodel.*;
|
import org.apache.poi.xwpf.usermodel.*;
|
||||||
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.select.NodeTraversor;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -88,7 +91,8 @@ public class WordBuilder {
|
||||||
});
|
});
|
||||||
this.options.put(ParagraphStyle.HTML, (mainDocumentPart, item) -> {
|
this.options.put(ParagraphStyle.HTML, (mainDocumentPart, item) -> {
|
||||||
Document htmlDoc = Jsoup.parse(((String)item).replaceAll("\n", "<br>"));
|
Document htmlDoc = Jsoup.parse(((String)item).replaceAll("\n", "<br>"));
|
||||||
HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, indent > 0 ? (indent/2.0F) * 0.8F : 0.8F);
|
// HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, indent > 0 ? (indent/2.0F) * 0.8F : 0.8F);
|
||||||
|
HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, this.indent);
|
||||||
return htmlToWorldBuilder.getParagraph();
|
return htmlToWorldBuilder.getParagraph();
|
||||||
});
|
});
|
||||||
this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> {
|
this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> {
|
||||||
|
@ -228,19 +232,20 @@ public class WordBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFDocument build(XWPFDocument document, PagedDatasetProfile pagedDatasetProfile, VisibilityRuleService visibilityRuleService) throws IOException {
|
public XWPFDocument build(XWPFDocument document, PagedDatasetProfile pagedDatasetProfile, VisibilityRuleService visibilityRuleService) throws IOException {
|
||||||
createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService);
|
// createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService);
|
||||||
XWPFNumbering numbering = document.createNumbering();
|
// XWPFNumbering numbering = document.createNumbering();
|
||||||
BigInteger tempNumId = BigInteger.ONE;
|
// BigInteger tempNumId = BigInteger.ONE;
|
||||||
boolean found = false;
|
// boolean found = false;
|
||||||
while (!found) {
|
// while (!found) {
|
||||||
Object o = numbering.getAbstractNum(tempNumId);
|
// Object o = numbering.getAbstractNum(tempNumId);
|
||||||
found = (o == null);
|
// found = (o == null);
|
||||||
if (!found) tempNumId = tempNumId.add(BigInteger.ONE);
|
// if (!found) tempNumId = tempNumId.add(BigInteger.ONE);
|
||||||
}
|
// }
|
||||||
cTAbstractNum.setAbstractNumId(tempNumId);
|
// cTAbstractNum.setAbstractNumId(tempNumId);
|
||||||
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
|
// XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
|
||||||
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
|
// BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
|
||||||
this.numId = numbering.addNum(abstractNumID);
|
// this.numId = numbering.addNum(abstractNumID);
|
||||||
|
|
||||||
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService);
|
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService);
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
@ -248,7 +253,7 @@ public class WordBuilder {
|
||||||
private void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
private void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
||||||
datasetProfilePages.forEach(item -> {
|
datasetProfilePages.forEach(item -> {
|
||||||
try {
|
try {
|
||||||
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER4, 0, createListing, visibilityRuleService, item.getOrdinal() + 1, null);
|
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, 0, createListing, visibilityRuleService, item.getOrdinal() + 1, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
@ -263,13 +268,13 @@ public class WordBuilder {
|
||||||
String tempSectionString = sectionString != null ? sectionString + "." + (section.getOrdinal() + 1) : "" + (section.getOrdinal() + 1);
|
String tempSectionString = sectionString != null ? sectionString + "." + (section.getOrdinal() + 1) : "" + (section.getOrdinal() + 1);
|
||||||
if (visibilityRuleService.isElementVisible(section.getId())) {
|
if (visibilityRuleService.isElementVisible(section.getId())) {
|
||||||
if (!createListing) {
|
if (!createListing) {
|
||||||
XWPFParagraph paragraph = addParagraphContent(page + "." + tempSectionString + " " + section.getTitle(), mainDocumentPart, style, numId);
|
XWPFParagraph paragraph = addParagraphContent(page + "." + tempSectionString + " " + section.getTitle(), mainDocumentPart, style, numId, indent);
|
||||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
number.setVal(BigInteger.valueOf(indent));
|
// number.setVal(BigInteger.valueOf(indent));
|
||||||
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
|
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
|
||||||
}
|
}
|
||||||
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER4, 1, createListing, visibilityRuleService, page, tempSectionString);
|
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, indent+1, createListing, visibilityRuleService, page, tempSectionString);
|
||||||
hasValue = createCompositeFields(section.getCompositeFields(), mainDocumentPart, 2, createListing, visibilityRuleService, page, tempSectionString);
|
hasValue = createCompositeFields(section.getCompositeFields(), mainDocumentPart, indent+1, createListing, visibilityRuleService, page, tempSectionString);
|
||||||
|
|
||||||
if (!hasValue && paragraphPos > -1) {
|
if (!hasValue && paragraphPos > -1) {
|
||||||
mainDocumentPart.removeBodyElement(paragraphPos);
|
mainDocumentPart.removeBodyElement(paragraphPos);
|
||||||
|
@ -290,19 +295,18 @@ public class WordBuilder {
|
||||||
int paragraphPos = -1;
|
int paragraphPos = -1;
|
||||||
int paragraphPosInner = -1;
|
int paragraphPosInner = -1;
|
||||||
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
|
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
|
||||||
XWPFParagraph paragraph = addParagraphContent("\t" + page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
XWPFParagraph paragraph = addParagraphContent(page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId, indent);
|
||||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
number.setVal(BigInteger.valueOf(indent));
|
// number.setVal(BigInteger.valueOf(indent));
|
||||||
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
|
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
|
||||||
if(compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()){
|
if(compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()){
|
||||||
// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId, indent);
|
||||||
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId);
|
|
||||||
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
|
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
|
||||||
hasMultiplicityItems = true;
|
hasMultiplicityItems = true;
|
||||||
multiplicityItems++;
|
multiplicityItems++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
hasValue = createFields(compositeField.getFields(), mainDocumentPart, indent, createListing, visibilityRuleService, hasMultiplicityItems);
|
||||||
if(hasValue){
|
if(hasValue){
|
||||||
returnedValue = true;
|
returnedValue = true;
|
||||||
} else if(paragraphPosInner > -1){
|
} else if(paragraphPosInner > -1){
|
||||||
|
@ -317,13 +321,13 @@ public class WordBuilder {
|
||||||
if(!createListing){
|
if(!createListing){
|
||||||
c++;
|
c++;
|
||||||
// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
||||||
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId);
|
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId, indent);
|
||||||
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
|
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
|
||||||
hasMultiplicityItems = true;
|
hasMultiplicityItems = true;
|
||||||
multiplicityItems++;
|
multiplicityItems++;
|
||||||
}
|
}
|
||||||
// hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
// hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
||||||
boolean hasValueInner = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
boolean hasValueInner = createFields(multiplicityFieldset.getFields(), mainDocumentPart, indent, createListing, visibilityRuleService, hasMultiplicityItems);
|
||||||
// if(hasValue){
|
// if(hasValue){
|
||||||
if(hasValueInner){
|
if(hasValueInner){
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
|
@ -342,9 +346,9 @@ public class WordBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasValue && compositeField.getHasCommentField() && compositeField.getCommentFieldValue() != null && !compositeField.getCommentFieldValue().isEmpty() && !createListing) {
|
if (hasValue && compositeField.getHasCommentField() && compositeField.getCommentFieldValue() != null && !compositeField.getCommentFieldValue().isEmpty() && !createListing) {
|
||||||
XWPFParagraph paragraph = addParagraphContent("<i>Comment:</i>\n"+compositeField.getCommentFieldValue(), mainDocumentPart, ParagraphStyle.HTML, numId);
|
XWPFParagraph paragraph = addParagraphContent("<i>Comment:</i>\n"+compositeField.getCommentFieldValue(), mainDocumentPart, ParagraphStyle.HTML, numId, indent);
|
||||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
number.setVal(BigInteger.valueOf(indent));
|
// number.setVal(BigInteger.valueOf(indent));
|
||||||
}
|
}
|
||||||
if (!hasValue && paragraphPos > -1) {
|
if (!hasValue && paragraphPos > -1) {
|
||||||
mainDocumentPart.removeBodyElement(paragraphPos);
|
mainDocumentPart.removeBodyElement(paragraphPos);
|
||||||
|
@ -373,10 +377,10 @@ public class WordBuilder {
|
||||||
}
|
}
|
||||||
if(isImage){
|
if(isImage){
|
||||||
if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
|
if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
|
||||||
XWPFParagraph paragraph = addParagraphContent(mapper.convertValue(field.getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId);
|
XWPFParagraph paragraph = addParagraphContent(mapper.convertValue(field.getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0);
|
||||||
if (paragraph != null) {
|
if (paragraph != null) {
|
||||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
number.setVal(BigInteger.valueOf(indent));
|
// number.setVal(BigInteger.valueOf(indent));
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
}
|
}
|
||||||
if(hasMultiplicityItems){
|
if(hasMultiplicityItems){
|
||||||
|
@ -407,7 +411,7 @@ public class WordBuilder {
|
||||||
String orcId = null;
|
String orcId = null;
|
||||||
if(isResearcher && val.contains("orcid:")){
|
if(isResearcher && val.contains("orcid:")){
|
||||||
orcId = val.substring(val.indexOf(':') + 1, val.indexOf(')'));
|
orcId = val.substring(val.indexOf(':') + 1, val.indexOf(')'));
|
||||||
val = val.substring(0, val.indexOf(':') + 1);
|
val = val.substring(0, val.indexOf(':') + 1) + " ";
|
||||||
orcidResearcher = true;
|
orcidResearcher = true;
|
||||||
}
|
}
|
||||||
format = "• " + val;
|
format = "• " + val;
|
||||||
|
@ -423,7 +427,7 @@ public class WordBuilder {
|
||||||
hasMultiplicityItems = false;
|
hasMultiplicityItems = false;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
|
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
||||||
if(orcidResearcher){
|
if(orcidResearcher){
|
||||||
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
||||||
run.setText(orcId);
|
run.setText(orcId);
|
||||||
|
@ -432,8 +436,8 @@ public class WordBuilder {
|
||||||
paragraph.createRun().setText(")");
|
paragraph.createRun().setText(")");
|
||||||
}
|
}
|
||||||
if (paragraph != null) {
|
if (paragraph != null) {
|
||||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
number.setVal(BigInteger.valueOf(indent));
|
// number.setVal(BigInteger.valueOf(indent));
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -451,10 +455,10 @@ public class WordBuilder {
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
|
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
||||||
if (paragraph != null) {
|
if (paragraph != null) {
|
||||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
number.setVal(BigInteger.valueOf(indent));
|
// number.setVal(BigInteger.valueOf(indent));
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -487,14 +491,16 @@ public class WordBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFParagraph addParagraphContent(Object content, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId) {
|
public XWPFParagraph addParagraphContent(Object content, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId, int indent) {
|
||||||
// this.indent = 0;
|
// this.indent = 0;
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
if (content instanceof String && ((String)content).isEmpty()) {
|
if (content instanceof String && ((String)content).isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
this.indent = indent;
|
||||||
XWPFParagraph paragraph = this.options.get(style).apply(mainDocumentPart, content);
|
XWPFParagraph paragraph = this.options.get(style).apply(mainDocumentPart, content);
|
||||||
if (paragraph != null) {
|
if (paragraph != null) {
|
||||||
|
paragraph.setIndentFromLeft(400*indent);
|
||||||
if (numId != null) {
|
if (numId != null) {
|
||||||
paragraph.setNumID(numId);
|
paragraph.setNumID(numId);
|
||||||
}
|
}
|
||||||
|
@ -511,18 +517,19 @@ public class WordBuilder {
|
||||||
for (int i = 0; i <= indent; i++) {
|
for (int i = 0; i <= indent; i++) {
|
||||||
textLevel += "%" + (i + 1) + ".";
|
textLevel += "%" + (i + 1) + ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (question) {
|
if (question) {
|
||||||
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
|
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
|
||||||
cTLvl.addNewLvlText().setVal("");
|
// cTLvl.addNewLvlText().setVal("");
|
||||||
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
||||||
} else if (!question && hasIndication) {
|
} else if (!question && hasIndication) {
|
||||||
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
|
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
|
||||||
cTLvl.addNewLvlText().setVal("");
|
// cTLvl.addNewLvlText().setVal("");
|
||||||
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
||||||
}
|
}
|
||||||
if (!question && !hasIndication) {
|
if (!question && !hasIndication) {
|
||||||
cTLvl.addNewNumFmt().setVal(STNumberFormat.NONE);
|
cTLvl.addNewNumFmt().setVal(STNumberFormat.NONE);
|
||||||
cTLvl.addNewLvlText().setVal("");
|
// cTLvl.addNewLvlText().setVal("");
|
||||||
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -658,60 +665,112 @@ public class WordBuilder {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillFirstPage(DMP dmpEntity, XWPFDocument document) {
|
public int findPosOfPoweredBy(XWPFDocument document) {
|
||||||
|
for (XWPFParagraph p : document.getParagraphs()) {
|
||||||
|
List<XWPFRun> runs = p.getRuns();
|
||||||
|
if (runs != null) {
|
||||||
|
for (XWPFRun r : runs) {
|
||||||
|
String text = r.getText(0);
|
||||||
|
if (text != null) {
|
||||||
|
if (text.equals("Powered by")) {
|
||||||
|
return document.getPosOfParagraph(p) - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillFirstPage(DMP dmpEntity, Dataset datasetEntity, XWPFDocument document) {
|
||||||
|
int parPos = 0;
|
||||||
|
int descrParPos = -1;
|
||||||
|
XWPFParagraph descrPar = null;
|
||||||
for(XWPFParagraph p: document.getParagraphs()){
|
for(XWPFParagraph p: document.getParagraphs()){
|
||||||
List<XWPFRun> runs = p.getRuns();
|
List<XWPFRun> runs = p.getRuns();
|
||||||
if(runs != null){
|
if(runs != null){
|
||||||
for(XWPFRun r : runs){
|
for(XWPFRun r : runs){
|
||||||
String text = r.getText(0);
|
String text = r.getText(0);
|
||||||
if(text != null){
|
if(text != null){
|
||||||
if(text.contains("{ARGOS.DMP.VERSION}")){
|
if(text.contains("{ARGOS.DMP.TITLE}")) {
|
||||||
text = text.replace("{ARGOS.DMP.VERSION}", "VERSION " + dmpEntity.getVersion());
|
text = text.replace("{ARGOS.DMP.TITLE}", dmpEntity.getLabel());
|
||||||
r.setText(text, 0);
|
r.setText(text, 0);
|
||||||
}
|
} else if(text.contains("{ARGOS.DMP.VERSION}")) {
|
||||||
else if(text.contains("{ARGOS.DMP.FUNDER}")){
|
text = text.replace("{ARGOS.DMP.VERSION}", "Version " + dmpEntity.getVersion());
|
||||||
text = text.replace("{ARGOS.DMP.FUNDER}", dmpEntity.getGrant().getFunder().getLabel());
|
|
||||||
r.setText(text, 0);
|
r.setText(text, 0);
|
||||||
}
|
} else if(datasetEntity != null && text.contains("{ARGOS.DATASET.TITLE}")) {
|
||||||
else if(text.contains("{ARGOS.DMP.GRANT}")){
|
text = text.replace("{ARGOS.DATASET.TITLE}", datasetEntity.getLabel());
|
||||||
text = text.replace("{ARGOS.DMP.GRANT}", dmpEntity.getGrant().getLabel());
|
|
||||||
r.setText(text, 0);
|
r.setText(text, 0);
|
||||||
|
} else if(datasetEntity != null && text.contains("{ARGOS.DATASET.DESCRIPTION}")) {
|
||||||
|
descrParPos = parPos;
|
||||||
|
descrPar = p;
|
||||||
|
text = text.replace("{ARGOS.DATASET.DESCRIPTION}", "");
|
||||||
|
r.setText(text, 0);
|
||||||
|
} else if(text.equals("{ARGOS.DMP.RESEARCHERS}")) {
|
||||||
|
String researchersNames = "";
|
||||||
|
Set<Researcher> researchers = dmpEntity.getResearchers();
|
||||||
|
int i = 0;
|
||||||
|
for(Researcher researcher : researchers){
|
||||||
|
i++;
|
||||||
|
researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : "");
|
||||||
|
}
|
||||||
|
text = text.replace("{ARGOS.DMP.RESEARCHERS}", researchersNames);
|
||||||
|
r.setText(text, 0);
|
||||||
|
r.setFontSize(17);
|
||||||
|
} else if(text.equals("{ARGOS.DMP.ORGANIZATIONS}")) {
|
||||||
|
String organisationsNames = "";
|
||||||
|
Set<Organisation> organisations = dmpEntity.getOrganisations();
|
||||||
|
int i = 0;
|
||||||
|
for(Organisation organisation : organisations){
|
||||||
|
i++;
|
||||||
|
organisationsNames += organisation.getLabel() + (i < organisations.size() ? ", " : "");
|
||||||
|
}
|
||||||
|
text = text.replace("{ARGOS.DMP.ORGANIZATIONS}", organisationsNames);
|
||||||
|
r.setText(text, 0);
|
||||||
|
r.setFontSize(17);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
parPos++;
|
||||||
|
}
|
||||||
|
if(descrParPos != -1 && datasetEntity.getDescription() != null) {
|
||||||
|
XmlCursor cursor = descrPar.getCTP().newCursor();
|
||||||
|
cursor.toNextSibling();
|
||||||
|
Document htmlDoc = Jsoup.parse(((String)datasetEntity.getDescription()).replaceAll("\n", "<br>"));
|
||||||
|
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor);
|
||||||
|
NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
int researchers = dmpEntity.getResearchers().size();
|
|
||||||
int organizations = dmpEntity.getOrganisations().size();
|
|
||||||
if(researchers > 0 || organizations > 0){
|
|
||||||
XWPFTable tbl = document.getTables().get(0);
|
XWPFTable tbl = document.getTables().get(0);
|
||||||
for(int i = (Integer.max(researchers, organizations) - 1); i > 0; i--)
|
|
||||||
tbl.createRow();
|
|
||||||
Iterator<XWPFTableRow> it = tbl.getRows().iterator();
|
Iterator<XWPFTableRow> it = tbl.getRows().iterator();
|
||||||
it.next(); // skip first row
|
it.next(); // skip first row
|
||||||
for(Researcher researcher : dmpEntity.getResearchers()){
|
|
||||||
if(it.hasNext()){
|
if(it.hasNext()){
|
||||||
XWPFRun run = it.next().getCell(0).getParagraphs().get(0).createRun();
|
XWPFParagraph p = it.next().getCell(0).getParagraphs().get(0);
|
||||||
run.setText(researcher.getLabel());
|
XWPFRun run = p.createRun();
|
||||||
|
run.setText(dmpEntity.getGrant().getFunder().getLabel());
|
||||||
run.setFontSize(17);
|
run.setFontSize(17);
|
||||||
}
|
p.setAlignment(ParagraphAlignment.CENTER);
|
||||||
}
|
}
|
||||||
it = tbl.getRows().iterator();
|
it = tbl.getRows().iterator();
|
||||||
it.next();
|
it.next();
|
||||||
for(Organisation organisation : dmpEntity.getOrganisations()){
|
|
||||||
if(it.hasNext()){
|
if(it.hasNext()){
|
||||||
XWPFParagraph p = it.next().getCell(1).getParagraphs().get(0);
|
XWPFParagraph p = it.next().getCell(1).getParagraphs().get(0);
|
||||||
XWPFRun run = p.createRun();
|
XWPFRun run = p.createRun();
|
||||||
run.setText(organisation.getLabel());
|
String text = dmpEntity.getGrant().getLabel();
|
||||||
|
String reference = dmpEntity.getGrant().getReference();
|
||||||
|
if(reference != null) {
|
||||||
|
String[] parts = reference.split("::");
|
||||||
|
text += parts.length > 1 ? "/ No "+parts[parts.length - 1] : "";
|
||||||
|
}
|
||||||
|
run.setText(text);
|
||||||
run.setFontSize(17);
|
run.setFontSize(17);
|
||||||
p.setAlignment(ParagraphAlignment.RIGHT);
|
p.setAlignment(ParagraphAlignment.CENTER);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillFooter(DMP dmpEntity, XWPFDocument document) {
|
public void fillFooter(DMP dmpEntity, XWPFDocument document, boolean isDataset) {
|
||||||
document.getFooterList().forEach(xwpfFooter -> {
|
document.getFooterList().forEach(xwpfFooter -> {
|
||||||
List<XWPFRun> runs = xwpfFooter.getParagraphs().get(0).getRuns();
|
List<XWPFRun> runs = xwpfFooter.getParagraphs().get(0).getRuns();
|
||||||
if(runs != null){
|
if(runs != null){
|
||||||
|
|
|
@ -25,6 +25,7 @@ pdf.converter.url=http://localhost:3000/
|
||||||
configuration.externalUrls=externalUrls/ExternalUrls.xml
|
configuration.externalUrls=externalUrls/ExternalUrls.xml
|
||||||
configuration.rda=RDACommonStandards.txt
|
configuration.rda=RDACommonStandards.txt
|
||||||
configuration.h2020template=documents/h2020.docx
|
configuration.h2020template=documents/h2020.docx
|
||||||
|
configuration.h2020datasettemplate=documents/h2020_dataset.docx
|
||||||
configuration.configurable_login_providers=configurableLoginProviders.json
|
configuration.configurable_login_providers=configurableLoginProviders.json
|
||||||
configuration.doi_funder=DOI_Funder.json
|
configuration.doi_funder=DOI_Funder.json
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ pdf.converter.url=http://docsbox-web/
|
||||||
configuration.externalUrls=externalUrls/ExternalUrls.xml
|
configuration.externalUrls=externalUrls/ExternalUrls.xml
|
||||||
configuration.rda=RDACommonStandards.txt
|
configuration.rda=RDACommonStandards.txt
|
||||||
configuration.h2020template=documents/h2020.docx
|
configuration.h2020template=documents/h2020.docx
|
||||||
|
configuration.h2020datasettemplate=documents/h2020_dataset.docx
|
||||||
configuration.configurable_login_providers=ConfigurableLoginProviders.json
|
configuration.configurable_login_providers=ConfigurableLoginProviders.json
|
||||||
configuration.doi_funder=DOI_Funder.json
|
configuration.doi_funder=DOI_Funder.json
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ pdf.converter.url=http://docsbox-web/
|
||||||
configuration.externalUrls=externalUrls/ExternalUrls.xml
|
configuration.externalUrls=externalUrls/ExternalUrls.xml
|
||||||
configuration.rda=RDACommonStandards.txt
|
configuration.rda=RDACommonStandards.txt
|
||||||
configuration.h2020template=documents/h2020.docx
|
configuration.h2020template=documents/h2020.docx
|
||||||
|
configuration.h2020datasettemplate=documents/h2020_dataset.docx
|
||||||
configuration.configurable_login_providers=ConfigurableLoginProviders.json
|
configuration.configurable_login_providers=ConfigurableLoginProviders.json
|
||||||
configuration.doi_funder=DOI_Funder.json
|
configuration.doi_funder=DOI_Funder.json
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ elasticsearch.certKey=
|
||||||
configuration.externalUrls=externalUrls/ExternalUrls.xml
|
configuration.externalUrls=externalUrls/ExternalUrls.xml
|
||||||
configuration.rda=RDACommonStandards.txt
|
configuration.rda=RDACommonStandards.txt
|
||||||
configuration.h2020template=documents/h2020.docx
|
configuration.h2020template=documents/h2020.docx
|
||||||
|
configuration.h2020datasettemplate=documents/h2020_dataset.docx
|
||||||
configuration.configurable_login_providers=ConfigurableLoginProviders.json
|
configuration.configurable_login_providers=ConfigurableLoginProviders.json
|
||||||
configuration.doi_funder=DOI_Funder.json
|
configuration.doi_funder=DOI_Funder.json
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue