Create a new StAX reader on a string.

@param paramString
the XML file as a string to parse
@return an {@link XMLEventReader}
@throws IOException
if I/O operation fails
@throws XMLStreamException
if any parsing error occurs
978685
public static synchronized XMLEventReader createStringReader(final String paramString)
        throws IOException, XMLStreamException {
        final XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        final InputStream in = new ByteArrayInputStream(paramString.getBytes());
        return factory.createXMLEventReader(in);
    }
911506
@SuppressWarnings("resource")
    @Override
    public HoconTreeTraversingParser createParser(String content)
        throws IOException, JsonParseException
    {
        Reader r = new StringReader(content);
        IOContext ctxt = _createContext(r, true); // true->own, can close
        // [JACKSON-512]: allow wrapping with InputDecorator
        if (_inputDecorator != null) {
            r = _inputDecorator.decorate(ctxt, r);
        }
        return _createParser(r, ctxt);
    }
1329976
protected final void readToEndElement(XMLEventReader eventReader, StartElement event)
            throws XMLStreamException {
        final Deque<QName> elementStack = new LinkedList<QName>();
        elementStack.push(event.getName());

        while (!elementStack.isEmpty()) {
            final XMLEvent nextEvent = eventReader.nextEvent();
            if (nextEvent.isStartElement()) {
                final StartElement startElement = nextEvent.asStartElement();
                elementStack.push(startElement.getName());
            } else if (nextEvent.isEndElement()) {
                final QName lastStart = elementStack.pop();
                final EndElement endElement = nextEvent.asEndElement();
                if (!lastStart.equals(endElement.getName())) {
                    throw new XMLStreamException(
                            "Invalid XML Structure, expected EndElement "
                                    + lastStart
                                    + " but found EndElment "
                                    + endElement.getName());
                }
            }
        }
    }
230238
public <B> XMLReader<B> map(final Function<? super T, ? extends B> mapper) {
		requireNonNull(mapper);

		return new XMLReader<B>(_name, _type) {
			@Override
			public B read(final XMLStreamReader xml, final boolean lenient)
				throws XMLStreamException
			{
				try {
					return mapper.apply(XMLReader.this.read(xml, lenient));
				} catch (RuntimeException e) {
					if (!lenient) {
						throw new XMLStreamException(format(
							"Invalid value for '%s'.", _name), e
						);
					} else {
						return null;
					}
				}
			}
		};
	}
788995
private String parseCT_Rst(XMLEventReader xmlEventReader) throws XMLStreamException {
    // Precondition: pointing to <si>;  Post condition: pointing to </si>
    StringBuilder buf = new StringBuilder();
    XMLEvent xmlEvent;
    while((xmlEvent = xmlEventReader.nextTag()).isStartElement()) {
      switch(xmlEvent.asStartElement().getName().getLocalPart()) {
        case "t": // Text
          buf.append(xmlEventReader.getElementText());
          break;
        case "r": // Rich Text Run
          parseCT_RElt(xmlEventReader, buf);
          break;
        case "rPh": // Phonetic Run
        case "phoneticPr": // Phonetic Properties
          skipElement(xmlEventReader);
          break;
        default:
          throw new IllegalArgumentException(xmlEvent.asStartElement().getName().getLocalPart());
      }
    }
    return buf.length() > 0 ? buf.toString() : null;
  }
1098186
public static Configuration loadFromString(String config)
    throws IOException, SAXException {
    ConfigurationImpl cfg = new ConfigurationImpl();

    XMLReader parser = XMLReaderFactory.createXMLReader();
    parser.setContentHandler(new ConfigHandler(cfg, null));
    Reader reader = new StringReader(config);
    parser.parse(new InputSource(reader));
    return cfg;
  }
