use of org.apache.xmlbeans.XmlOptions in project mdw-designer by CenturyLinkCloud.
the class NewTaskTemplateWizard method performFinish.
@Override
public boolean performFinish() {
TaskTemplate taskTemplate = (TaskTemplate) getWorkflowAsset();
try {
TaskTemplateDocument doc;
if (isImportFile()) {
// load from selected file
doc = TaskTemplateDocument.Factory.parse(new File(getImportFilePath()));
com.centurylink.mdw.task.TaskTemplate template = doc.getTaskTemplate();
// selection)
if (template.getLogicalId() == null)
throw new XmlException("Task template missing logicalId");
else if (template.getCategory() == null)
throw new XmlException("Task template missing category");
else if (template.getName() == null || template.getName().isEmpty())
throw new XmlException("Task template missing name");
} else {
doc = TaskTemplateDocument.Factory.newInstance();
com.centurylink.mdw.task.TaskTemplate template = doc.addNewTaskTemplate();
String taskName = taskTemplate.getName().substring(0, taskTemplate.getName().length() - 5);
template.setLogicalId(taskName.replace(' ', '_'));
template.setCategory("GEN");
template.setName(taskName);
if ("AUTOFORM".equals(taskTemplate.getLanguage())) {
Attribute form = template.addNewAttribute();
form.setName("FormName");
form.setStringValue("Autoform");
}
}
XmlOptions xmlOptions = new XmlOptions().setSaveAggressiveNamespaces();
xmlOptions.setSavePrettyPrint().setSavePrettyPrintIndent(2);
taskTemplate.setContent(doc.xmlText(xmlOptions));
String templateName = taskTemplate.getName();
taskTemplate.setTaskVO(new TaskVO(doc.getTaskTemplate()));
taskTemplate.setName(templateName);
taskTemplate.getTaskVO().setPackageName(taskTemplate.getPackage().getName());
DesignerProxy designerProxy = taskTemplate.getProject().getDesignerProxy();
designerProxy.createNewTaskTemplate(taskTemplate);
if (designerProxy.getRunnerStatus().equals(RunnerStatus.SUCCESS)) {
taskTemplate.openFile(new NullProgressMonitor());
taskTemplate.addElementChangeListener(taskTemplate.getProject());
taskTemplate.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, taskTemplate);
taskTemplate.setVersion(1);
taskTemplate.fireElementChangeEvent(ChangeType.VERSION_CHANGE, taskTemplate);
DesignerPerspective.promptForShowPerspective(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), taskTemplate);
return true;
} else {
return false;
}
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "Create " + taskTemplate.getTitle(), taskTemplate.getProject());
return false;
}
}
use of org.apache.xmlbeans.XmlOptions in project knime-core by knime.
the class PMMLValidator method validatePMML.
/**
* Validates a document against the schema and returns the number of
* errors found.
*
* @param pmmlDocument the PMMML document
* @return the error message or an em
*/
public static Map<String, String> validatePMML(final PMMLDocument pmmlDocument) {
XmlOptions validateOptions = new XmlOptions();
List<XmlError> errorList = new ArrayList<XmlError>();
validateOptions.setErrorListener(errorList);
pmmlDocument.validate(validateOptions);
Map<String, String> errorMessages = new TreeMap<String, String>();
for (XmlError error : errorList) {
String location = error.getCursorLocation().xmlText();
if (location.length() > 50) {
location = location.substring(0, 50) + "[...]";
}
String errorMessage = error.getMessage().replace(PMML_NAMESPACE_URI, "");
LOGGER.error(location + ": " + errorMessage);
errorMessages.put(location, errorMessage);
}
return errorMessages;
}
use of org.apache.xmlbeans.XmlOptions in project knime-core by knime.
the class NodeDescriptionUtil method getPrettyXmlText.
/**
* Obtain a String representation of the children of the given XML object. Intended for pretty-printing contents of
* nodes that resemble HTML-formatted text. Strip comments, namespace prefixes and namespace attributes.
* If the given String is {@code null}, the method returns {@code null}.
*
* @param obj the XML object whose child nodes should be printed to a String
* @return a string representation of the nodes children, or null if {@code obj} is null.
*/
public static String getPrettyXmlText(final XmlObject obj) {
if (obj == null) {
return null;
}
var xmlOptions = // strip comments
new XmlOptions().setLoadStripComments().setLoadStripProcinsts();
var writer = new StringWriter();
try {
REMOVE_NAMESPACES_TRANSFORMER.get().transform(new StreamSource(obj.newReader(xmlOptions)), new StreamResult(writer));
} catch (TransformerException | ConcurrentException e) {
NodeLogger.getLogger(NodeDescriptionUtil.class).error("Could not format text, reason: " + e.getMessage(), e);
e.printStackTrace();
}
var s = writer.toString();
// On Windows, the transformer produces CRLF (\r\n) line endings, on Unix only LF (\n)
if (Platform.OS_WIN32.equals(Platform.getOS())) {
s = CRLF.matcher(s).replaceAll("\n");
}
return NodeDescriptionUtil.stripXmlFragment(s);
}
use of org.apache.xmlbeans.XmlOptions in project knime-core by knime.
the class NodeDescription13Proxy method validate.
/**
* Validate against the XML Schema. If violations are found they are reported via the logger as coding problems.
*
* @return <code>true</code> if the document is valid, <code>false</code> otherwise
*/
final boolean validate() {
// this method has default visibility so that we can use it in testcases
XmlOptions options = new XmlOptions(OPTIONS);
List<XmlError> errors = new ArrayList<XmlError>();
options.setErrorListener(errors);
boolean valid = m_document.validate(options);
if (!valid) {
logger.coding("Node description of '" + m_document.getKnimeNode().getName() + "' does not conform to the Schema. Violations follow.");
for (XmlError err : errors) {
logger.coding(err.toString());
}
}
return valid;
}
use of org.apache.xmlbeans.XmlOptions in project knime-core by knime.
the class NodeDescription28Proxy method validate.
/**
* Validate against the XML Schema. If violations are found they are reported via the logger as coding problems.
*
* @return <code>true</code> if the document is valid, <code>false</code> otherwise
*/
protected final boolean validate() {
// this method has default visibility so that we can use it in testcases
XmlOptions options = new XmlOptions(OPTIONS);
List<XmlError> errors = new ArrayList<XmlError>();
options.setErrorListener(errors);
boolean valid = m_document.validate(options);
if (!valid) {
logger.coding("Node description of '" + m_document.getKnimeNode().getName() + "' does not conform to the Schema. Violations follow.");
for (XmlError err : errors) {
logger.coding(err.toString());
}
}
return valid;
}
Aggregations