Search in sources :

Example 51 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project poi by apache.

the class XSLFSheet method commit.

protected final void commit() throws IOException {
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    String docName = getRootElementName();
    if (docName != null) {
        xmlOptions.setSaveSyntheticDocumentElement(new QName("http://schemas.openxmlformats.org/presentationml/2006/main", docName));
    }
    PackagePart part = getPackagePart();
    OutputStream out = part.getOutputStream();
    getXmlObject().save(out, xmlOptions);
    out.close();
}
Also used : QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) OutputStream(java.io.OutputStream) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 52 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project mdw-designer by CenturyLinkCloud.

the class TaskTemplateEditor method saveDialog.

private int saveDialog(boolean closeButton) {
    VersionableSaveDialog saveDlg = new VersionableSaveDialog(getSite().getShell(), taskTemplate, closeButton);
    int result = saveDlg.open();
    if (result == VersionableSaveDialog.CANCEL)
        return result;
    try {
        if (result == VersionableSaveDialog.CLOSE_WITHOUT_SAVE) {
            // refresh from file
            String content = new String(PluginUtil.readFile(taskTemplate.getFile()));
            TaskVO taskVO;
            if (content.trim().startsWith("{")) {
                taskVO = new TaskVO(new JSONObject(content));
            } else {
                TaskTemplateDocument docx = TaskTemplateDocument.Factory.parse(content);
                taskVO = new TaskVO(docx.getTaskTemplate());
            }
            taskVO.setName(taskTemplate.getName());
            taskVO.setTaskId(taskTemplate.getId());
            taskVO.setPackageName(taskTemplate.getPackage().getName());
            taskTemplate.setTaskVO(taskVO);
            taskTemplate.setDirty(false);
            return result;
        } else // save the template
        {
            // clean out units attrs
            taskTemplate.removeAttribute("TaskSLA_UNITS");
            taskTemplate.removeAttribute("ALERT_INTERVAL_UNITS");
            Increment versionIncrement = saveDlg.getVersionIncrement();
            String pkgMeta = taskTemplate.getPackage().getMetaContent();
            if (pkgMeta != null && pkgMeta.trim().startsWith("{")) {
                taskTemplate.setContent(taskTemplate.getTaskVO().getJson().toString(2));
            } else {
                TaskTemplateDocument doc = TaskTemplateDocument.Factory.newInstance();
                doc.setTaskTemplate(taskTemplate.getTaskVO().toTemplate());
                XmlOptions xmlOptions = new XmlOptions().setSaveAggressiveNamespaces();
                xmlOptions.setSavePrettyPrint().setSavePrettyPrintIndent(2);
                taskTemplate.setContent(doc.xmlText(xmlOptions));
            }
            taskTemplate.ensureFileWritable();
            InputStream is = new ByteArrayInputStream(taskTemplate.getContent().getBytes());
            taskTemplate.getAssetFile().setContents(is, true, true, new NullProgressMonitor());
            if (versionIncrement != Increment.Overwrite) {
                taskTemplate.setVersion(versionIncrement == Increment.Major ? taskTemplate.getNextMajorVersion() : taskTemplate.getNextMinorVersion());
                taskTemplate.setRevisionComment(saveDlg.getVersionComment());
                taskTemplate.getProject().getDesignerProxy().saveWorkflowAssetWithProgress(taskTemplate, false);
                taskTemplate.fireElementChangeEvent(ChangeType.VERSION_CHANGE, taskTemplate.getVersion());
            }
            dirtyStateChanged(false);
            if (!taskTemplate.getProject().isRemote())
                taskTemplate.getProject().getDesignerProxy().getCacheRefresh().fireRefresh(false);
            return result;
        }
    } catch (Exception ex) {
        PluginMessages.uiError(getSite().getShell(), ex, "Save Task Template", taskTemplate.getProject());
        return VersionableSaveDialog.CANCEL;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TaskTemplateDocument(com.centurylink.mdw.task.TaskTemplateDocument) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionableSaveDialog(com.centurylink.mdw.plugin.designer.dialogs.VersionableSaveDialog) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Increment(com.centurylink.mdw.plugin.designer.model.Versionable.Increment) XmlOptions(org.apache.xmlbeans.XmlOptions) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) JSONException(org.json.JSONException) PartInitException(org.eclipse.ui.PartInitException)

Example 53 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project mdw-designer by CenturyLinkCloud.

the class CustomTaskManager method updateApplicationXml.

private void updateApplicationXml(WorkflowProject project, String webUri, String contextRoot, IProgressMonitor monitor) throws XmlException, CoreException, IOException {
    monitor.subTask("Update application deployment descriptor");
    String namespace = "http://java.sun.com/xml/ns/j2ee";
    QName id = new QName("id");
    String errorMsg = "Update failed for EAR content META-INF/application.xml.";
    XmlCursor xmlCursor = null;
    try {
        IFile appXmlFile = project.getEarContentFolder().getFile("META-INF/application.xml");
        XmlObject xmlBean = XmlObject.Factory.parse(appXmlFile.getContents());
        xmlCursor = xmlBean.newCursor();
        // document
        xmlCursor.toChild(0);
        if (!xmlCursor.toChild(namespace, "module")) {
            namespace = "http://java.sun.com/xml/ns/javaee";
            xmlCursor.toChild(namespace, "module");
        }
        boolean found = true;
        while (found && !"MDWTaskManagerWeb".equals(xmlCursor.getAttributeText(id))) found = xmlCursor.toNextSibling(namespace, "module");
        if (!found)
            throw new XmlException(errorMsg + "\nNo 'module' element found with id='MDWTaskManagerWeb'");
        if (!xmlCursor.toChild(namespace, "web"))
            throw new XmlException(errorMsg + "\nMissing 'web' subelement under module 'MDWTaskManagerWeb'");
        if (!xmlCursor.toChild(namespace, "web-uri"))
            throw new XmlException(errorMsg + "\nMissing 'web-uri' subelement under module 'MDWTaskManagerWeb'");
        xmlCursor.setTextValue(webUri);
        xmlCursor.toParent();
        if (!xmlCursor.toChild(namespace, "context-root"))
            throw new XmlException(errorMsg + "\nMissing 'context-root' subelement under module 'MDWTaskManagerWeb'");
        xmlCursor.setTextValue(contextRoot);
        XmlOptions xmlOptions = new XmlOptions();
        xmlOptions.setUseDefaultNamespace();
        PluginUtil.writeFile(appXmlFile, xmlBean.xmlText(xmlOptions), monitor);
    } finally {
        if (xmlCursor != null)
            xmlCursor.dispose();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) QName(javax.xml.namespace.QName) XmlException(org.apache.xmlbeans.XmlException) XmlOptions(org.apache.xmlbeans.XmlOptions) XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 54 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project mdw-designer by CenturyLinkCloud.

the class DesignerCompatibility method getOldProcessDefinition.

public String getOldProcessDefinition(String pkgDefXML) throws XmlException {
    // reparse with reverse namespaces
    XmlOptions reverseOpts = Compatibility.getReverseNamespaceOptions();
    com.qwest.mdw.xmlSchema.ProcessDefinitionDocument oldDoc = com.qwest.mdw.xmlSchema.ProcessDefinitionDocument.Factory.parse(pkgDefXML, reverseOpts);
    XmlOptions printOpts = new XmlOptions().setSavePrettyPrint().setSavePrettyPrintIndent(2);
    return oldDoc.xmlText(printOpts);
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions)

Example 55 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project mdw-designer by CenturyLinkCloud.

the class DesignerCompatibility method getOldProcessDefinition.

public String getOldProcessDefinition(ProcessDefinitionDocument procDefDoc) throws XmlException {
    // reparse with reverse namespaces
    XmlOptions reverseOpts = Compatibility.getReverseNamespaceOptions();
    com.qwest.mdw.xmlSchema.ProcessDefinitionDocument oldDoc = com.qwest.mdw.xmlSchema.ProcessDefinitionDocument.Factory.parse(procDefDoc.xmlText(), reverseOpts);
    XmlOptions printOpts = new XmlOptions().setSavePrettyPrint().setSavePrettyPrintIndent(2);
    return oldDoc.xmlText(printOpts);
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions)

Aggregations

XmlOptions (org.apache.xmlbeans.XmlOptions)63 QName (javax.xml.namespace.QName)20 OutputStream (java.io.OutputStream)18 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)17 ArrayList (java.util.ArrayList)12 XmlError (org.apache.xmlbeans.XmlError)11 XmlException (org.apache.xmlbeans.XmlException)11 IOException (java.io.IOException)9 Beta (org.apache.poi.util.Beta)7 Before (org.junit.Before)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 XmlObject (org.apache.xmlbeans.XmlObject)4 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)3 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)3 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)3 EncodingException (org.n52.svalbard.encode.exception.EncodingException)3 MDWProcessDefinition (com.centurylink.mdw.bpm.MDWProcessDefinition)2 ProcessDefinitionDocument (com.centurylink.mdw.bpm.ProcessDefinitionDocument)2 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)2 Attribute (com.centurylink.mdw.task.Attribute)2