406746
public static String createXMLFeatureDescriptor(
      final TrainingParameters params) throws IOException {

    final Element aggGenerators = new Element("generators");
    final Document doc = new Document(aggGenerators);

    // <generators>
    // <cache>
    // <generators>
    final Element cached = new Element("cache");
    final Element generators = new Element("generators");
    // <window prevLength="2" nextLength="2">
    // <token />
    // </window>
    if (Flags.isTokenFeature(params)) {
      setWindow(params);
      final String tokenFeatureRange = Flags.getTokenFeaturesRange(params);
      final Element tokenFeature = new Element("custom");
      tokenFeature.setAttribute("class", TokenFeatureGenerator.class.getName());
      tokenFeature.setAttribute("range", tokenFeatureRange);
      final Element tokenWindow = new Element("window");
      tokenWindow.setAttribute("prevLength", Integer.toString(leftWindow));
      tokenWindow.setAttribute("nextLength", Integer.toString(rightWindow));
      tokenWindow.addContent(tokenFeature);
      generators.addContent(tokenWindow);
      System.err.println("-> Token features added!: Window range " + leftWindow
          + ":" + rightWindow);
    }
    if (Flags.isTokenClassFeature(params)) {
      setWindow(params);
      final String tokenClassFeatureRange = Flags
          .getTokenClassFeaturesRange(params);
      final Element tokenClassFeature = new Element("custom");
      tokenClassFeature.setAttribute("class",
          TokenClassFeatureGenerator.class.getName());
      tokenClassFeature.setAttribute("range", tokenClassFeatureRange);
      final Element tokenClassWindow = new Element("window");
      tokenClassWindow.setAttribute("prevLength", Integer.toString(leftWindow));
      tokenClassWindow.setAttribute("nextLength",
          Integer.toString(rightWindow));
      tokenClassWindow.addContent(tokenClassFeature);
      generators.addContent(tokenClassWindow);
      System.err.println("-> Token Class Features added!: Window range "
          + leftWindow + ":" + rightWindow);
    }
    if (Flags.isWordShapeSuperSenseFeature(params)) {
      setWindow(params);
      final Element wordShapeSuperSenseFeature = new Element("custom");
      wordShapeSuperSenseFeature.setAttribute("class",
          WordShapeSuperSenseFeatureGenerator.class.getName());
      final Element wordShapeWindow = new Element("window");
      wordShapeWindow.setAttribute("prevLength", Integer.toString(leftWindow));
      wordShapeWindow.setAttribute("nextLength", Integer.toString(rightWindow));
      wordShapeWindow.addContent(wordShapeSuperSenseFeature);
      generators.addContent(wordShapeWindow);
      System.err
          .println("-> Word Shape SuperSense Features added!: Window range "
              + leftWindow + ":" + rightWindow);
    }
    if (Flags.isOutcomePriorFeature(params)) {
      final Element outcomePriorFeature = new Element("custom");
      outcomePriorFeature.setAttribute("class",
          OutcomePriorFeatureGenerator.class.getName());
      generators.addContent(outcomePriorFeature);
      System.err.println("-> Outcome Prior Features added!");
    }
    if (Flags.isPreviousMapFeature(params)) {
      final Element previousMapFeature = new Element("custom");
      previousMapFeature.setAttribute("class",
          PreviousMapFeatureGenerator.class.getName());
      generators.addContent(previousMapFeature);
      System.err.println("-> Previous Map Features added!");
    }
    if (Flags.isSentenceFeature(params)) {
      final String beginSentence = Flags.getSentenceFeaturesBegin(params);
      final String endSentence = Flags.getSentenceFeaturesEnd(params);
      final Element sentenceFeature = new Element("custom");
      sentenceFeature.setAttribute("class",
          SentenceFeatureGenerator.class.getName());
      sentenceFeature.setAttribute("begin", beginSentence);
      sentenceFeature.setAttribute("end", endSentence);
      generators.addContent(sentenceFeature);
      System.err.println("-> Sentence Features added!");
    }
    if (Flags.isPrefixFeature(params)) {
      final String beginPrefix = Flags.getPrefixFeaturesBegin(params);
      final String endPrefix = Flags.getPrefixFeaturesEnd(params);
      final Element prefixFeature = new Element("custom");
      prefixFeature.setAttribute("class",
          PrefixFeatureGenerator.class.getName());
      prefixFeature.setAttribute("begin", beginPrefix);
      prefixFeature.setAttribute("end", endPrefix);
      generators.addContent(prefixFeature);
      System.err.println("-> Prefix Features added!");
    }
    if (Flags.isSuffixFeature(params)) {
      final String beginSuffix = Flags.getSuffixFeaturesBegin(params);
      final String endSuffix = Flags.getSuffixFeaturesEnd(params);
      final Element suffixFeature = new Element("custom");
      suffixFeature.setAttribute("class",
          SuffixFeatureGenerator.class.getName());
      suffixFeature.setAttribute("begin", beginSuffix);
      suffixFeature.setAttribute("end", endSuffix);
      generators.addContent(suffixFeature);
      System.err.println("-> Suffix Features added!");
    }
    if (Flags.isBigramClassFeature(params)) {
      final Element bigramFeature = new Element("custom");
      bigramFeature.setAttribute("class",
          BigramClassFeatureGenerator.class.getName());
      generators.addContent(bigramFeature);
      System.err.println("-> Bigram Class Features added!");
    }
    if (Flags.isTrigramClassFeature(params)) {
      final Element trigramFeature = new Element("custom");
      trigramFeature.setAttribute("class",
          TrigramClassFeatureGenerator.class.getName());
      generators.addContent(trigramFeature);
      System.err.println("-> Trigram Class Features added!");
    }
    if (Flags.isFourgramClassFeature(params)) {
      final Element fourgramFeature = new Element("custom");
      fourgramFeature.setAttribute("class",
          FourgramClassFeatureGenerator.class.getName());
      generators.addContent(fourgramFeature);
      System.err.println("-> Fourgram Class Features added!");
    }
    if (Flags.isFivegramClassFeature(params)) {
      final Element fivegramFeature = new Element("custom");
      fivegramFeature.setAttribute("class",
          FivegramClassFeatureGenerator.class.getName());
      generators.addContent(fivegramFeature);
      System.err.println("-> Fivegram Class Features added!");
    }
    if (Flags.isCharNgramClassFeature(params)) {
      final String charngramRange = Flags.getCharNgramFeaturesRange(params);
      final String[] rangeArray = Flags.processNgramRange(charngramRange);
      final Element charngramFeature = new Element("custom");
      charngramFeature.setAttribute("class",
          CharacterNgramFeatureGenerator.class.getName());
      charngramFeature.setAttribute("minLength", rangeArray[0]);
      charngramFeature.setAttribute("maxLength", rangeArray[1]);
      generators.addContent(charngramFeature);
      System.err.println("-> CharNgram Class Features added!");
    }
    // Dictionary Features
    if (Flags.isDictionaryFeatures(params)) {
      setWindow(params);
      final String dictPath = Flags.getDictionaryFeatures(params);
      final String seqCodec = Flags.getSequenceCodec(params);
      final List<File> fileList = StringUtils.getFilesInDir(new File(dictPath));
      for (final File dictFile : fileList) {
        final Element dictFeatures = new Element("custom");
        dictFeatures.setAttribute("class",
            DictionaryFeatureGenerator.class.getName());
        dictFeatures.setAttribute("dict",
            IOUtils.normalizeLexiconName(dictFile.getName()));
        dictFeatures.setAttribute("seqCodec", seqCodec);
        final Element dictWindow = new Element("window");
        dictWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        dictWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        dictWindow.addContent(dictFeatures);
        generators.addContent(dictWindow);
      }
      System.err.println("-> Dictionary Features added!");
    }
    // Brown clustering features
    if (Flags.isBrownFeatures(params)) {
      setWindow(params);
      // previous 2 maps features
      final Element prev2MapFeature = new Element("custom");
      prev2MapFeature.setAttribute("class",
          Prev2MapFeatureGenerator.class.getName());
      generators.addContent(prev2MapFeature);
      // previous map and token feature (in window)
      final Element prevMapTokenFeature = new Element("custom");
      prevMapTokenFeature.setAttribute("class",
          PreviousMapTokenFeatureGenerator.class.getName());
      final Element prevMapTokenWindow = new Element("window");
      prevMapTokenWindow.setAttribute("prevLength",
          Integer.toString(leftWindow));
      prevMapTokenWindow.setAttribute("nextLength",
          Integer.toString(rightWindow));
      prevMapTokenWindow.addContent(prevMapTokenFeature);
      generators.addContent(prevMapTokenWindow);
      // brown clustering features
      final String brownClusterPath = Flags.getBrownFeatures(params);
      final List<File> brownClusterFiles = Flags
          .getClusterLexiconFiles(brownClusterPath);
      for (final File brownClusterFile : brownClusterFiles) {
        // brown bigram class features
        final Element brownBigramFeatures = new Element("custom");
        brownBigramFeatures.setAttribute("class",
            BrownBigramFeatureGenerator.class.getName());
        brownBigramFeatures.setAttribute("dict",
            IOUtils.normalizeLexiconName(brownClusterFile.getName()));
        generators.addContent(brownBigramFeatures);
        // brown token feature
        final Element brownTokenFeature = new Element("custom");
        brownTokenFeature.setAttribute("class",
            BrownTokenFeatureGenerator.class.getName());
        brownTokenFeature.setAttribute("dict",
            IOUtils.normalizeLexiconName(brownClusterFile.getName()));
        final Element brownTokenWindow = new Element("window");
        brownTokenWindow.setAttribute("prevLength",
            Integer.toString(leftWindow));
        brownTokenWindow.setAttribute("nextLength",
            Integer.toString(rightWindow));
        brownTokenWindow.addContent(brownTokenFeature);
        generators.addContent(brownTokenWindow);
        // brown token class feature
        final Element brownTokenClassFeature = new Element("custom");
        brownTokenClassFeature.setAttribute("class",
            BrownTokenClassFeatureGenerator.class.getName());
        brownTokenClassFeature.setAttribute("dict",
            IOUtils.normalizeLexiconName(brownClusterFile.getName()));
        final Element brownTokenClassWindow = new Element("window");
        brownTokenClassWindow.setAttribute("prevLength",
            Integer.toString(leftWindow));
        brownTokenClassWindow.setAttribute("nextLength",
            Integer.toString(rightWindow));
        brownTokenClassWindow.addContent(brownTokenClassFeature);
        generators.addContent(brownTokenClassWindow);
      }
      System.err.println("-> Brown Cluster Features added!");
    }
    // Clark clustering features
    if (Flags.isClarkFeatures(params)) {
      setWindow(params);
      final String clarkClusterPath = Flags.getClarkFeatures(params);
      final List<File> clarkClusterFiles = Flags
          .getClusterLexiconFiles(clarkClusterPath);
      for (final File clarkCluster : clarkClusterFiles) {
        final Element clarkFeatures = new Element("custom");
        clarkFeatures.setAttribute("class",
            ClarkFeatureGenerator.class.getName());
        clarkFeatures.setAttribute("dict",
            IOUtils.normalizeLexiconName(clarkCluster.getName()));
        final Element clarkWindow = new Element("window");
        clarkWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        clarkWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        clarkWindow.addContent(clarkFeatures);
        generators.addContent(clarkWindow);
      }
      System.err.println("-> Clark Cluster Features added!");
    }
    // word2vec clustering features
    if (Flags.isWord2VecClusterFeatures(params)) {
      setWindow(params);
      final String word2vecClusterPath = Flags
          .getWord2VecClusterFeatures(params);
      final List<File> word2vecClusterFiles = Flags
          .getClusterLexiconFiles(word2vecClusterPath);
      for (final File word2vecFile : word2vecClusterFiles) {
        final Element word2vecClusterFeatures = new Element("custom");
        word2vecClusterFeatures.setAttribute("class",
            Word2VecClusterFeatureGenerator.class.getName());
        word2vecClusterFeatures.setAttribute("dict",
            IOUtils.normalizeLexiconName(word2vecFile.getName()));
        final Element word2vecClusterWindow = new Element("window");
        word2vecClusterWindow.setAttribute("prevLength",
            Integer.toString(leftWindow));
        word2vecClusterWindow.setAttribute("nextLength",
            Integer.toString(rightWindow));
        word2vecClusterWindow.addContent(word2vecClusterFeatures);
        generators.addContent(word2vecClusterWindow);
      }
      System.err.println("-> Word2Vec Clusters Features added!");
    }
    // Morphological features
    if (Flags.isPOSTagModelFeatures(params)) {
      setWindow(params);
      final String posModelPath = Flags.getPOSTagModelFeatures(params);
      final String posModelRange = Flags.getPOSTagModelFeaturesRange(params);
      final Element posTagClassFeatureElement = new Element("custom");
      posTagClassFeatureElement.setAttribute("class",
          POSTagModelFeatureGenerator.class.getName());
      posTagClassFeatureElement.setAttribute("model",
          IOUtils.normalizeLexiconName(new File(posModelPath).getName()));
      posTagClassFeatureElement.setAttribute("range", posModelRange);
      final Element posTagClassFeatureWindow = new Element("window");
      posTagClassFeatureWindow.setAttribute("prevLength",
          Integer.toString(leftWindow));
      posTagClassFeatureWindow.setAttribute("nextLength",
          Integer.toString(rightWindow));
      posTagClassFeatureWindow.addContent(posTagClassFeatureElement);
      generators.addContent(posTagClassFeatureWindow);
      System.err.println("-> POSTagModel Features added!");
    }
    if (Flags.isPOSDictionaryFeatures(params)) {
      setWindow(params);
      final String posDictPath = Flags.getPOSDictionaryFeatures(params);
      final Element posDictFeatures = new Element("custom");
      posDictFeatures.setAttribute("class",
          POSDictionaryFeatureGenerator.class.getName());
      posDictFeatures.setAttribute("dict",
          IOUtils.normalizeLexiconName(new File(posDictPath).getName()));
      final Element posDictWindow = new Element("window");
      posDictWindow.setAttribute("prevLength", Integer.toString(leftWindow));
      posDictWindow.setAttribute("nextLength", Integer.toString(rightWindow));
      posDictWindow.addContent(posDictFeatures);
      generators.addContent(posDictWindow);
      System.err.println("-> POSDictionary Features added!");
    }
    if (Flags.isLemmaModelFeatures(params)) {
      setWindow(params);
      final String lemmaModelPath = Flags.getLemmaModelFeatures(params);
      final Element lemmaClassFeatureElement = new Element("custom");
      lemmaClassFeatureElement.setAttribute("class",
          LemmaModelFeatureGenerator.class.getName());
      lemmaClassFeatureElement.setAttribute("model",
          IOUtils.normalizeLexiconName(new File(lemmaModelPath).getName()));
      final Element lemmaClassFeatureWindow = new Element("window");
      lemmaClassFeatureWindow.setAttribute("prevLength",
          Integer.toString(leftWindow));
      lemmaClassFeatureWindow.setAttribute("nextLength",
          Integer.toString(rightWindow));
      lemmaClassFeatureWindow.addContent(lemmaClassFeatureElement);
      generators.addContent(lemmaClassFeatureWindow);
      System.err.println("-> LemmaModel Features added!");
    }
    if (Flags.isLemmaDictionaryFeatures(params)) {
      setWindow(params);
      final String lemmaDictPath = Flags.getLemmaDictionaryFeatures(params);
      final String[] lemmaDictResources = Flags
          .getLemmaDictionaryResources(lemmaDictPath);
      final Element lemmaClassFeatureElement = new Element("custom");
      lemmaClassFeatureElement.setAttribute("class",
          LemmaDictionaryFeatureGenerator.class.getName());
      lemmaClassFeatureElement.setAttribute("model", IOUtils
          .normalizeLexiconName(new File(lemmaDictResources[0]).getName()));
      lemmaClassFeatureElement.setAttribute("dict", IOUtils
          .normalizeLexiconName(new File(lemmaDictResources[1]).getName()));
      final Element lemmaClassFeatureWindow = new Element("window");
      lemmaClassFeatureWindow.setAttribute("prevLength",
          Integer.toString(leftWindow));
      lemmaClassFeatureWindow.setAttribute("nextLength",
          Integer.toString(rightWindow));
      lemmaClassFeatureWindow.addContent(lemmaClassFeatureElement);
      generators.addContent(lemmaClassFeatureWindow);
      System.err.println("-> LemmaDictionary Features added!");
    }
    if (Flags.isMFSFeatures(params)) {
      setWindow(params);
      final String mfsPath = Flags.getMFSFeatures(params);
      final String[] mfsResources = Flags.getMFSResources(mfsPath);
      final String mfsRange = Flags.getMFSFeaturesRange(params);
      final String seqCodec = Flags.getSequenceCodec(params);
      final Element mfsClassFeatureElement = new Element("custom");
      mfsClassFeatureElement.setAttribute("class",
          MFSFeatureGenerator.class.getName());
      mfsClassFeatureElement.setAttribute("model",
          IOUtils.normalizeLexiconName(new File(mfsResources[0]).getName()));
      mfsClassFeatureElement.setAttribute("dict",
          IOUtils.normalizeLexiconName(new File(mfsResources[1]).getName()));
      mfsClassFeatureElement.setAttribute("mfs",
          IOUtils.normalizeLexiconName(new File(mfsResources[2]).getName()));
      mfsClassFeatureElement.setAttribute("range", mfsRange);
      mfsClassFeatureElement.setAttribute("seqCodec", seqCodec);
      final Element mfsClassFeatureWindow = new Element("window");
      mfsClassFeatureWindow.setAttribute("prevLength",
          Integer.toString(leftWindow));
      mfsClassFeatureWindow.setAttribute("nextLength",
          Integer.toString(rightWindow));
      mfsClassFeatureWindow.addContent(mfsClassFeatureElement);
      generators.addContent(mfsClassFeatureWindow);
      System.err.println("-> MFS Features added");
    }
    if (Flags.isSuperSenseFeatures(params)) {
      final String mfsPath = Flags.getSuperSenseFeatures(params);
      final String[] mfsResources = Flags.getSuperSenseResources(mfsPath);
      final String mfsRange = Flags.getSuperSenseFeaturesRange(params);
      final String seqCodec = Flags.getSequenceCodec(params);
      final Element mfsClassFeatureElement = new Element("custom");
      mfsClassFeatureElement.setAttribute("class",
          SuperSenseFeatureGenerator.class.getName());
      mfsClassFeatureElement.setAttribute("model",
          IOUtils.normalizeLexiconName(new File(mfsResources[0]).getName()));
      mfsClassFeatureElement.setAttribute("dict",
          IOUtils.normalizeLexiconName(new File(mfsResources[1]).getName()));
      mfsClassFeatureElement.setAttribute("mfs",
          IOUtils.normalizeLexiconName(new File(mfsResources[2]).getName()));
      mfsClassFeatureElement.setAttribute("range", mfsRange);
      mfsClassFeatureElement.setAttribute("seqCodec", seqCodec);
      generators.addContent(mfsClassFeatureElement);
      System.err.println("-> SuperSense Features added!");
    }
    if (Flags.isPOSBaselineFeatures(params)) {
      final String beginPrefix = Flags.getPrefixBegin(params);
      final String endPrefix = Flags.getPrefixEnd(params);
      final String beginSuffix = Flags.getSuffixBegin(params);
      final String endSuffix = Flags.getSuffixEnd(params);
      final Element posFeatureElement = new Element("custom");
      posFeatureElement.setAttribute("class",
          POSBaselineContextGenerator.class.getName());
      posFeatureElement.setAttribute("prefBegin", beginPrefix);
      posFeatureElement.setAttribute("prefEnd", endPrefix);
      posFeatureElement.setAttribute("sufBegin", beginSuffix);
      posFeatureElement.setAttribute("sufEnd", endSuffix);
      generators.addContent(posFeatureElement);
      System.err.println("-> POS Baseline Context Generator added!");
    }
    if (Flags.isLemmaBaselineFeatures(params)) {
      final String beginPrefix = Flags.getPrefixBegin(params);
      final String endPrefix = Flags.getPrefixEnd(params);
      final String beginSuffix = Flags.getSuffixBegin(params);
      final String endSuffix = Flags.getSuffixEnd(params);
      final String posModel = Flags.getLemmaBaselineFeatures(params);
      final String lemmaRange = Flags.getLemmaBaselineFeaturesRange(params);
      final Element lemmaFeatureElement = new Element("custom");
      lemmaFeatureElement.setAttribute("class",
          LemmaBaselineContextGenerator.class.getName());
      lemmaFeatureElement.setAttribute("prefBegin", beginPrefix);
      lemmaFeatureElement.setAttribute("prefEnd", endPrefix);
      lemmaFeatureElement.setAttribute("sufBegin", beginSuffix);
      lemmaFeatureElement.setAttribute("sufEnd", endSuffix);
      lemmaFeatureElement.setAttribute("model",
          IOUtils.normalizeLexiconName(new File(posModel).getName()));
      lemmaFeatureElement.setAttribute("range", lemmaRange);
      generators.addContent(lemmaFeatureElement);
      System.err.println("-> Lemma Baseline Context Generator added!");
    }
    if (Flags.isChunkBaselineFeatures(params)) {
      final String posModel = Flags.getChunkBaselineFeatures(params);
      final Element chunkFeatureElement = new Element("custom");
      chunkFeatureElement.setAttribute("class",
          ChunkBaselineContextGenerator.class.getName());
      chunkFeatureElement.setAttribute("model",
          IOUtils.normalizeLexiconName(new File(posModel).getName()));
      generators.addContent(chunkFeatureElement);
      System.err.println("-> Chunk Baseline Context Generator added!");
    }

    if (Flags.isPredicateContextFeatures(params)) {
      final String predicateContextFile = Flags
          .getPredicateContextFeatures(params);
      final Element predicateContextFeatureElement = new Element("custom");
      predicateContextFeatureElement.setAttribute("class",
          PredicateContextFeatureGenerator.class.getName());
      predicateContextFeatureElement.setAttribute("dict", IOUtils
          .normalizeLexiconName(new File(predicateContextFile).getName()));
      generators.addContent(predicateContextFeatureElement);
      System.err.println("-> Predicate Context Generator added!");
    }

    aggGenerators.addContent(cached);
    cached.addContent(generators);

    final XMLOutputter xmlOutput = new XMLOutputter();
    final Format format = Format.getPrettyFormat();
    xmlOutput.setFormat(format);
    return xmlOutput.outputString(doc);

  }
