use of org.odftoolkit.odfdom.doc.OdfDocument in project structr by structr.
the class ODFExporter method createDocumentFromTemplate.
/*
static final Logger logger = LoggerFactory.getLogger(ODTExporter.class.getName());
public static final Property<VirtualType> transformationProvider = new EndNode("transformationProvider", TransformationRules.class);
public static final Property<File> documentTemplate = new EndNode("documentTemplate", DocumentTemplate.class);
public static final Property<File> resultDocument = new EndNode("resultDocument", DocumentResult.class);
public static final View defaultView = new View(ODTExporter.class, PropertyView.Public, id, type, transformationProvider, documentTemplate, resultDocument);
public static final View uiView = new View(ODTExporter.class, PropertyView.Ui,
id, name, owner, type, createdBy, deleted, hidden, createdDate, lastModifiedDate, visibleToPublicUsers, visibleToAuthenticatedUsers, visibilityStartDate, visibilityEndDate,
transformationProvider, documentTemplate, resultDocument
);
*/
public static void createDocumentFromTemplate(final ODFExporter thisNode) throws FrameworkException {
final SecurityContext securityContext = thisNode.getSecurityContext();
final File template = thisNode.getDocumentTemplate();
File output = thisNode.getResultDocument();
OdfDocument templateOdt;
try {
if (template == null) {
throw new FrameworkException(422, "Template not set");
}
// If no result file is given, create one and set it as result document
if (output == null) {
output = FileHelper.createFile(securityContext, new byte[] {}, template.getContentType(), File.class, thisNode.getName().concat("_").concat(template.getName()));
output.setParent(template.getParent());
output.unlockSystemPropertiesOnce();
output.setProperty(AbstractNode.type, File.class.getSimpleName());
thisNode.setResultDocument(output);
}
templateOdt = OdfDocument.loadDocument(template.getFileOnDisk().getAbsolutePath());
templateOdt.save(output.getOutputStream());
templateOdt.close();
} catch (Exception e) {
logger.error("Error while creating ODS from template", e);
}
}
Aggregations