List of usage examples for javax.xml.stream XMLStreamWriter writeCharacters
public void writeCharacters(String text) throws XMLStreamException;
From source file:org.exoplatform.services.jcr.ext.artifact.ArtifactManagingServiceImpl.java
protected File createSingleMetadata(String groupId, String artifactId, String version) throws FileNotFoundException { File temp = null;// ww w . j ava2 s . co m try { String filename = getUniqueFilename("maven-metadata.xml"); temp = File.createTempFile(filename, null); OutputStream os = new FileOutputStream(temp); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(os); try { writer.writeStartDocument("UTF-8", "1.0"); writer.writeStartElement("metadata"); writer.writeStartElement("groupId"); writer.writeCharacters(groupId); writer.writeEndElement(); writer.writeStartElement("artifactId"); writer.writeCharacters(artifactId); writer.writeEndElement(); writer.writeStartElement("version"); writer.writeCharacters(version); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndDocument(); } finally { writer.flush(); writer.close(); os.close(); } } catch (XMLStreamException e) { LOG.error("Error on creating metadata - XML", e); } catch (IOException e) { LOG.error("Error on creating metadata - FILE", e); } return (temp != null && temp.exists()) ? temp : null; }
From source file:org.exoplatform.services.jcr.ext.artifact.ArtifactManagingServiceImpl.java
protected File createMultiMetadata(String groupId, String artifactId, String current_version, List<String> v_list) throws FileNotFoundException { File temp = null;/*from ww w . j a v a 2s . com*/ try { String filename = getUniqueFilename("maven-metadata.xml"); temp = File.createTempFile(filename, null); OutputStream os = new FileOutputStream(temp); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(os); try { writer.writeStartDocument("UTF-8", "1.0"); writer.writeStartElement("metadata"); writer.writeStartElement("groupId"); writer.writeCharacters(groupId); writer.writeEndElement(); writer.writeStartElement("artifactId"); writer.writeCharacters(artifactId); writer.writeEndElement(); String elderVersion; if (v_list.size() > 0) { Collections.sort(v_list); // sort list elderVersion = v_list.get(0); // get first element } else elderVersion = current_version; v_list.add(current_version); writer.writeStartElement("version"); writer.writeCharacters(elderVersion); writer.writeEndElement(); writer.writeStartElement("versions"); writer.writeStartElement("versioning"); for (Iterator<String> iterator = v_list.iterator(); iterator.hasNext();) { writer.writeStartElement("version"); writer.writeCharacters(iterator.next()); writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndDocument(); } finally { writer.flush(); writer.close(); os.close(); } } catch (XMLStreamException e) { LOG.error("Error on creating metadata - XML", e); } catch (IOException e) { LOG.error("Error on creating metadata - FILE", e); } return (temp != null && temp.exists()) ? temp : null; }
From source file:org.flowable.bpmn.converter.BaseBpmnXMLConverter.java
public void convertToXML(XMLStreamWriter xtw, BaseElement baseElement, BpmnModel model) throws Exception { xtw.writeStartElement(getXMLElementName()); boolean didWriteExtensionStartElement = false; writeDefaultAttribute(ATTRIBUTE_ID, baseElement.getId(), xtw); if (baseElement instanceof FlowElement) { writeDefaultAttribute(ATTRIBUTE_NAME, ((FlowElement) baseElement).getName(), xtw); }// w w w .j a v a 2s .c o m if (baseElement instanceof FlowNode) { final FlowNode flowNode = (FlowNode) baseElement; if (flowNode.isAsynchronous()) { writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw); if (flowNode.isNotExclusive()) { writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw); } } if (baseElement instanceof Activity) { final Activity activity = (Activity) baseElement; if (activity.isForCompensation()) { writeDefaultAttribute(ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION, ATTRIBUTE_VALUE_TRUE, xtw); } if (StringUtils.isNotEmpty(activity.getDefaultFlow())) { FlowElement defaultFlowElement = model.getFlowElement(activity.getDefaultFlow()); if (defaultFlowElement instanceof SequenceFlow) { writeDefaultAttribute(ATTRIBUTE_DEFAULT, activity.getDefaultFlow(), xtw); } } } if (baseElement instanceof Gateway) { final Gateway gateway = (Gateway) baseElement; if (StringUtils.isNotEmpty(gateway.getDefaultFlow())) { FlowElement defaultFlowElement = model.getFlowElement(gateway.getDefaultFlow()); if (defaultFlowElement instanceof SequenceFlow) { writeDefaultAttribute(ATTRIBUTE_DEFAULT, gateway.getDefaultFlow(), xtw); } } } } writeAdditionalAttributes(baseElement, model, xtw); if (baseElement instanceof FlowElement) { final FlowElement flowElement = (FlowElement) baseElement; if (StringUtils.isNotEmpty(flowElement.getDocumentation())) { xtw.writeStartElement(ELEMENT_DOCUMENTATION); xtw.writeCharacters(flowElement.getDocumentation()); xtw.writeEndElement(); } } didWriteExtensionStartElement = writeExtensionChildElements(baseElement, didWriteExtensionStartElement, xtw); didWriteExtensionStartElement = writeListeners(baseElement, didWriteExtensionStartElement, xtw); didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(baseElement, didWriteExtensionStartElement, model.getNamespaces(), xtw); if (baseElement instanceof Activity) { final Activity activity = (Activity) baseElement; FailedJobRetryCountExport.writeFailedJobRetryCount(activity, xtw); } if (didWriteExtensionStartElement) { xtw.writeEndElement(); } if (baseElement instanceof Activity) { final Activity activity = (Activity) baseElement; MultiInstanceExport.writeMultiInstance(activity, xtw); } writeAdditionalChildElements(baseElement, model, xtw); xtw.writeEndElement(); }
From source file:org.flowable.bpmn.converter.BaseBpmnXMLConverter.java
protected void writeTimerDefinition(Event parentEvent, TimerEventDefinition timerDefinition, XMLStreamWriter xtw) throws Exception { xtw.writeStartElement(ELEMENT_EVENT_TIMERDEFINITION); if (StringUtils.isNotEmpty(timerDefinition.getCalendarName())) { writeQualifiedAttribute(ATTRIBUTE_CALENDAR_NAME, timerDefinition.getCalendarName(), xtw); }//from ww w .j a v a 2 s .c om boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(timerDefinition, false, xtw); if (didWriteExtensionStartElement) { xtw.writeEndElement(); } if (StringUtils.isNotEmpty(timerDefinition.getTimeDate())) { xtw.writeStartElement(ATTRIBUTE_TIMER_DATE); xtw.writeCharacters(timerDefinition.getTimeDate()); xtw.writeEndElement(); } else if (StringUtils.isNotEmpty(timerDefinition.getTimeCycle())) { xtw.writeStartElement(ATTRIBUTE_TIMER_CYCLE); if (StringUtils.isNotEmpty(timerDefinition.getEndDate())) { xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE, ATTRIBUTE_END_DATE, timerDefinition.getEndDate()); } xtw.writeCharacters(timerDefinition.getTimeCycle()); xtw.writeEndElement(); } else if (StringUtils.isNotEmpty(timerDefinition.getTimeDuration())) { xtw.writeStartElement(ATTRIBUTE_TIMER_DURATION); xtw.writeCharacters(timerDefinition.getTimeDuration()); xtw.writeEndElement(); } xtw.writeEndElement(); }
From source file:org.flowable.bpmn.converter.BpmnXMLConverter.java
protected void createXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw) throws Exception { if (flowElement instanceof SubProcess) { SubProcess subProcess = (SubProcess) flowElement; if (flowElement instanceof Transaction) { xtw.writeStartElement(ELEMENT_TRANSACTION); } else if (flowElement instanceof AdhocSubProcess) { xtw.writeStartElement(ELEMENT_ADHOC_SUBPROCESS); } else {//ww w .j a va2 s. c o m xtw.writeStartElement(ELEMENT_SUBPROCESS); } xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId()); if (StringUtils.isNotEmpty(subProcess.getName())) { xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName()); } else { xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess"); } if (subProcess instanceof EventSubProcess) { xtw.writeAttribute(ATTRIBUTE_TRIGGERED_BY, ATTRIBUTE_VALUE_TRUE); } else if (subProcess instanceof Transaction == false) { if (subProcess.isAsynchronous()) { BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw); if (subProcess.isNotExclusive()) { BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw); } } } else if (subProcess instanceof AdhocSubProcess) { AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess; BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_CANCEL_REMAINING_INSTANCES, String.valueOf(adhocSubProcess.isCancelRemainingInstances()), xtw); if (StringUtils.isNotEmpty(adhocSubProcess.getOrdering())) { BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_ORDERING, adhocSubProcess.getOrdering(), xtw); } } if (StringUtils.isNotEmpty(subProcess.getDocumentation())) { xtw.writeStartElement(ELEMENT_DOCUMENTATION); xtw.writeCharacters(subProcess.getDocumentation()); xtw.writeEndElement(); } boolean didWriteExtensionStartElement = FlowableListenerExport.writeListeners(subProcess, false, xtw); didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(subProcess, didWriteExtensionStartElement, model.getNamespaces(), xtw); if (didWriteExtensionStartElement) { // closing extensions element xtw.writeEndElement(); } MultiInstanceExport.writeMultiInstance(subProcess, xtw); if (subProcess instanceof AdhocSubProcess) { AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess; if (StringUtils.isNotEmpty(adhocSubProcess.getCompletionCondition())) { xtw.writeStartElement(ELEMENT_COMPLETION_CONDITION); xtw.writeCData(adhocSubProcess.getCompletionCondition()); xtw.writeEndElement(); } } for (FlowElement subElement : subProcess.getFlowElements()) { createXML(subElement, model, xtw); } for (Artifact artifact : subProcess.getArtifacts()) { createXML(artifact, model, xtw); } xtw.writeEndElement(); } else { BaseBpmnXMLConverter converter = convertersToXMLMap.get(flowElement.getClass()); if (converter == null) { throw new XMLException("No converter for " + flowElement.getClass() + " found"); } converter.convertToXML(xtw, flowElement, model); } }
From source file:org.flowable.bpmn.converter.export.FailedJobRetryCountExport.java
public static void writeFailedJobRetryCount(Activity activity, XMLStreamWriter xtw) throws Exception { String failedJobRetryCycle = activity.getFailedJobRetryTimeCycleValue(); if (failedJobRetryCycle != null) { if (StringUtils.isNotEmpty(failedJobRetryCycle)) { xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, FAILED_JOB_RETRY_TIME_CYCLE, FLOWABLE_EXTENSIONS_NAMESPACE); xtw.writeCharacters(failedJobRetryCycle); xtw.writeEndElement();/*from ww w. j a va2 s . c om*/ } } }
From source file:org.flowable.bpmn.converter.export.LaneExport.java
public static void writeLanes(Process process, XMLStreamWriter xtw) throws Exception { if (!process.getLanes().isEmpty()) { xtw.writeStartElement(ELEMENT_LANESET); xtw.writeAttribute(ATTRIBUTE_ID, "laneSet_" + process.getId()); for (Lane lane : process.getLanes()) { xtw.writeStartElement(ELEMENT_LANE); xtw.writeAttribute(ATTRIBUTE_ID, lane.getId()); if (StringUtils.isNotEmpty(lane.getName())) { xtw.writeAttribute(ATTRIBUTE_NAME, lane.getName()); }//from w ww . j ava 2s.c om boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(lane, false, xtw); if (didWriteExtensionStartElement) { xtw.writeEndElement(); } for (String flowNodeRef : lane.getFlowReferences()) { xtw.writeStartElement(ELEMENT_FLOWNODE_REF); xtw.writeCharacters(flowNodeRef); xtw.writeEndElement(); } xtw.writeEndElement(); } xtw.writeEndElement(); } }
From source file:org.flowable.bpmn.converter.export.ProcessExport.java
@SuppressWarnings("unchecked") public static void writeProcess(Process process, XMLStreamWriter xtw) throws Exception { // start process element xtw.writeStartElement(ELEMENT_PROCESS); xtw.writeAttribute(ATTRIBUTE_ID, process.getId()); if (StringUtils.isNotEmpty(process.getName())) { xtw.writeAttribute(ATTRIBUTE_NAME, process.getName()); }/*ww w . jav a 2 s .com*/ xtw.writeAttribute(ATTRIBUTE_PROCESS_EXECUTABLE, Boolean.toString(process.isExecutable())); if (!process.getCandidateStarterUsers().isEmpty()) { xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE, ATTRIBUTE_PROCESS_CANDIDATE_USERS, BpmnXMLUtil.convertToDelimitedString(process.getCandidateStarterUsers())); } if (!process.getCandidateStarterGroups().isEmpty()) { xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE, ATTRIBUTE_PROCESS_CANDIDATE_GROUPS, BpmnXMLUtil.convertToDelimitedString(process.getCandidateStarterGroups())); } // write custom attributes BpmnXMLUtil.writeCustomAttributes(process.getAttributes().values(), xtw, defaultProcessAttributes); if (StringUtils.isNotEmpty(process.getDocumentation())) { xtw.writeStartElement(ELEMENT_DOCUMENTATION); xtw.writeCharacters(process.getDocumentation()); xtw.writeEndElement(); } boolean didWriteExtensionStartElement = FlowableListenerExport.writeListeners(process, false, xtw); didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(process, didWriteExtensionStartElement, xtw); if (didWriteExtensionStartElement) { // closing extensions element xtw.writeEndElement(); } LaneExport.writeLanes(process, xtw); }
From source file:org.flowable.bpmn.converter.ServiceTaskXMLConverter.java
@Override protected boolean writeExtensionChildElements(BaseElement element, boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception { ServiceTask serviceTask = (ServiceTask) element; if (!serviceTask.getCustomProperties().isEmpty()) { for (CustomProperty customProperty : serviceTask.getCustomProperties()) { if (StringUtils.isEmpty(customProperty.getSimpleValue())) { continue; }/* ww w. ja va 2 s.co m*/ if (didWriteExtensionStartElement == false) { xtw.writeStartElement(ELEMENT_EXTENSIONS); didWriteExtensionStartElement = true; } xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ELEMENT_FIELD, FLOWABLE_EXTENSIONS_NAMESPACE); xtw.writeAttribute(ATTRIBUTE_FIELD_NAME, customProperty.getName()); if ((customProperty.getSimpleValue().contains("${") || customProperty.getSimpleValue().contains("#{")) && customProperty.getSimpleValue().contains("}")) { xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ATTRIBUTE_FIELD_EXPRESSION, FLOWABLE_EXTENSIONS_NAMESPACE); } else { xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ELEMENT_FIELD_STRING, FLOWABLE_EXTENSIONS_NAMESPACE); } xtw.writeCharacters(customProperty.getSimpleValue()); xtw.writeEndElement(); xtw.writeEndElement(); } } else { didWriteExtensionStartElement = FieldExtensionExport .writeFieldExtensions(serviceTask.getFieldExtensions(), didWriteExtensionStartElement, xtw); } return didWriteExtensionStartElement; }
From source file:org.flowable.bpmn.converter.UserTaskXMLConverter.java
@Override protected boolean writeExtensionChildElements(BaseElement element, boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception { UserTask userTask = (UserTask) element; didWriteExtensionStartElement = writeFormProperties(userTask, didWriteExtensionStartElement, xtw); didWriteExtensionStartElement = writeCustomIdentities(element, didWriteExtensionStartElement, xtw); if (!userTask.getCustomProperties().isEmpty()) { for (CustomProperty customProperty : userTask.getCustomProperties()) { if (StringUtils.isEmpty(customProperty.getSimpleValue())) { continue; }//from ww w . jav a 2 s . co m if (didWriteExtensionStartElement == false) { xtw.writeStartElement(ELEMENT_EXTENSIONS); didWriteExtensionStartElement = true; } xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, customProperty.getName(), FLOWABLE_EXTENSIONS_NAMESPACE); xtw.writeCharacters(customProperty.getSimpleValue()); xtw.writeEndElement(); } } return didWriteExtensionStartElement; }