685801
private String readCharactersUntilEndOfArgument(XMLEventReader reader,
                                                    QName tagName,
                                                    String methodName,
                                                    String argumentName,
                                                    String argumentType)
            throws XMLStreamException, JournalException {
        StringBuffer stringValue = new StringBuffer();
        while (true) {
            XMLEvent event = reader.nextEvent();
            if (event.isCharacters()) {
                stringValue.append(event.asCharacters().getData());
            } else if (isEndTagEvent(event, tagName)) {
                break;
            } else {
                throw getUnexpectedEventInArgumentException(argumentName,
                                                            argumentType,
                                                            methodName,
                                                            event);
            }
        }
        return stringValue.toString();
    }
947064
private static Object readParam(DataInput reader) throws IOException {
		int type = reader.readUnsignedByte();
		switch (type) {
		case BYTE_ID:
			return Byte.valueOf(reader.readByte());
		case SHORT_ID:
			return Short.valueOf(reader.readShort());
		case INTEGER_ID:
			return Integer.valueOf(reader.readInt());
		case CHAR_ID:
			return Character.valueOf(reader.readChar());
		case LONG_ID:
			return Long.valueOf(reader.readLong());
		case FLOAT_ID:
			return Float.valueOf(reader.readFloat());
		case DOUBLE_ID:
			return Double.valueOf(reader.readDouble());
		case DATE_ID:
			return new Date(reader.readLong());
		case STRING_ID:
			return readString(reader);
		case NULL_ID:
			return null;
		}
		throw new DeserializerException("Wrong type of a parameter", "one of the B,S,I,C,L,F,D,T,O,N", Character.toString((char)type));
	}
