List of usage examples for javax.xml.stream XMLStreamReader getAttributeType
public String getAttributeType(int index);
From source file:Main.java
private static void printAttributes(XMLStreamReader xmlr) { if (xmlr.getAttributeCount() > 0) { System.out.println("\nHAS ATTRIBUTES: "); int count = xmlr.getAttributeCount(); for (int i = 0; i < count; i++) { QName name = xmlr.getAttributeName(i); String namespace = xmlr.getAttributeNamespace(i); String type = xmlr.getAttributeType(i); String prefix = xmlr.getAttributePrefix(i); String value = xmlr.getAttributeValue(i); System.out.println("ATTRIBUTE-PREFIX: " + prefix); System.out.println("ATTRIBUTE-NAMESP: " + namespace); System.out.println("ATTRIBUTE-NAME: " + name.toString()); System.out.println("ATTRIBUTE-VALUE: " + value); System.out.println("ATTRIBUTE-TYPE: " + type); }/*from w w w . ja v a2 s . c o m*/ } else { System.out.println("HAS NO ATTRIBUTES"); } }
From source file:com.rapidminer.gui.properties.OperatorPropertyPanel.java
/** * Starts a progress thread which parses the parameter descriptions for the provided operator , * cleans the {@link #parameterDescriptionCache}, and stores parsed descriptions in the * {@link #parameterDescriptionCache}./*from w ww . j av a2s . c o m*/ */ private void parseParameterDescriptions(final Operator operator) { parameterDescriptionCache.clear(); URL documentationURL = OperatorDocumentationBrowser.getDocResourcePath(operator); if (documentationURL != null) { try (InputStream documentationStream = documentationURL.openStream()) { XMLStreamReader reader = XML_STREAM_FACTORY.createXMLStreamReader(documentationStream); String parameterKey = null; // The builder that stores the parameter description text StringBuilder parameterTextBuilder = null; boolean inParameters = false; while (reader.hasNext()) { switch (reader.next()) { case XMLStreamReader.START_ELEMENT: if (!inParameters && reader.getLocalName().equals(TAG_PARAMETERS)) { inParameters = true; } else { AttributesImpl attributes = new AttributesImpl(); for (int i = 0; i < reader.getAttributeCount(); i++) { attributes.addAttribute("", reader.getAttributeLocalName(i), reader.getAttributeName(i).toString(), reader.getAttributeType(i), reader.getAttributeValue(i)); } // Check if no parameter was found if (reader.getLocalName().equals(TAG_PARAMETER)) { parameterKey = attributes.getValue(ATTRIBUTE_PARAMETER_KEY); // In case a parameter key was found, create a new string // builder if (parameterKey != null) { parameterTextBuilder = new StringBuilder(); } } if (parameterTextBuilder != null) { appendParameterStartTag(reader.getLocalName(), attributes, parameterTextBuilder); } } break; case XMLStreamReader.END_ELEMENT: // end parsing when end of parameters element is reached if (reader.getLocalName().equals(TAG_PARAMETERS)) { return; } if (parameterTextBuilder != null) { // otherwise add element to description text parameterTextBuilder.append("</"); parameterTextBuilder.append(reader.getLocalName()); parameterTextBuilder.append(">"); // Store description when parameter element ends if (reader.getLocalName().equals(TAG_PARAMETER)) { final String parameterDescription = parameterTextBuilder.toString(); final String key = parameterKey; if (!parameterDescriptionCache.containsKey(parameterKey)) { Source xmlSource = new StreamSource(new StringReader(parameterDescription)); try { String desc = OperatorDocToHtmlConverter.applyXSLTTransformation(xmlSource); parameterDescriptionCache.put(key, StringEscapeUtils.unescapeHtml(desc)); } catch (TransformerException e) { // ignore } } } } break; case XMLStreamReader.CHARACTERS: if (parameterTextBuilder != null) { parameterTextBuilder.append(StringEscapeUtils.escapeHtml(reader.getText())); } break; default: // ignore other events break; } } } catch (IOException | XMLStreamException e) { // ignore } } }
From source file:gima.neo4j.testsuite.osmcheck.OSMImporter.java
public void importFile(OSMWriter<?> osmWriter, String dataset, boolean allPoints, Charset charset) throws IOException, XMLStreamException { System.out.println("Importing with osm-writer: " + osmWriter); osmWriter.getOrCreateOSMDataset(layerName); osm_dataset = osmWriter.getDatasetId(); long startTime = System.currentTimeMillis(); long[] times = new long[] { 0L, 0L, 0L, 0L }; javax.xml.stream.XMLInputFactory factory = javax.xml.stream.XMLInputFactory.newInstance(); CountedFileReader reader = new CountedFileReader(dataset, charset); javax.xml.stream.XMLStreamReader parser = factory.createXMLStreamReader(reader); int countXMLTags = 0; beginProgressMonitor(100);//w w w. j a va 2 s . c o m setLogContext(dataset); boolean startedWays = false; boolean startedRelations = false; try { ArrayList<String> currentXMLTags = new ArrayList<String>(); int depth = 0; Map<String, Object> wayProperties = null; ArrayList<Long> wayNodes = new ArrayList<Long>(); Map<String, Object> relationProperties = null; ArrayList<Map<String, Object>> relationMembers = new ArrayList<Map<String, Object>>(); LinkedHashMap<String, Object> currentNodeTags = new LinkedHashMap<String, Object>(); while (true) { updateProgressMonitor(reader.getPercentRead()); incrLogContext(); int event = parser.next(); if (event == javax.xml.stream.XMLStreamConstants.END_DOCUMENT) { break; } switch (event) { case javax.xml.stream.XMLStreamConstants.START_ELEMENT: currentXMLTags.add(depth, parser.getLocalName()); String tagPath = currentXMLTags.toString(); if (tagPath.equals("[osm]")) { osmWriter.setDatasetProperties(extractProperties(parser)); } else if (tagPath.equals("[osm, bounds]")) { osmWriter.addOSMBBox(extractProperties("bbox", parser)); } else if (tagPath.equals("[osm, node]")) { // <node id="269682538" lat="56.0420950" lon="12.9693483" user="sanna" uid="31450" visible="true" version="1" changeset="133823" timestamp="2008-06-11T12:36:28Z"/> osmWriter.createOSMNode(extractProperties("node", parser)); } else if (tagPath.equals("[osm, way]")) { // <way id="27359054" user="spull" uid="61533" visible="true" version="8" changeset="4707351" timestamp="2010-05-15T15:39:57Z"> if (!startedWays) { startedWays = true; times[0] = System.currentTimeMillis(); osmWriter.optimize(); times[1] = System.currentTimeMillis(); } wayProperties = extractProperties("way", parser); wayNodes.clear(); } else if (tagPath.equals("[osm, way, nd]")) { Map<String, Object> properties = extractProperties(parser); wayNodes.add(Long.parseLong(properties.get("ref").toString())); } else if (tagPath.endsWith("tag]")) { Map<String, Object> properties = extractProperties(parser); currentNodeTags.put(properties.get("k").toString(), properties.get("v").toString()); } else if (tagPath.equals("[osm, relation]")) { // <relation id="77965" user="Grillo" uid="13957" visible="true" version="24" changeset="5465617" timestamp="2010-08-11T19:25:46Z"> if (!startedRelations) { startedRelations = true; times[2] = System.currentTimeMillis(); osmWriter.optimize(); times[3] = System.currentTimeMillis(); } relationProperties = extractProperties("relation", parser); relationMembers.clear(); } else if (tagPath.equals("[osm, relation, member]")) { relationMembers.add(extractProperties(parser)); } if (startedRelations) { if (countXMLTags < 10) { log("Starting tag at depth " + depth + ": " + currentXMLTags.get(depth) + " - " + currentXMLTags.toString()); for (int i = 0; i < parser.getAttributeCount(); i++) { log("\t" + currentXMLTags.toString() + ": " + parser.getAttributeLocalName(i) + "[" + parser.getAttributeNamespace(i) + "," + parser.getAttributePrefix(i) + "," + parser.getAttributeType(i) + "," + "] = " + parser.getAttributeValue(i)); } } countXMLTags++; } depth++; break; case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (currentXMLTags.toString().equals("[osm, node]")) { osmWriter.addOSMNodeTags(allPoints, currentNodeTags); } else if (currentXMLTags.toString().equals("[osm, way]")) { osmWriter.createOSMWay(wayProperties, wayNodes, currentNodeTags); } else if (currentXMLTags.toString().equals("[osm, relation]")) { osmWriter.createOSMRelation(relationProperties, relationMembers, currentNodeTags); } depth--; currentXMLTags.remove(depth); // log("Ending tag at depth "+depth+": "+currentTags.get(depth)); break; default: break; } } } finally { endProgressMonitor(); parser.close(); osmWriter.finish(); this.osm_dataset = osmWriter.getDatasetId(); } describeTimes(startTime, times); osmWriter.describeMissing(); osmWriter.describeLoaded(); long stopTime = System.currentTimeMillis(); log("info | Elapsed time in seconds: " + (1.0 * (stopTime - startTime) / 1000.0)); stats.dumpGeomStats(); stats.printTagStats(); }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
/** * add attributes//w ww . j a va 2s.c o m * * @param NameCreator nc * @param element SOAPElement which is the target of the new attributes * @param reader XMLStreamReader whose cursor is at START_ELEMENT * @throws SOAPException */ protected void addAttributes(NameCreator nc, SOAPElement element, XMLStreamReader reader) throws SOAPException { if (log.isDebugEnabled()) { log.debug("addAttributes: Entry"); } // Add the attributes from the reader int size = reader.getAttributeCount(); for (int i = 0; i < size; i++) { QName qName = reader.getAttributeName(i); String prefix = reader.getAttributePrefix(i); String value = reader.getAttributeValue(i); Name name = nc.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI()); element.addAttribute(name, value); try { if (log.isDebugEnabled()) { log.debug("Setting attrType"); } String namespace = qName.getNamespaceURI(); Attr attr = null; // This is an org.w3c.dom.Attr if (namespace == null || namespace.length() == 0) { attr = element.getAttributeNode(qName.getLocalPart()); } else { attr = element.getAttributeNodeNS(namespace, qName.getLocalPart()); } if (attr != null) { String attrType = reader.getAttributeType(i); attr.setUserData(SAAJConverter.OM_ATTRIBUTE_KEY, attrType, null); if (log.isDebugEnabled()) { log.debug("Storing attrType in UserData: " + attrType); } } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("An error occured while processing attrType: " + e.getMessage()); } } } if (log.isDebugEnabled()) { log.debug("addAttributes: Exit"); } }
From source file:org.neo4j.gis.spatial.osm.OSMImporter.java
public void importFile(OSMWriter<?> osmWriter, String dataset, boolean allPoints, Charset charset) throws IOException, XMLStreamException { System.out.println("Importing with osm-writer: " + osmWriter); osmWriter.getOrCreateOSMDataset(layerName); osm_dataset = osmWriter.getDatasetId(); long startTime = System.currentTimeMillis(); long[] times = new long[] { 0L, 0L, 0L, 0L }; javax.xml.stream.XMLInputFactory factory = javax.xml.stream.XMLInputFactory.newInstance(); CountedFileReader reader = new CountedFileReader(dataset, charset); javax.xml.stream.XMLStreamReader parser = factory.createXMLStreamReader(reader); int countXMLTags = 0; beginProgressMonitor(100);//from www . j a v a2 s. c o m setLogContext(dataset); boolean startedWays = false; boolean startedRelations = false; try { ArrayList<String> currentXMLTags = new ArrayList<String>(); int depth = 0; Map<String, Object> wayProperties = null; ArrayList<Long> wayNodes = new ArrayList<Long>(); Map<String, Object> relationProperties = null; ArrayList<Map<String, Object>> relationMembers = new ArrayList<Map<String, Object>>(); LinkedHashMap<String, Object> currentNodeTags = new LinkedHashMap<String, Object>(); while (true) { updateProgressMonitor(reader.getPercentRead()); incrLogContext(); int event = parser.next(); if (event == javax.xml.stream.XMLStreamConstants.END_DOCUMENT) { break; } switch (event) { case javax.xml.stream.XMLStreamConstants.START_ELEMENT: currentXMLTags.add(depth, parser.getLocalName()); String tagPath = currentXMLTags.toString(); if (tagPath.equals("[osm]")) { osmWriter.setDatasetProperties(extractProperties(parser)); } else if (tagPath.equals("[osm, bounds]")) { osmWriter.addOSMBBox(extractProperties("bbox", parser)); } else if (tagPath.equals("[osm, node]")) { // <node id="269682538" lat="56.0420950" // lon="12.9693483" user="sanna" uid="31450" // visible="true" version="1" changeset="133823" // timestamp="2008-06-11T12:36:28Z"/> osmWriter.createOSMNode(extractProperties("node", parser)); } else if (tagPath.equals("[osm, way]")) { // <way id="27359054" user="spull" uid="61533" // visible="true" version="8" changeset="4707351" // timestamp="2010-05-15T15:39:57Z"> if (!startedWays) { startedWays = true; times[0] = System.currentTimeMillis(); osmWriter.optimize(); times[1] = System.currentTimeMillis(); } wayProperties = extractProperties("way", parser); wayNodes.clear(); } else if (tagPath.equals("[osm, way, nd]")) { Map<String, Object> properties = extractProperties(parser); wayNodes.add(Long.parseLong(properties.get("ref").toString())); } else if (tagPath.endsWith("tag]")) { Map<String, Object> properties = extractProperties(parser); currentNodeTags.put(properties.get("k").toString(), properties.get("v").toString()); } else if (tagPath.equals("[osm, relation]")) { // <relation id="77965" user="Grillo" uid="13957" // visible="true" version="24" changeset="5465617" // timestamp="2010-08-11T19:25:46Z"> if (!startedRelations) { startedRelations = true; times[2] = System.currentTimeMillis(); osmWriter.optimize(); times[3] = System.currentTimeMillis(); } relationProperties = extractProperties("relation", parser); relationMembers.clear(); } else if (tagPath.equals("[osm, relation, member]")) { relationMembers.add(extractProperties(parser)); } if (startedRelations) { if (countXMLTags < 10) { log("Starting tag at depth " + depth + ": " + currentXMLTags.get(depth) + " - " + currentXMLTags.toString()); for (int i = 0; i < parser.getAttributeCount(); i++) { log("\t" + currentXMLTags.toString() + ": " + parser.getAttributeLocalName(i) + "[" + parser.getAttributeNamespace(i) + "," + parser.getAttributePrefix(i) + "," + parser.getAttributeType(i) + "," + "] = " + parser.getAttributeValue(i)); } } countXMLTags++; } depth++; break; case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (currentXMLTags.toString().equals("[osm, node]")) { osmWriter.addOSMNodeTags(allPoints, currentNodeTags); } else if (currentXMLTags.toString().equals("[osm, way]")) { osmWriter.createOSMWay(wayProperties, wayNodes, currentNodeTags); } else if (currentXMLTags.toString().equals("[osm, relation]")) { osmWriter.createOSMRelation(relationProperties, relationMembers, currentNodeTags); } depth--; currentXMLTags.remove(depth); // log("Ending tag at depth "+depth+": "+currentTags.get(depth)); break; default: break; } } } finally { endProgressMonitor(); parser.close(); osmWriter.finish(); this.osm_dataset = osmWriter.getDatasetId(); } describeTimes(startTime, times); osmWriter.describeMissing(); osmWriter.describeLoaded(); long stopTime = System.currentTimeMillis(); log("info | Elapsed time in seconds: " + (1.0 * (stopTime - startTime) / 1000.0)); stats.dumpGeomStats(); stats.printTagStats(); }