protected internal virtual IDictionary <string, DiagramNode> fixFlowNodePositionsIfModelFromAdonis(Document bpmnModel, IDictionary <string, DiagramNode> elementBoundsFromBpmnDi) { if (isExportedFromAdonis50(bpmnModel)) { IDictionary <string, DiagramNode> mapOfFixedBounds = new Dictionary <string, DiagramNode>(); XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xPath = xPathFactory.newXPath(); xPath.NamespaceContext = new Bpmn20NamespaceContext(); foreach (KeyValuePair <string, DiagramNode> entry in elementBoundsFromBpmnDi.SetOfKeyValuePairs()) { string elementId = entry.Key; DiagramNode elementBounds = entry.Value; string expression = "local-name(//bpmn:*[@id = '" + elementId + "'])"; try { XPathExpression xPathExpression = xPath.compile(expression); string elementLocalName = xPathExpression.evaluate(bpmnModel); if (!"participant".Equals(elementLocalName) && !"lane".Equals(elementLocalName) && !"textAnnotation".Equals(elementLocalName) && !"group".Equals(elementLocalName)) { elementBounds.X = elementBounds.X - elementBounds.Width / 2; elementBounds.Y = elementBounds.Y - elementBounds.Height / 2; } } catch (XPathExpressionException e) { throw new ProcessEngineException("Error while evaluating the following XPath expression on a BPMN XML document: '" + expression + "'.", e); } mapOfFixedBounds[elementId] = elementBounds; } return(mapOfFixedBounds); } else { return(elementBoundsFromBpmnDi); } }
private OSMTagMapping(URL tagConf) { try { sbyte defaultZoomAppear; // ---- Parse XML file ---- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(tagConf.openStream()); XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression xe = xpath.compile(XPATH_EXPRESSION_DEFAULT_ZOOM); defaultZoomAppear = sbyte.Parse((string)xe.evaluate(document, XPathConstants.STRING)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.HashMap<Nullable<short>, java.util.Set<String>> tmpPoiZoomOverrides = new java.util.HashMap<>(); Dictionary <short?, ISet <string> > tmpPoiZoomOverrides = new Dictionary <short?, ISet <string> >(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.HashMap<Nullable<short>, java.util.Set<String>> tmpWayZoomOverrides = new java.util.HashMap<>(); Dictionary <short?, ISet <string> > tmpWayZoomOverrides = new Dictionary <short?, ISet <string> >(); // ---- Get list of poi nodes ---- xe = xpath.compile(XPATH_EXPRESSION_POIS); NodeList pois = (NodeList)xe.evaluate(document, XPathConstants.NODESET); for (int i = 0; i < pois.Length; i++) { NamedNodeMap attributes = pois.item(i).Attributes; string key = attributes.getNamedItem("key").TextContent; string value = attributes.getNamedItem("value").TextContent; string[] equivalentValues = null; if (attributes.getNamedItem("equivalent-values") != null) { equivalentValues = attributes.getNamedItem("equivalent-values").TextContent.Split(","); } sbyte zoom = attributes.getNamedItem("zoom-appear") == null ? defaultZoomAppear : sbyte.Parse(attributes.getNamedItem("zoom-appear").TextContent); bool renderable = attributes.getNamedItem("renderable") == null ? true : bool.Parse(attributes.getNamedItem("renderable").TextContent); bool forcePolygonLine = attributes.getNamedItem("force-polygon-line") == null ? false : bool.Parse(attributes.getNamedItem("force-polygon-line").TextContent); OSMTag osmTag = new OSMTag(this.poiID, key, value, zoom, renderable, forcePolygonLine); if (this.stringToPoiTag.ContainsKey(osmTag.tagKey())) { LOGGER.warning("duplicate osm-tag found in tag-mapping configuration (ignoring): " + osmTag); continue; } LOGGER.finest("adding poi: " + osmTag); this.stringToPoiTag[osmTag.tagKey()] = osmTag; if (equivalentValues != null) { foreach (string equivalentValue in equivalentValues) { this.stringToPoiTag[OSMTag.tagKey(key, equivalentValue)] = osmTag; } } this.idToPoiTag[Convert.ToInt16(this.poiID)] = osmTag; // also fill optimization mapping with identity this.optimizedPoiIds[Convert.ToInt16(this.poiID)] = Convert.ToInt16(this.poiID); // check if this tag overrides the zoom level spec of another tag NodeList zoomOverrideNodes = pois.item(i).ChildNodes; for (int j = 0; j < zoomOverrideNodes.Length; j++) { Node overriddenNode = zoomOverrideNodes.item(j); if (overriddenNode is Element) { string keyOverridden = overriddenNode.Attributes.getNamedItem("key").TextContent; string valueOverridden = overriddenNode.Attributes.getNamedItem("value").TextContent; ISet <string> s = tmpPoiZoomOverrides[Convert.ToInt16(this.poiID)]; if (s == null) { s = new HashSet <>(); tmpPoiZoomOverrides[Convert.ToInt16(this.poiID)] = s; } s.Add(OSMTag.tagKey(keyOverridden, valueOverridden)); } } this.poiID++; } // ---- Get list of way nodes ---- xe = xpath.compile(XPATH_EXPRESSION_WAYS); NodeList ways = (NodeList)xe.evaluate(document, XPathConstants.NODESET); for (int i = 0; i < ways.Length; i++) { NamedNodeMap attributes = ways.item(i).Attributes; string key = attributes.getNamedItem("key").TextContent; string value = attributes.getNamedItem("value").TextContent; string[] equivalentValues = null; if (attributes.getNamedItem("equivalent-values") != null) { equivalentValues = attributes.getNamedItem("equivalent-values").TextContent.Split(","); } sbyte zoom = attributes.getNamedItem("zoom-appear") == null ? defaultZoomAppear : sbyte.Parse(attributes.getNamedItem("zoom-appear").TextContent); bool renderable = attributes.getNamedItem("renderable") == null ? true : bool.Parse(attributes.getNamedItem("renderable").TextContent); bool forcePolygonLine = attributes.getNamedItem("force-polygon-line") == null ? false : bool.Parse(attributes.getNamedItem("force-polygon-line").TextContent); OSMTag osmTag = new OSMTag(this.wayID, key, value, zoom, renderable, forcePolygonLine); if (this.stringToWayTag.ContainsKey(osmTag.tagKey())) { LOGGER.warning("duplicate osm-tag found in tag-mapping configuration (ignoring): " + osmTag); continue; } LOGGER.finest("adding way: " + osmTag); this.stringToWayTag[osmTag.tagKey()] = osmTag; if (equivalentValues != null) { foreach (string equivalentValue in equivalentValues) { this.stringToWayTag[OSMTag.tagKey(key, equivalentValue)] = osmTag; } } this.idToWayTag[Convert.ToInt16(this.wayID)] = osmTag; // also fill optimization mapping with identity this.optimizedWayIds[Convert.ToInt16(this.wayID)] = Convert.ToInt16(this.wayID); // check if this tag overrides the zoom level spec of another tag NodeList zoomOverrideNodes = ways.item(i).ChildNodes; for (int j = 0; j < zoomOverrideNodes.Length; j++) { Node overriddenNode = zoomOverrideNodes.item(j); if (overriddenNode is Element) { string keyOverridden = overriddenNode.Attributes.getNamedItem("key").TextContent; string valueOverridden = overriddenNode.Attributes.getNamedItem("value").TextContent; ISet <string> s = tmpWayZoomOverrides[Convert.ToInt16(this.wayID)]; if (s == null) { s = new HashSet <>(); tmpWayZoomOverrides[Convert.ToInt16(this.wayID)] = s; } s.Add(OSMTag.tagKey(keyOverridden, valueOverridden)); } } this.wayID++; } // copy temporary values from zoom-override data sets foreach (KeyValuePair <short?, ISet <string> > entry in tmpPoiZoomOverrides.SetOfKeyValuePairs()) { ISet <OSMTag> overriddenTags = new HashSet <OSMTag>(); foreach (string tagString in entry.Value) { OSMTag tag = this.stringToPoiTag[tagString]; if (tag != null) { overriddenTags.Add(tag); } } if (overriddenTags.Count > 0) { this.poiZoomOverrides[entry.Key] = overriddenTags; } } foreach (KeyValuePair <short?, ISet <string> > entry in tmpWayZoomOverrides.SetOfKeyValuePairs()) { ISet <OSMTag> overriddenTags = new HashSet <OSMTag>(); foreach (string tagString in entry.Value) { OSMTag tag = this.stringToWayTag[tagString]; if (tag != null) { overriddenTags.Add(tag); } } if (overriddenTags.Count > 0) { this.wayZoomOverrides[entry.Key] = overriddenTags; } } // ---- Error handling ---- } catch (SAXParseException spe) { LOGGER.severe("\n** Parsing error, line " + spe.LineNumber + ", uri " + spe.SystemId); throw new System.InvalidOperationException(spe); } catch (SAXException sxe) { throw new System.InvalidOperationException(sxe); } catch (ParserConfigurationException pce) { throw new System.InvalidOperationException(pce); } catch (IOException ioe) { throw new System.InvalidOperationException(ioe); } catch (XPathExpressionException e) { throw new System.InvalidOperationException(e); } }