672991
public static synchronized XMLEventReader createFileReader(final File paramFile) throws IOException,
        XMLStreamException {
        final XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        final InputStream in = new FileInputStream(paramFile);
        return factory.createXMLEventReader(in);
    }
202586
public UnprotectedStringBuffer readInnerText() throws XMLException, IOException {
		if (!Type.START_ELEMENT.equals(event.type))
throw new IOException("Invalid call of readInnerText: it must be called on a start element, current event type is: " + event.type);
		if (event.isClosed) return new UnprotectedStringBuffer();
		UnprotectedStringBuffer elementName = event.text;
		UnprotectedStringBuffer innerText = new UnprotectedStringBuffer();
		do {
			try { next(); }
			catch (EOFException e) {
				throw new XMLException(getPosition(), "Unexpected end", "readInnerText(" + elementName.toString() + ")");
			}
			if (Type.COMMENT.equals(event.type)) continue;
			if (Type.TEXT.equals(event.type)) {
				innerText.append(event.text);
				continue;
			}
			if (Type.START_ELEMENT.equals(event.type)) {
				closeElement();
				continue;
			}
			if (Type.END_ELEMENT.equals(event.type)) {
				if (!event.text.equals(elementName))
					throw new XMLException(getPosition(), "Unexpected end element", event.text.asString());
				return innerText;
			}
		} while (true);
	}
