Search in sources :

Example 6 with OdfDocument

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);
    }
}
Also used : OdfDocument(org.odftoolkit.odfdom.doc.OdfDocument) FrameworkException(org.structr.common.error.FrameworkException) SecurityContext(org.structr.common.SecurityContext) File(org.structr.web.entity.File) FrameworkException(org.structr.common.error.FrameworkException)

Aggregations

OdfDocument (org.odftoolkit.odfdom.doc.OdfDocument)6 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 OdfTable (org.odftoolkit.odfdom.doc.table.OdfTable)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Cell (com.google.refine.model.Cell)2 Recon (com.google.refine.model.Recon)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONObject (org.json.JSONObject)2 OdfTableCell (org.odftoolkit.odfdom.doc.table.OdfTableCell)2 OdfTableRow (org.odftoolkit.odfdom.doc.table.OdfTableRow)2 FrameworkException (org.structr.common.error.FrameworkException)2 File (org.structr.web.entity.File)2 URI (java.net.URI)1