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();
}
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;
}
}
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();
}
}
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);
}
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);
}
Aggregations