List of usage examples for javax.xml.stream XMLStreamReader getLocalName
public String getLocalName();
From source file:org.eclipse.smila.connectivity.framework.agent.jobfile.JobFileReader.java
/** * /*from w w w .j av a 2s . com*/ * @param staxReader * source XML stream * @param tagName * tag name * @return true if we are currently at a start tag with the specified name */ private boolean isStartTag(final XMLStreamReader staxReader, final String tagName) { return staxReader.isStartElement() && tagName.equals(staxReader.getLocalName()); }
From source file:org.eclipse.smila.connectivity.framework.agent.jobfile.JobFileReader.java
/** * /* w ww. ja v a2 s . c o m*/ * @param staxReader * source XML stream * @param tagName * tag name * @return true if we are currently at a end tag with the specified name */ private boolean isEndTag(final XMLStreamReader staxReader, final String tagName) { return staxReader.isEndElement() && tagName.equals(staxReader.getLocalName()); }
From source file:org.elissa.web.server.TransformerServlet.java
private void revisitSequenceFlows(Definitions def, String orig) { try {//from w ww . ja va2 s . com Map<String, Map<String, String>> sequenceFlowMapping = new HashMap<String, Map<String, String>>(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(orig)); while (reader.hasNext()) { if (reader.next() == XMLStreamReader.START_ELEMENT) { if ("sequenceFlow".equals(reader.getLocalName())) { String id = ""; String source = ""; String target = ""; for (int i = 0; i < reader.getAttributeCount(); i++) { if ("id".equals(reader.getAttributeLocalName(i))) { id = reader.getAttributeValue(i); } if ("sourceRef".equals(reader.getAttributeLocalName(i))) { source = reader.getAttributeValue(i); } if ("targetRef".equals(reader.getAttributeLocalName(i))) { target = reader.getAttributeValue(i); } } Map<String, String> valueMap = new HashMap<String, String>(); valueMap.put("sourceRef", source); valueMap.put("targetRef", target); sequenceFlowMapping.put(id, valueMap); } } } List<RootElement> rootElements = def.getRootElements(); for (RootElement root : rootElements) { if (root instanceof Process) { Process process = (Process) root; List<FlowElement> flowElements = process.getFlowElements(); for (FlowElement fe : flowElements) { if (fe instanceof SequenceFlow) { SequenceFlow sf = (SequenceFlow) fe; if (sequenceFlowMapping.containsKey(sf.getId())) { sf.setSourceRef( getFlowNode(def, sequenceFlowMapping.get(sf.getId()).get("sourceRef"))); sf.setTargetRef( getFlowNode(def, sequenceFlowMapping.get(sf.getId()).get("targetRef"))); } else { _logger.error("Could not find mapping for sequenceFlow: " + sf.getId()); } } } } } } catch (FactoryConfigurationError e) { _logger.error(e.getMessage()); e.printStackTrace(); } catch (Exception e) { _logger.error(e.getMessage()); e.printStackTrace(); } }
From source file:org.elissa.web.server.TransformerServlet.java
private void addBpmnDiInfo(Definitions def, String gpd) { try {/* w w w . jav a2 s. co m*/ Map<String, Bounds> _bounds = new HashMap<String, Bounds>(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(gpd)); while (reader.hasNext()) { if (reader.next() == XMLStreamReader.START_ELEMENT) { if ("node".equals(reader.getLocalName())) { Bounds b = DcFactory.eINSTANCE.createBounds(); String nodeName = null; String nodeX = null; String nodeY = null; String nodeWidth = null; String nodeHeight = null; for (int i = 0; i < reader.getAttributeCount(); i++) { if ("name".equals(reader.getAttributeLocalName(i))) { nodeName = reader.getAttributeValue(i); } else if ("x".equals(reader.getAttributeLocalName(i))) { nodeX = reader.getAttributeValue(i); } else if ("y".equals(reader.getAttributeLocalName(i))) { nodeY = reader.getAttributeValue(i); } else if ("width".equals(reader.getAttributeLocalName(i))) { nodeWidth = reader.getAttributeValue(i); } else if ("height".equals(reader.getAttributeLocalName(i))) { nodeHeight = reader.getAttributeValue(i); } } b.setX(new Float(nodeX).floatValue()); b.setY(new Float(nodeY).floatValue()); b.setWidth(new Float(nodeWidth).floatValue()); b.setHeight(new Float(nodeHeight).floatValue()); _bounds.put(nodeName, b); } } } for (RootElement rootElement : def.getRootElements()) { if (rootElement instanceof Process) { Process process = (Process) rootElement; BpmnDiFactory diFactory = BpmnDiFactory.eINSTANCE; BPMNDiagram diagram = diFactory.createBPMNDiagram(); BPMNPlane plane = diFactory.createBPMNPlane(); plane.setBpmnElement(process); diagram.setPlane(plane); for (FlowElement flowElement : process.getFlowElements()) { if (flowElement instanceof FlowNode) { Bounds b = _bounds.get(flowElement.getId()); if (b != null) { BPMNShape shape = diFactory.createBPMNShape(); shape.setBpmnElement(flowElement); shape.setBounds(b); plane.getPlaneElement().add(shape); } } else if (flowElement instanceof SequenceFlow) { SequenceFlow sequenceFlow = (SequenceFlow) flowElement; BPMNEdge edge = diFactory.createBPMNEdge(); edge.setBpmnElement(flowElement); DcFactory dcFactory = DcFactory.eINSTANCE; Point point = dcFactory.createPoint(); if (sequenceFlow.getSourceRef() != null) { Bounds sourceBounds = _bounds.get(sequenceFlow.getSourceRef().getId()); point.setX(sourceBounds.getX() + (sourceBounds.getWidth() / 2)); point.setY(sourceBounds.getY() + (sourceBounds.getHeight() / 2)); } edge.getWaypoint().add(point); // List<Point> dockers = _dockers.get(sequenceFlow.getId()); // for (int i = 1; i < dockers.size() - 1; i++) { // edge.getWaypoint().add(dockers.get(i)); // } point = dcFactory.createPoint(); if (sequenceFlow.getTargetRef() != null) { Bounds targetBounds = _bounds.get(sequenceFlow.getTargetRef().getId()); point.setX(targetBounds.getX() + (targetBounds.getWidth() / 2)); point.setY(targetBounds.getY() + (targetBounds.getHeight() / 2)); } edge.getWaypoint().add(point); plane.getPlaneElement().add(edge); } } def.getDiagrams().add(diagram); } } } catch (FactoryConfigurationError e) { _logger.error("Exception adding bpmndi info: " + e.getMessage()); } catch (Exception e) { _logger.error("Exception adding bpmndi info: " + e.getMessage()); } }
From source file:org.elissa.web.server.TransformerServlet.java
private String[] findPackageAndAssetNameForUUID(String uuid, IDiagramProfile profile) { List<String> packages = new ArrayList<String>(); String packagesURL = ExternalInfo.getExternalProtocol(profile) + "://" + ExternalInfo.getExternalHost(profile) + "/" + profile.getExternalLoadURLSubdomain().substring(0, profile.getExternalLoadURLSubdomain().indexOf("/")) + "/rest/packages/"; try {// www . j a v a 2 s . c om XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory .createXMLStreamReader(getInputStreamForURL(packagesURL, "GET", profile)); while (reader.hasNext()) { if (reader.next() == XMLStreamReader.START_ELEMENT) { if ("title".equals(reader.getLocalName())) { packages.add(reader.getElementText()); } } } } catch (Exception e) { // we dont want to barf..just log that error happened _logger.error(e.getMessage()); } boolean gotPackage = false; String[] pkgassetnames = new String[2]; for (String nextPackage : packages) { String packageAssetURL = ExternalInfo.getExternalProtocol(profile) + "://" + ExternalInfo.getExternalHost(profile) + "/" + profile.getExternalLoadURLSubdomain().substring(0, profile.getExternalLoadURLSubdomain().indexOf("/")) + "/rest/packages/" + nextPackage + "/assets/"; try { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory .createXMLStreamReader(getInputStreamForURL(packageAssetURL, "GET", profile)); String title = ""; while (reader.hasNext()) { int next = reader.next(); if (next == XMLStreamReader.START_ELEMENT) { if ("title".equals(reader.getLocalName())) { title = reader.getElementText(); } if ("uuid".equals(reader.getLocalName())) { String eleText = reader.getElementText(); if (uuid.equals(eleText)) { pkgassetnames[0] = nextPackage; pkgassetnames[1] = title; gotPackage = true; } } } } } catch (Exception e) { // we dont want to barf..just log that error happened _logger.error(e.getMessage()); } if (gotPackage) { // noo need to loop through rest of packages break; } } return pkgassetnames; }
From source file:org.erdc.cobie.shared.COBieUtility.java
static public Map<String, String> elementMapFromXMLObject(XmlObject xml) { Map<String, String> elementMap = new HashMap<String, String>(); XMLStreamReader rdr = xml.newXMLStreamReader(); String keyName = ""; String keyVal = ""; boolean lastWasStartElement = false; int attCount = 0; try {//w w w. j ava 2 s . co m while (rdr.hasNext()) { try { attCount = rdr.getAttributeCount(); } catch (Exception ex) { attCount = 0; } if (attCount > 0) { for (int i = 0; i < attCount; i++) { keyName = rdr.getAttributeLocalName(i); keyVal = rdr.getAttributeValue(i); if (!elementMap.containsKey(keyName)) { elementMap.put(keyName, escape(keyVal)); } lastWasStartElement = false; } } if (rdr.isStartElement()) { keyName = rdr.getLocalName(); lastWasStartElement = true; } else if (rdr.isCharacters() && lastWasStartElement) { if (isElementADateTime(xml, keyName)) { keyVal = COBieUtility.stringFromXmlDateTime(xml, keyName); } else { keyVal = rdr.getText(); } if (!elementMap.containsKey(keyName)) { elementMap.put(keyName, escape(keyVal)); } lastWasStartElement = false; } else { lastWasStartElement = false; } rdr.next(); } } catch (XMLStreamException e) { LOGGER.error("", e); } return elementMap; }
From source file:org.flockdata.integration.FileProcessor.java
private int processXMLFile(String file, ExtractProfile extractProfile) throws IOException, FlockException, IllegalAccessException, InstantiationException, ClassNotFoundException { try {/*from w w w . j a va 2s . com*/ int rows = 0; StopWatch watch = new StopWatch(); StreamSource source = new StreamSource(file); XMLInputFactory xif = XMLInputFactory.newFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(source); XmlMappable mappable = (XmlMappable) Class.forName(extractProfile.getHandler()).newInstance(); mappable.positionReader(xsr); String dataType = mappable.getDataType(); watch.start(); try { long then = new DateTime().getMillis(); while (xsr.getLocalName().equals(dataType)) { EntityInputBean entityInputBean = Transformer.toEntity(mappable, xsr, extractProfile.getContentModel()); rows++; xsr.nextTag(); getPayloadWriter().writeEntity(entityInputBean); if (stopProcessing(rows, then)) { break; } } } finally { getPayloadWriter().flush(); } return endProcess(watch, rows, 0); } catch (XMLStreamException | JAXBException e1) { throw new IOException(e1); } }
From source file:org.flowable.bpmn.converter.BaseBpmnXMLConverter.java
@SuppressWarnings("unchecked") protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception { ExtensionElement extensionElement = new ExtensionElement(); extensionElement.setName(xtr.getLocalName()); if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) { extensionElement.setNamespace(xtr.getNamespaceURI()); }//from w ww. ja v a2 s . co m if (StringUtils.isNotEmpty(xtr.getPrefix())) { extensionElement.setNamespacePrefix(xtr.getPrefix()); } BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes); boolean readyWithExtensionElement = false; while (readyWithExtensionElement == false && xtr.hasNext()) { xtr.next(); if (xtr.isCharacters() || XMLStreamReader.CDATA == xtr.getEventType()) { if (StringUtils.isNotEmpty(xtr.getText().trim())) { extensionElement.setElementText(xtr.getText().trim()); } } else if (xtr.isStartElement()) { ExtensionElement childExtensionElement = parseExtensionElement(xtr); extensionElement.addChildElement(childExtensionElement); } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) { readyWithExtensionElement = true; } } return extensionElement; }
From source file:org.flowable.bpmn.converter.BpmnXMLConverter.java
public BpmnModel convertToBpmnModel(XMLStreamReader xtr) { BpmnModel model = new BpmnModel(); model.setStartEventFormTypes(startEventFormTypes); model.setUserTaskFormTypes(userTaskFormTypes); try {//ww w . jav a 2s . c o m Process activeProcess = null; List<SubProcess> activeSubProcessList = new ArrayList<SubProcess>(); while (xtr.hasNext()) { try { xtr.next(); } catch (Exception e) { LOGGER.debug("Error reading XML document", e); throw new XMLException("Error reading XML", e); } if (xtr.isEndElement() && (ELEMENT_SUBPROCESS.equals(xtr.getLocalName()) || ELEMENT_TRANSACTION.equals(xtr.getLocalName()) || ELEMENT_ADHOC_SUBPROCESS.equals(xtr.getLocalName()))) { activeSubProcessList.remove(activeSubProcessList.size() - 1); } if (xtr.isStartElement() == false) { continue; } if (ELEMENT_DEFINITIONS.equals(xtr.getLocalName())) { definitionsParser.parse(xtr, model); } else if (ELEMENT_RESOURCE.equals(xtr.getLocalName())) { resourceParser.parse(xtr, model); } else if (ELEMENT_SIGNAL.equals(xtr.getLocalName())) { signalParser.parse(xtr, model); } else if (ELEMENT_MESSAGE.equals(xtr.getLocalName())) { messageParser.parse(xtr, model); } else if (ELEMENT_ERROR.equals(xtr.getLocalName())) { if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) { model.addError(xtr.getAttributeValue(null, ATTRIBUTE_ID), xtr.getAttributeValue(null, ATTRIBUTE_ERROR_CODE)); } } else if (ELEMENT_IMPORT.equals(xtr.getLocalName())) { importParser.parse(xtr, model); } else if (ELEMENT_ITEM_DEFINITION.equals(xtr.getLocalName())) { itemDefinitionParser.parse(xtr, model); } else if (ELEMENT_DATA_STORE.equals(xtr.getLocalName())) { dataStoreParser.parse(xtr, model); } else if (ELEMENT_INTERFACE.equals(xtr.getLocalName())) { interfaceParser.parse(xtr, model); } else if (ELEMENT_IOSPECIFICATION.equals(xtr.getLocalName())) { ioSpecificationParser.parseChildElement(xtr, activeProcess, model); } else if (ELEMENT_PARTICIPANT.equals(xtr.getLocalName())) { participantParser.parse(xtr, model); } else if (ELEMENT_MESSAGE_FLOW.equals(xtr.getLocalName())) { messageFlowParser.parse(xtr, model); } else if (ELEMENT_PROCESS.equals(xtr.getLocalName())) { Process process = processParser.parse(xtr, model); if (process != null) { activeProcess = process; } } else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) { potentialStarterParser.parse(xtr, activeProcess); } else if (ELEMENT_LANE.equals(xtr.getLocalName())) { laneParser.parse(xtr, activeProcess, model); } else if (ELEMENT_DOCUMENTATION.equals(xtr.getLocalName())) { BaseElement parentElement = null; if (!activeSubProcessList.isEmpty()) { parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1); } else if (activeProcess != null) { parentElement = activeProcess; } documentationParser.parseChildElement(xtr, parentElement, model); } else if (activeProcess == null && ELEMENT_TEXT_ANNOTATION.equals(xtr.getLocalName())) { String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID); TextAnnotation textAnnotation = (TextAnnotation) new TextAnnotationXMLConverter() .convertXMLToElement(xtr, model); textAnnotation.setId(elementId); model.getGlobalArtifacts().add(textAnnotation); } else if (activeProcess == null && ELEMENT_ASSOCIATION.equals(xtr.getLocalName())) { String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID); Association association = (Association) new AssociationXMLConverter().convertXMLToElement(xtr, model); association.setId(elementId); model.getGlobalArtifacts().add(association); } else if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) { extensionElementsParser.parse(xtr, activeSubProcessList, activeProcess, model); } else if (ELEMENT_SUBPROCESS.equals(xtr.getLocalName()) || ELEMENT_TRANSACTION.equals(xtr.getLocalName()) || ELEMENT_ADHOC_SUBPROCESS.equals(xtr.getLocalName())) { subProcessParser.parse(xtr, activeSubProcessList, activeProcess); } else if (ELEMENT_COMPLETION_CONDITION.equals(xtr.getLocalName())) { if (!activeSubProcessList.isEmpty()) { SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1); if (subProcess instanceof AdhocSubProcess) { AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess; adhocSubProcess.setCompletionCondition(xtr.getElementText()); } } } else if (ELEMENT_DI_SHAPE.equals(xtr.getLocalName())) { bpmnShapeParser.parse(xtr, model); } else if (ELEMENT_DI_EDGE.equals(xtr.getLocalName())) { bpmnEdgeParser.parse(xtr, model); } else { if (!activeSubProcessList.isEmpty() && ELEMENT_MULTIINSTANCE.equalsIgnoreCase(xtr.getLocalName())) { multiInstanceParser.parseChildElement(xtr, activeSubProcessList.get(activeSubProcessList.size() - 1), model); } else if (convertersToBpmnMap.containsKey(xtr.getLocalName())) { if (activeProcess != null) { BaseBpmnXMLConverter converter = convertersToBpmnMap.get(xtr.getLocalName()); converter.convertToBpmnModel(xtr, model, activeProcess, activeSubProcessList); } } } } for (Process process : model.getProcesses()) { for (Pool pool : model.getPools()) { if (process.getId().equals(pool.getProcessRef())) { pool.setExecutable(process.isExecutable()); } } processFlowElements(process.getFlowElements(), process); } } catch (XMLException e) { throw e; } catch (Exception e) { LOGGER.error("Error processing BPMN document", e); throw new XMLException("Error processing BPMN document", e); } return model; }
From source file:org.flowable.bpmn.converter.child.DataAssociationParser.java
public static void parseDataAssociation(DataAssociation dataAssociation, String elementName, XMLStreamReader xtr) { boolean readyWithDataAssociation = false; Assignment assignment = null;//from ww w. j ava 2 s.co m try { dataAssociation.setId(xtr.getAttributeValue(null, "id")); while (readyWithDataAssociation == false && xtr.hasNext()) { xtr.next(); if (xtr.isStartElement() && ELEMENT_SOURCE_REF.equals(xtr.getLocalName())) { String sourceRef = xtr.getElementText(); if (StringUtils.isNotEmpty(sourceRef)) { dataAssociation.setSourceRef(sourceRef.trim()); } } else if (xtr.isStartElement() && ELEMENT_TARGET_REF.equals(xtr.getLocalName())) { String targetRef = xtr.getElementText(); if (StringUtils.isNotEmpty(targetRef)) { dataAssociation.setTargetRef(targetRef.trim()); } } else if (xtr.isStartElement() && ELEMENT_TRANSFORMATION.equals(xtr.getLocalName())) { String transformation = xtr.getElementText(); if (StringUtils.isNotEmpty(transformation)) { dataAssociation.setTransformation(transformation.trim()); } } else if (xtr.isStartElement() && ELEMENT_ASSIGNMENT.equals(xtr.getLocalName())) { assignment = new Assignment(); BpmnXMLUtil.addXMLLocation(assignment, xtr); } else if (xtr.isStartElement() && ELEMENT_FROM.equals(xtr.getLocalName())) { String from = xtr.getElementText(); if (assignment != null && StringUtils.isNotEmpty(from)) { assignment.setFrom(from.trim()); } } else if (xtr.isStartElement() && ELEMENT_TO.equals(xtr.getLocalName())) { String to = xtr.getElementText(); if (assignment != null && StringUtils.isNotEmpty(to)) { assignment.setTo(to.trim()); } } else if (xtr.isEndElement() && ELEMENT_ASSIGNMENT.equals(xtr.getLocalName())) { if (StringUtils.isNotEmpty(assignment.getFrom()) && StringUtils.isNotEmpty(assignment.getTo())) { dataAssociation.getAssignments().add(assignment); } } else if (xtr.isEndElement() && elementName.equals(xtr.getLocalName())) { readyWithDataAssociation = true; } } } catch (Exception e) { LOGGER.warn("Error parsing data association child elements", e); } }