1282194
public static Document string2Doc(String inputXMLString, boolean namespaceAwareness) {
        try {
            return XmlDocumentReader.parse(inputXMLString, false);
        } catch (IOException | SAXException e) {
            log.error("Cannot parse XML string.", e);
            return null;
        }
//        try {
//            DocumentBuilder builder = getDocumentBuilder(namespaceAwareness);
//            InputSource is = new InputSource(new StringReader(inputXMLString));
//            is.setEncoding("UTF-8");
//            return builder.parse(is);
//        } catch (SAXException | ParserConfigurationException | IOException e) {
//            log.error("cannot parse following content\n\n" + inputXMLString);
//            e.printStackTrace();
//            return null;
//        }
    }
175340
public static JsonNode stringToJsonNode(String paramName, String val) {
        if (val == null) {
            return null;
        }
        try {
            return MAPPER.readTree(val);
        } catch (IOException e) {
            throw new SdkClientException(paramName + " must be a valid JSON document", e);
        }
    }
449678
String readString() throws IOException {
		StringBuilder sb = new StringBuilder(50);
		// first char must be ":
		char ch = reader.next();
		if (ch != '\"') {
			throw new JsonParseException("Expected \" but actual is: " + ch,
					reader.readed);
		}
		for (;;) {
			ch = reader.next();
			if (ch == '\\') {
				// escape: \" \\ \/ \b \f \n \r \t
				char ech = reader.next();
				switch (ech) {
				case '\"':
					sb.append('\"');
					break;
				case '\\':
					sb.append('\\');
					break;
				case '/':
					sb.append('/');
					break;
				case 'b':
					sb.append('\b');
					break;
				case 'f':
					sb.append('\f');
					break;
				case 'n':
					sb.append('\n');
					break;
				case 'r':
					sb.append('\r');
					break;
				case 't':
					sb.append('\t');
					break;
				case 'u':
					// read an unicode uXXXX:
					int u = 0;
					for (int i = 0; i < 4; i++) {
						char uch = reader.next();
						if (uch >= '0' && uch <= '9') {
							u = (u << 4) + (uch - '0');
						} else if (uch >= 'a' && uch <= 'f') {
							u = (u << 4) + (uch - 'a') + 10;
						} else if (uch >= 'A' && uch <= 'F') {
							u = (u << 4) + (uch - 'A') + 10;
						} else {
							throw new JsonParseException("Unexpected char: " + uch,
									reader.readed);
						}
					}
					sb.append((char) u);
					break;
				default:
					throw new JsonParseException("Unexpected char: " + ch,
							reader.readed);
				}
			} else if (ch == '\"') {
				// end of string:
				break;
			} else if (ch == '\r' || ch == '\n') {
				throw new JsonParseException("Unexpected char: " + ch,
						reader.readed);
			} else {
				sb.append(ch);
			}
		}
		return sb.toString();
	}
229874
public synchronized Node parse(InputStream in) throws IOException, SAXException {
        //_dtd=null;
        Handler handler = new Handler();
        XMLReader reader = _parser.getXMLReader();
        reader.setContentHandler(handler);
        reader.setErrorHandler(handler);
        reader.setEntityResolver(handler);
        _parser.parse(new InputSource(in), handler);
        if (handler.error != null)
            throw handler.error;
        Node root = (Node)handler.root;
        handler.reset();
        return root;
    }
378898
@Override
    public XMLEventReader createXMLEventReader(InputStream in)
        throws XMLStreamException
    {
        // false for auto-close, since caller has access to the input stream
        return new WstxEventReader(createEventAllocator(),
        		createSR(null, in, null, true, false));
    }
1145928
protected XMLEvent readStartTag(XMLEventReader reader, QName tagName)
            throws XMLStreamException, JournalException {
        XMLEvent event = reader.nextTag();
        if (!isStartTagEvent(event, tagName)) {
            throw getNotStartTagException(tagName, event);
        }
        return event;
    }