List of usage examples for javax.xml.stream XMLStreamWriter writeCharacters
public void writeCharacters(String text) throws XMLStreamException;
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
public static void main(String[] args) { logger.info("Starting application [ rtd ] ..."); try {/*from w ww. j a v a 2 s. co m*/ config.addConfiguration( new XMLConfiguration(RetrieveTestData.class.getClassLoader().getResource(CONFIG_FILENAME))); HierarchicalConfiguration appConfig = config.configurationAt(APPLICATION_CONFIG_ROOT); EodDataProvider eodDataProvider = null; OutputStream out = new FileOutputStream(OUTPUT_FILENAME); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(out); eodDataProvider = EodDataProviderFactory.create(appConfig, EODDATA_PROVIDER_NAME); writer.writeStartDocument("utf-8", "1.0"); writer.writeCharacters(NEWLINE); writer.writeComment("Test data for running DataScraper unit tests against"); writer.writeCharacters(NEWLINE); writer.setPrefix(XML_PREFIX, XML_NAMESPACE_URI); writer.writeStartElement(XML_NAMESPACE_URI, TESTDATA_LOCALNAME); writer.writeNamespace(XML_PREFIX, XML_NAMESPACE_URI); writer.writeCharacters(NEWLINE); serializeExchanges(eodDataProvider, writer); serializeSymbols(eodDataProvider, writer); serializeQuotes(eodDataProvider, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); writer.writeEndDocument(); writer.flush(); writer.close(); } catch (ConfigurationException ce) { logger.error(ce.toString()); ce.printStackTrace(); } catch (Exception e) { logger.error(e.toString()); logger.error(e); } logger.info("Exiting application [ rtd ] ..."); }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
private static void serialize(ADBBean[] beanArray, QName qname, XMLStreamWriter writer) { for (ADBBean bean : beanArray) { try {//from w w w. j a v a 2s . c o m bean.serialize(qname, writer); writer.writeCharacters(NEWLINE); } catch (XMLStreamException xse) { logger.error(xse.toString()); logger.error(xse); } } }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
private static void serializeExchanges(EodDataProvider eodDataProvider, XMLStreamWriter writer) { try {/*w w w.ja v a2 s. co m*/ writer.writeStartElement(XML_NAMESPACE_URI, EXCHANGES_LOCALNAME); writer.writeCharacters(NEWLINE); serialize(eodDataProvider.getExchanges(), EXCHANGE_QNAME, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); } catch (XMLStreamException xse) { logger.error(xse.toString()); logger.error(xse); } catch (EodDataProviderException edpe) { logger.error(edpe.toString()); logger.error(edpe); } finally { if (eodDataProvider != null) { // eodDataProvider.close(); } } }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
private static void serializeSymbols(EodDataProvider eodDataProvider, XMLStreamWriter writer) { try {/* ww w . j av a2 s . c om*/ writer.writeStartElement(XML_NAMESPACE_URI, SYMBOLS_LOCALNAME); writer.writeAttribute(XML_NAMESPACE_URI, TESTEXCHANGE_ATTRNAME, TEST_EXCHANGE); writer.writeCharacters(NEWLINE); serialize(eodDataProvider.getSymbols(TEST_EXCHANGE), SYMBOL_QNAME, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); } catch (XMLStreamException xse) { logger.error(xse.toString()); logger.error(xse); } catch (EodDataProviderException edpe) { logger.error(edpe.toString()); logger.error(edpe); } finally { if (eodDataProvider != null) { // eodDataProvider.close(); } } }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
private static void serializeQuotes(EodDataProvider eodDataProvider, XMLStreamWriter writer) { try {/*from w ww . j a v a2s .c o m*/ writer.writeStartElement(XML_NAMESPACE_URI, QUOTES_LOCALNAME); writer.writeAttribute(XML_NAMESPACE_URI, TESTEXCHANGE_ATTRNAME, TEST_EXCHANGE); writer.writeAttribute(XML_NAMESPACE_URI, TESTSYMBOL_ATTRNAME, TEST_SYMBOL); writer.writeCharacters(NEWLINE); Calendar startCalendar = Calendar.getInstance(); startCalendar.add(Calendar.YEAR, HISTORY_YEAR_OFFSET); // startCalendar.add(Calendar.MONTH, HISTORY_MONTH_OFFSET); Calendar endCalendar = Calendar.getInstance(); serialize(eodDataProvider.getQuotes(TEST_EXCHANGE, TEST_SYMBOL, startCalendar, endCalendar, DEFAULT_FREQUENCY), QUOTE_QNAME, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); } catch (XMLStreamException xse) { logger.error(xse.toString()); logger.error(xse); } catch (EodDataProviderException edpe) { logger.error(edpe.toString()); logger.error(edpe); } finally { if (eodDataProvider != null) { // eodDataProvider.close(); } } }
From source file:org.activiti.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); }/*from w w w.j a v a2 s . c o m*/ if (baseElement instanceof Activity) { final Activity activity = (Activity) baseElement; if (activity.isAsynchronous()) { writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw); if (activity.isNotExclusive()) { writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw); } } 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 (gateway.isAsynchronous()) { writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw); if (gateway.isNotExclusive()) { writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw); } } 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.activiti.bpmn.converter.BaseBpmnXMLConverter.java
protected void writeTimerDefinition(Event parentEvent, TimerEventDefinition timerDefinition, XMLStreamWriter xtw) throws Exception { xtw.writeStartElement(ELEMENT_EVENT_TIMERDEFINITION); boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(timerDefinition, false, xtw); if (didWriteExtensionStartElement) { xtw.writeEndElement();//from ww w . j a v a 2 s.com } 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); 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.activiti.bpmn.converter.BpmnXMLConverter.java
private void createXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw) throws Exception { if (flowElement instanceof SubProcess) { SubProcess subProcess = (SubProcess) flowElement; xtw.writeStartElement(ELEMENT_SUBPROCESS); xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId()); if (StringUtils.isNotEmpty(subProcess.getName())) { xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName()); } else {//from w w w . ja va 2s . c o m xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess"); } if (subProcess instanceof EventSubProcess) { xtw.writeAttribute(ATTRIBUTE_TRIGGERED_BY, ATTRIBUTE_VALUE_TRUE); } if (StringUtils.isNotEmpty(subProcess.getDocumentation())) { xtw.writeStartElement(ELEMENT_DOCUMENTATION); xtw.writeCharacters(subProcess.getDocumentation()); xtw.writeEndElement(); } boolean didWriteExtensionStartElement = ActivitiListenerExport.writeListeners(subProcess, false, xtw); didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(subProcess, didWriteExtensionStartElement, xtw); if (didWriteExtensionStartElement) { // closing extensions element xtw.writeEndElement(); } MultiInstanceExport.writeMultiInstance(subProcess, xtw); 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.activiti.bpmn.converter.DataStoreReferenceXMLConverter.java
@Override protected void writeAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception { DataStoreReference dataStoreRef = (DataStoreReference) element; if (StringUtils.isNotEmpty(dataStoreRef.getDataState())) { xtw.writeStartElement(ELEMENT_DATA_STATE); xtw.writeCharacters(dataStoreRef.getDataState()); xtw.writeEndElement();// www . j a v a2s . c om } }
From source file:org.activiti.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(ACTIVITI_EXTENSIONS_PREFIX, FAILED_JOB_RETRY_TIME_CYCLE, ACTIVITI_EXTENSIONS_NAMESPACE); xtw.writeCharacters(failedJobRetryCycle); xtw.writeEndElement();// ww w. j a va2 s .c o m } } }