List of usage examples for javax.xml.stream XMLStreamReader getText
public String getText();
From source file:net.xy.jcms.controller.configurations.parser.TranslationParser.java
/** * checks for parameters <parameter name="contentgroup" group="1" * convert="de.jamba.ContentGroupConverter"/> * // w w w . j a v a2s . com * @param parser * @return value * @throws XMLStreamException * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException */ private static List<RuleParameter> parseParameter(final XMLStreamReader parser, final ClassLoader loader) throws XMLStreamException, ClassNotFoundException { final List<RuleParameter> params = new ArrayList<RuleParameter>(); while (parser.nextTag() == XMLStreamConstants.START_ELEMENT) { String parameterName = null, converter = null; Integer aplicatesToGroup = null; if (parser.getAttributeCount() != 3 && parser.getAttributeCount() != 2) { throw new IllegalArgumentException("There are to much or few attributes specified for parameter."); } for (int i = 0; i < parser.getAttributeCount(); i++) { if (parser.getAttributeLocalName(i).equals("name")) { parameterName = parser.getAttributeValue(i); } else if (parser.getAttributeLocalName(i).equals("convert")) { converter = parser.getAttributeValue(i); } else if (parser.getAttributeLocalName(i).equals("group")) { aplicatesToGroup = new Integer(parser.getAttributeValue(i)); } } boolean goEnd = true; Map<String, String> mappings = null; if (parser.next() == XMLStreamConstants.CHARACTERS) { final String mappingStr = parser.getText(); // get integrated mapping body if (StringUtils.isNotBlank(mappingStr)) { mappings = new HashMap<String, String>(); final String[] lines = mappingStr.split("\n"); for (String line : lines) { line = line.trim(); if (StringUtils.isBlank(line) || line.startsWith("#")) { continue; } final String[] pair = line.split("=", 2); mappings.put(pair[0].trim(), pair[1].trim()); } } } else { goEnd = false; // allready on end } if (StringUtils.isBlank(parameterName)) { throw new IllegalArgumentException("Parameter name has to be set"); } else if (StringUtils.isBlank(converter)) { throw new IllegalArgumentException("Parameter Converter has to be set"); } else if (aplicatesToGroup == null) { throw new IllegalArgumentException("Applicates to regex group has to be set"); } else { if (mappings != null) { // get special mapping converter params.add(new RuleParameter(parameterName, aplicatesToGroup, ((InitializableController<?>) ConverterPool.get(converter, loader)) .initialize(mappings))); } else { // get normal converter params.add(new RuleParameter(parameterName, aplicatesToGroup, ConverterPool.get(converter, loader))); } } if (goEnd) { parser.nextTag(); // gets endtag } } return params; }
From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java
/** * parses the description field/*from www.j av a 2s . c o m*/ * * @param parser * @return * @throws XMLStreamException */ private static String parseDescription(final XMLStreamReader parser) throws XMLStreamException { parser.next(); final String text = parser.getText(); parser.nextTag(); return text; }
From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java
/** * inits an config from the xml body/*from ww w .ja v a 2s . com*/ * * @param type * @param parser * @return * @throws XMLStreamException */ private static Configuration<?> getConfigurationByBody(final ConfigurationType type, final XMLStreamReader parser, final ClassLoader loader) throws XMLStreamException { parser.next(); final String text = parser.getText(); return Configuration.initByString(type, text, loader); }
From source file:org.activiti.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 w w. j av a 2 s .c om 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()) { 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.activiti.dmn.converter.util.DmnXMLUtil.java
public static DmnExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception { DmnExtensionElement extensionElement = new DmnExtensionElement(); extensionElement.setName(xtr.getLocalName()); if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) { extensionElement.setNamespace(xtr.getNamespaceURI()); }//from w w w . ja v a 2 s. c o m if (StringUtils.isNotEmpty(xtr.getPrefix())) { extensionElement.setNamespacePrefix(xtr.getPrefix()); } for (int i = 0; i < xtr.getAttributeCount(); i++) { DmnExtensionAttribute extensionAttribute = new DmnExtensionAttribute(); extensionAttribute.setName(xtr.getAttributeLocalName(i)); extensionAttribute.setValue(xtr.getAttributeValue(i)); if (StringUtils.isNotEmpty(xtr.getAttributeNamespace(i))) { extensionAttribute.setNamespace(xtr.getAttributeNamespace(i)); } if (StringUtils.isNotEmpty(xtr.getAttributePrefix(i))) { extensionAttribute.setNamespacePrefix(xtr.getAttributePrefix(i)); } extensionElement.addAttribute(extensionAttribute); } 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()) { DmnExtensionElement childExtensionElement = parseExtensionElement(xtr); extensionElement.addChildElement(childExtensionElement); } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) { readyWithExtensionElement = true; } } return extensionElement; }
From source file:org.apache.axiom.om.impl.serialize.StreamingOMSerializer.java
/** * @param reader/* w w w . j ava 2s.com*/ * @param writer * @throws XMLStreamException */ protected void serializeText(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { writer.writeCharacters(reader.getText()); }
From source file:org.apache.axiom.om.impl.serialize.StreamingOMSerializer.java
/** * Method serializeCData./*from w w w .j a v a2 s . co m*/ * * @param reader * @param writer * @throws XMLStreamException */ protected void serializeCData(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { writer.writeCData(reader.getText()); }
From source file:org.apache.axiom.om.impl.serialize.StreamingOMSerializer.java
/** * Method serializeComment.//w w w . j av a 2 s.co m * * @param reader * @param writer * @throws XMLStreamException */ protected void serializeComment(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { writer.writeComment(reader.getText()); }
From source file:org.apache.axiom.util.stax.XMLStreamReaderUtils.java
/** * Get the character data for the current event from the given reader and * write it to the given writer. The method will try to figure out the most * efficient way to copy the data without unnecessary buffering or * conversions between strings and character arrays. * /*from www . jav a 2 s . co m*/ * @param reader * the reader to get the character data from * @param writer * the writer to write the character data to * @throws XMLStreamException * if the underlying XML source is not well-formed * @throws IOException * if an I/O error occurs when writing the character data * @throws IllegalStateException * if this state is not a valid text state. * @see CharacterDataReader */ public static void writeTextTo(XMLStreamReader reader, Writer writer) throws XMLStreamException, IOException { CharacterDataReader cdataReader; try { cdataReader = (CharacterDataReader) reader.getProperty(CharacterDataReader.PROPERTY); } catch (IllegalArgumentException ex) { cdataReader = null; } if (cdataReader != null) { cdataReader.writeTextTo(writer); } else { writer.write(reader.getText()); } }