Java Code Examples for javax.xml.stream.XMLStreamWriter#writeComment()

The following examples show how to use javax.xml.stream.XMLStreamWriter#writeComment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EwsServiceXmlWriter.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * @param xmlNode XML node
 * @param xmlStreamWriter XML stream writer
 * @throws XMLStreamException the XML stream exception
 */
public static void writeNode(Node xmlNode, XMLStreamWriter xmlStreamWriter)
    throws XMLStreamException {
  if (xmlNode instanceof Element) {
    addElement((Element) xmlNode, xmlStreamWriter);
  } else if (xmlNode instanceof Text) {
    xmlStreamWriter.writeCharacters(xmlNode.getNodeValue());
  } else if (xmlNode instanceof CDATASection) {
    xmlStreamWriter.writeCData(((CDATASection) xmlNode).getData());
  } else if (xmlNode instanceof Comment) {
    xmlStreamWriter.writeComment(((Comment) xmlNode).getData());
  } else if (xmlNode instanceof EntityReference) {
    xmlStreamWriter.writeEntityRef(xmlNode.getNodeValue());
  } else if (xmlNode instanceof ProcessingInstruction) {
    ProcessingInstruction procInst = (ProcessingInstruction) xmlNode;
    xmlStreamWriter.writeProcessingInstruction(procInst.getTarget(),
        procInst.getData());
  } else if (xmlNode instanceof Document) {
    writeToDocument((Document) xmlNode, xmlStreamWriter);
  }
}
 
Example 2
Source File: DOMUtil.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Traverses a DOM node and writes out on a streaming writer.
 *
 * @param node
 * @param writer
 */
public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException {
    writeTagWithAttributes(node, writer);

    if (node.hasChildNodes()) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            switch (child.getNodeType()) {
                case Node.PROCESSING_INSTRUCTION_NODE:
                    writer.writeProcessingInstruction(child.getNodeValue());
                    break;
                case Node.DOCUMENT_TYPE_NODE:
                    break;
                case Node.CDATA_SECTION_NODE:
                    writer.writeCData(child.getNodeValue());
                    break;
                case Node.COMMENT_NODE:
                    writer.writeComment(child.getNodeValue());
                    break;
                case Node.TEXT_NODE:
                    writer.writeCharacters(child.getNodeValue());
                    break;
                case Node.ELEMENT_NODE:
                    serializeNode((Element) child, writer);
                    break;
                default: break;
            }
        }
    }
    writer.writeEndElement();
}
 
Example 3
Source File: DOMUtil.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Traverses a DOM node and writes out on a streaming writer.
 *
 * @param node
 * @param writer
 */
public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException {
    writeTagWithAttributes(node, writer);

    if (node.hasChildNodes()) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            switch (child.getNodeType()) {
                case Node.PROCESSING_INSTRUCTION_NODE:
                    writer.writeProcessingInstruction(child.getNodeValue());
                    break;
                case Node.DOCUMENT_TYPE_NODE:
                    break;
                case Node.CDATA_SECTION_NODE:
                    writer.writeCData(child.getNodeValue());
                    break;
                case Node.COMMENT_NODE:
                    writer.writeComment(child.getNodeValue());
                    break;
                case Node.TEXT_NODE:
                    writer.writeCharacters(child.getNodeValue());
                    break;
                case Node.ELEMENT_NODE:
                    serializeNode((Element) child, writer);
                    break;
                default: break;
            }
        }
    }
    writer.writeEndElement();
}
 
Example 4
Source File: frmSettings.java    From Course_Generator with GNU General Public License v3.0 5 votes vote down vote up
private void SaveTheme() {
	String s = Utils.SaveDialog(this, DataDir + "/" + CgConst.CG_DIR + "/themes/", "", ".theme",
			bundle.getString("frmMain.themeFile"), true, bundle.getString("frmMain.FileExist"));

	if (!s.isEmpty()) {
		// -- Save the data in the home directory
		XMLOutputFactory factory = XMLOutputFactory.newInstance();
		try {
			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(s));
			XMLStreamWriter writer = new IndentingXMLStreamWriter(
					factory.createXMLStreamWriter(bufferedOutputStream, "UTF-8"));

			writer.writeStartDocument("UTF-8", "1.0");
			writer.writeComment("Course Generator (C) Pierre DELORE");
			writer.writeStartElement("THEME");
			Utils.WriteIntToXML(writer, "COLORDIFFVERYEASY", ColorVeryEasy.getRGB());
			Utils.WriteIntToXML(writer, "COLORDIFFEASY", ColorEasy.getRGB());
			Utils.WriteIntToXML(writer, "COLORDIFFAVERAGE", ColorAverage.getRGB());
			Utils.WriteIntToXML(writer, "COLORDIFFHARD", ColorHard.getRGB());
			Utils.WriteIntToXML(writer, "COLORDIFFVERYHARD", ColorVeryHard.getRGB());
			Utils.WriteIntToXML(writer, "COLORNIGHT", ColorNight.getRGB());
			Utils.WriteIntToXML(writer, "NORMALTRACKWIDTH", spinNormalTrackWidth.getValueAsInt());
			Utils.WriteIntToXML(writer, "NIGHTTRACKWIDTH", spinNightTrackWidth.getValueAsInt());
			Utils.WriteIntToXML(writer, "NORMALTRACKTRANSPARENCY", spinNormalTrackTransparency.getValueAsInt());
			Utils.WriteIntToXML(writer, "NIGHTTRACKTRANSPARENCY", spinNightTrackTransparency.getValueAsInt());

			writer.writeEndElement();
			writer.writeEndDocument();

			writer.flush();
			writer.close();
			bufferedOutputStream.close();
		} catch (XMLStreamException | IOException e) {
			e.printStackTrace();
		}
	}
}
 
Example 5
Source File: DOMUtil.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Traverses a DOM node and writes out on a streaming writer.
 *
 * @param node
 * @param writer
 */
public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException {
    writeTagWithAttributes(node, writer);

    if (node.hasChildNodes()) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            switch (child.getNodeType()) {
                case Node.PROCESSING_INSTRUCTION_NODE:
                    writer.writeProcessingInstruction(child.getNodeValue());
                    break;
                case Node.DOCUMENT_TYPE_NODE:
                    break;
                case Node.CDATA_SECTION_NODE:
                    writer.writeCData(child.getNodeValue());
                    break;
                case Node.COMMENT_NODE:
                    writer.writeComment(child.getNodeValue());
                    break;
                case Node.TEXT_NODE:
                    writer.writeCharacters(child.getNodeValue());
                    break;
                case Node.ELEMENT_NODE:
                    serializeNode((Element) child, writer);
                    break;
                default: break;
            }
        }
    }
    writer.writeEndElement();
}
 
Example 6
Source File: DOMUtil.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Traverses a DOM node and writes out on a streaming writer.
 *
 * @param node
 * @param writer
 */
public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException {
    writeTagWithAttributes(node, writer);

    if (node.hasChildNodes()) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            switch (child.getNodeType()) {
                case Node.PROCESSING_INSTRUCTION_NODE:
                    writer.writeProcessingInstruction(child.getNodeValue());
                    break;
                case Node.DOCUMENT_TYPE_NODE:
                    break;
                case Node.CDATA_SECTION_NODE:
                    writer.writeCData(child.getNodeValue());
                    break;
                case Node.COMMENT_NODE:
                    writer.writeComment(child.getNodeValue());
                    break;
                case Node.TEXT_NODE:
                    writer.writeCharacters(child.getNodeValue());
                    break;
                case Node.ELEMENT_NODE:
                    serializeNode((Element) child, writer);
                    break;
                default: break;
            }
        }
    }
    writer.writeEndElement();
}
 
Example 7
Source File: CfgPrune.java    From aion with MIT License 5 votes vote down vote up
public void toXML(XMLStreamWriter xmlWriter) throws XMLStreamException {
    xmlWriter.writeCharacters("\r\n\t\t");
    xmlWriter.writeStartElement("prune");

    xmlWriter.writeCharacters("\r\n\t\t\t");
    xmlWriter.writeComment("Boolean value. Enable/disable database pruning.");
    xmlWriter.writeCharacters("\r\n\t\t\t");
    xmlWriter.writeStartElement("enabled");
    xmlWriter.writeCharacters(String.valueOf(this.enabled));
    xmlWriter.writeEndElement();

    xmlWriter.writeCharacters("\r\n\t\t\t");
    xmlWriter.writeComment("Boolean value. Enable/disable database archiving.");
    xmlWriter.writeCharacters("\r\n\t\t\t");
    xmlWriter.writeStartElement("archived");
    xmlWriter.writeCharacters(String.valueOf(this.archived));
    xmlWriter.writeEndElement();

    xmlWriter.writeCharacters("\r\n\t\t\t");
    xmlWriter.writeComment(
            "Integer value with minimum set to 128. Only blocks older than best block level minus this number are candidates for pruning.");
    xmlWriter.writeCharacters("\r\n\t\t\t");
    xmlWriter.writeStartElement("current_count");
    xmlWriter.writeCharacters(String.valueOf(this.current_count));
    xmlWriter.writeEndElement();

    xmlWriter.writeCharacters("\r\n\t\t\t");
    xmlWriter.writeComment(
            "Integer value with minimum set to 1000. States for blocks that are exact multiples of this number will not be pruned.");
    xmlWriter.writeCharacters("\r\n\t\t\t");
    xmlWriter.writeStartElement("archive_rate");
    xmlWriter.writeCharacters(String.valueOf(this.archive_rate));
    xmlWriter.writeEndElement();

    xmlWriter.writeCharacters("\r\n\t\t");
    xmlWriter.writeEndElement();
}
 
Example 8
Source File: DefaultNSWriter.java    From softwarecave with GNU General Public License v3.0 5 votes vote down vote up
private void writeBooksElem(XMLStreamWriter writer, List<Book> books) throws XMLStreamException {
    writer.writeStartDocument("utf-8", "1.0");
    writer.writeComment("Describes list of books");
    
    writer.setDefaultNamespace(NS);
    writer.writeStartElement(NS, "books");
    writer.writeDefaultNamespace(NS);
    for (Book book : books)
        writeBookElem(writer, book);
    writer.writeEndElement();

    writer.writeEndDocument();
}
 
Example 9
Source File: DOMUtil.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Traverses a DOM node and writes out on a streaming writer.
 *
 * @param node
 * @param writer
 */
public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException {
    writeTagWithAttributes(node, writer);

    if (node.hasChildNodes()) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            switch (child.getNodeType()) {
                case Node.PROCESSING_INSTRUCTION_NODE:
                    writer.writeProcessingInstruction(child.getNodeValue());
                    break;
                case Node.DOCUMENT_TYPE_NODE:
                    break;
                case Node.CDATA_SECTION_NODE:
                    writer.writeCData(child.getNodeValue());
                    break;
                case Node.COMMENT_NODE:
                    writer.writeComment(child.getNodeValue());
                    break;
                case Node.TEXT_NODE:
                    writer.writeCharacters(child.getNodeValue());
                    break;
                case Node.ELEMENT_NODE:
                    serializeNode((Element) child, writer);
                    break;
                default: break;
            }
        }
    }
    writer.writeEndElement();
}
 
Example 10
Source File: SolrSchemaXMLWriter.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
	 * Automatically add fields to the schema depending on qualities in the current GOlrField.
	 * 
	 * @param field GOlrField
	 * @param xml
	 * @throws XMLStreamException
	 */
	private void generateAutomaticFields(GOlrField field, XMLStreamWriter xml) throws XMLStreamException{

		// Detect whether we need to automatically add _*_map mapping information.
		// Work on either "list" or "closure".
		Pattern pcl = Pattern.compile("(.*)_closure_label$");
		Pattern pll = Pattern.compile("(.*)_list_label$");
		Matcher clmatch = pcl.matcher(field.id);
		Matcher llmatch = pll.matcher(field.id);

		// See if it's one of the above.
		String baseName = null;
		String mtype = null;
		if( clmatch.matches() ){
			baseName = clmatch.group(1);
			mtype = "_closure_map";
		}else if( llmatch.matches() ){
			baseName = llmatch.group(1);
			mtype = "_list_map";
		}
		
		if( mtype != null ){
			
			// NOTE: See comments below.
			xml.writeComment(" Automatically created to capture mapping information ");
			xml.writeComment(" between " + baseName + "_(list|closure) and " + field.id + ".");
			xml.writeComment(" It is not indexed for searching (JSON blob), but may be useful to the client. ");
			xml.writeStartElement("field"); // <field>
			xml.writeAttribute("name", baseName + mtype);
			xml.writeAttribute("type", "string");
			xml.writeAttribute("required", "false");
			xml.writeAttribute("multiValued", "false");
			xml.writeAttribute("indexed", "false");
			xml.writeAttribute("stored", "true");
			xml.writeEndElement(); // </field>
		}
}
 
Example 11
Source File: WinnowAnalyzedElevate.java    From quaerite with Apache License 2.0 5 votes vote down vote up
private void commentElevate(XMLStreamWriter out, Elevate elevate) throws XMLStreamException {
    StringWriter writer = new StringWriter();
    XMLStreamWriter comment = XMLOutputFactory.newInstance()
            .createXMLStreamWriter(writer);
    writeElevate(comment, elevate);
    comment.writeCharacters("\n");
    writer.flush();
    out.writeCharacters("\n");
    out.writeComment(writer.toString());
}
 
Example 12
Source File: CfgDb.java    From aion with MIT License 4 votes vote down vote up
public String toXML() {
    final XMLOutputFactory output = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlWriter;
    String xml;
    try {
        Writer strWriter = new StringWriter();
        xmlWriter = output.createXMLStreamWriter(strWriter);
        xmlWriter.writeCharacters("\r\n\t");
        xmlWriter.writeStartElement("db");

        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeComment("Sets the physical location on disk where data will be stored.");
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeStartElement("path");
        xmlWriter.writeCharacters(this.getPath());
        xmlWriter.writeEndElement();

        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeComment(
                "Boolean value. Enable/disable database integrity check run at startup.");
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeStartElement("check_integrity");
        xmlWriter.writeCharacters(String.valueOf(this.check_integrity));
        xmlWriter.writeEndElement();

        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeComment(
                "Data pruning behavior for the state database. Options: FULL, TOP, SPREAD.");
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeComment("FULL: the state is not pruned");
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeComment(
                "TOP: the state is kept only for the top K blocks; limits sync to branching only within the stored blocks");
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeComment(
                "SPREAD: the state is kept for the top K blocks and at regular block intervals");
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeStartElement("state-storage");
        xmlWriter.writeCharacters(this.prune_option.toString());
        xmlWriter.writeEndElement();

        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeComment("Data storage behavior for the transaction database. Boolean value used to enable/disable internal transaction storage.");
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeStartElement("internal-tx-storage");
        xmlWriter.writeCharacters(String.valueOf(internalTxStorage));
        xmlWriter.writeEndElement();

        if (!expert) {
            xmlWriter.writeCharacters("\r\n\t\t");
            xmlWriter.writeComment(
                    "Database implementation used to store data; supported options: leveldb, h2, rocksdb.");
            xmlWriter.writeCharacters("\r\n\t\t");
            xmlWriter.writeComment(
                    "Caution: changing implementation requires re-syncing from genesis!");
            xmlWriter.writeCharacters("\r\n\t\t");
            xmlWriter.writeStartElement("vendor");
            xmlWriter.writeCharacters(this.vendor);
            xmlWriter.writeEndElement();

            xmlWriter.writeCharacters("\r\n\t\t");
            xmlWriter.writeComment(
                    "Boolean value. Enable/disable database compression to trade storage space for execution time.");
            xmlWriter.writeCharacters("\r\n\t\t");
            xmlWriter.writeStartElement(Props.ENABLE_DB_COMPRESSION);
            xmlWriter.writeCharacters(String.valueOf(this.compression));
            xmlWriter.writeEndElement();
        } else {
            for (Map.Entry<String, CfgDbDetails> entry : specificConfig.entrySet()) {
                entry.getValue().toXML(entry.getKey(), xmlWriter, expert);
            }
        }

        xmlWriter.writeCharacters("\r\n\t");
        xmlWriter.writeEndElement();
        xml = strWriter.toString();
        strWriter.flush();
        strWriter.close();
        xmlWriter.flush();
        xmlWriter.close();
        return xml;
    } catch (IOException | XMLStreamException e) {
        e.printStackTrace();
        return "";
    }
}
 
Example 13
Source File: StaxUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static void copy(XMLStreamReader reader,
                        XMLStreamWriter writer,
                        boolean fragment,
                        boolean isThreshold) throws XMLStreamException {
    // number of elements read in
    int read = 0;
    int elementCount = 0;
    final Deque<Integer> countStack = new ArrayDeque<>();
    int event = reader.getEventType();

    while (reader.hasNext()) {
        switch (event) {
        case XMLStreamConstants.START_ELEMENT:
            read++;
            if (isThreshold) {
                elementCount++;

                if (MAX_ELEMENT_DEPTH_VAL != -1 && read >= MAX_ELEMENT_DEPTH_VAL) {
                    throw new DepthExceededStaxException("reach the innerElementLevelThreshold:"
                                               + MAX_ELEMENT_DEPTH_VAL);
                }
                if (MAX_CHILD_ELEMENTS_VAL != -1 && elementCount >= MAX_CHILD_ELEMENTS_VAL) {
                    throw new DepthExceededStaxException("reach the innerElementCountThreshold:"
                                               + MAX_CHILD_ELEMENTS_VAL);
                }
                countStack.push(elementCount);
                elementCount = 0;
            }
            writeStartElement(reader, writer);
            break;
        case XMLStreamConstants.END_ELEMENT:
            if (read > 0) {
                writer.writeEndElement();
            }
            read--;
            if (read < 0 && fragment) {
                return;
            }
            if (isThreshold && !countStack.isEmpty()) {
                elementCount = countStack.pop();
            }
            break;
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.SPACE:
            String s = reader.getText();
            if (s != null) {
                writer.writeCharacters(s);
            }
            break;
        case XMLStreamConstants.COMMENT:
            writer.writeComment(reader.getText());
            break;
        case XMLStreamConstants.CDATA:
            writer.writeCData(reader.getText());
            break;
        case XMLStreamConstants.START_DOCUMENT:
        case XMLStreamConstants.END_DOCUMENT:
        case XMLStreamConstants.ATTRIBUTE:
        case XMLStreamConstants.NAMESPACE:
            break;
        default:
            break;
        }
        event = reader.next();
    }
}
 
Example 14
Source File: CommentNode.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public void marshall(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeComment(comment);
}
 
Example 15
Source File: WriterTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testTwo() {

    System.out.println("Test StreamWriter's Namespace Context");

    try {
        String outputFile = USER_DIR + files[1] + ".out";
        System.out.println("Writing output to " + outputFile);

        xtw = outputFactory.createXMLStreamWriter(System.out);
        xtw.writeStartDocument();
        xtw.writeStartElement("elemTwo");
        xtw.setPrefix("html", "http://www.w3.org/TR/REC-html40");
        xtw.writeNamespace("html", "http://www.w3.org/TR/REC-html40");
        xtw.writeEndDocument();
        NamespaceContext nc = xtw.getNamespaceContext();
        // Got a Namespace Context.class

        XMLStreamWriter xtw1 = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);

        xtw1.writeComment("all elements here are explicitly in the HTML namespace");
        xtw1.setNamespaceContext(nc);
        xtw1.writeStartDocument("utf-8", "1.0");
        xtw1.setPrefix("htmlOne", "http://www.w3.org/TR/REC-html40");
        NamespaceContext nc1 = xtw1.getNamespaceContext();
        xtw1.close();
        Iterator it = nc1.getPrefixes("http://www.w3.org/TR/REC-html40");

        // FileWriter fw = new FileWriter(outputFile);
        while (it.hasNext()) {
            System.out.println("Prefixes :" + it.next());
            // fw.write((String)it.next());
            // fw.write(";");
        }
        // fw.close();
        // assertTrue(checkResults(testTwo+".out", testTwo+".org"));
        System.out.println("Done");
    } catch (Exception ex) {
        Assert.fail("testTwo Failed " + ex);
        ex.printStackTrace();
    }

}
 
Example 16
Source File: SolrSchemaXMLWriter.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Just dump out the fields of our various lists.
 * 
 * @param config
 * @param xml
 * @throws XMLStreamException
 */
//private void outFields(List<? extends GOlrCoreField> fieldList, XMLStreamWriter xml) throws XMLStreamException{
private void outFields(ConfigManager config, XMLStreamWriter xml) throws XMLStreamException{

	ArrayList<GOlrField> fieldList = config.getFields();
	for( GOlrField field : fieldList ){

		// Output any comments we found as a bunch at the top;
		// this should help clarify things when fields are overloaded.
		ArrayList<String> comments = config.getFieldComments(field.id);
		for( String comment : comments ){
			xml.writeComment(comment);
		}
		
		// Gather things up first.
		String f_id = field.id;
		String f_type = field.type;
		// ID is the only required field.
		String f_required = "false";
		if( field.id.equals("id") ){
			f_required = "true";
		}
		// Cardinality maps to multivalued.
		String f_multi = "true";
		if( field.cardinality.equals("single") ){
			f_multi = "false";
		}
		String f_indexed = field.indexed;
		
		// Write out the "main" field declaration.
		xml.writeStartElement("field");
		// The main variants.
		xml.writeAttribute("name", f_id);
		xml.writeAttribute("type", f_type);
		xml.writeAttribute("required", f_required);
		xml.writeAttribute("multiValued", f_multi);
		xml.writeAttribute("indexed", f_indexed);
		// Invariants: we'll always store.
		xml.writeAttribute("stored", "true");
		// Done.
		xml.writeEndElement(); // </field>

		// If searchable is true, create an additional field that mirrors
		// the main one, but using the tokenizer (needed for edismax, etc.).
		String f_searchable = field.searchable;
		//LOG.info("field.searchable: " + f_searchable);
		if( f_searchable.equals("true") ){

			//String munged_id = f_id + config.getSearchableExtension();
			String munged_id = f_id + "_searchable";

			xml.writeComment("An easily searchable (TextField tokenized) version of " + f_id + ".");
			xml.writeStartElement("field");
			// The main variants.
			xml.writeAttribute("name", munged_id);
			xml.writeAttribute("type", "text_searchable");
			xml.writeAttribute("required", f_required);
			xml.writeAttribute("multiValued", f_multi);
			// Invariants: we'll always store and index.
			xml.writeAttribute("indexed", "true");
			xml.writeAttribute("stored", "true");
			// Done.
			xml.writeEndElement(); // </field>				

			// Also, add the field copy soe we don't have to worry about manually loading it.
			xml.writeStartElement("copyField");
			//  <copyField source="body" dest="teaser" maxChars="300"/>
			xml.writeAttribute("source", f_id);
			xml.writeAttribute("dest", munged_id);
			xml.writeEndElement(); // </copyField>
		}
		
		// Add any automatically generated fields if necessary.
		generateAutomaticFields(field, xml);
	}
}
 
Example 17
Source File: CfgLog.java    From aion with MIT License 4 votes vote down vote up
public String toXML() {
    final XMLOutputFactory output = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlWriter;
    String xml;
    try {
        Writer strWriter = new StringWriter();
        xmlWriter = output.createXMLStreamWriter(strWriter);
        xmlWriter.writeCharacters("\r\n\t");
        xmlWriter.writeStartElement("log");
        xmlWriter.writeCharacters("\r\n");

        /*
         * XML - Displays tag/entry in the config.xml
         * Boolean value to allow logger to be toggled ON and OFF
         */
        xmlWriter.writeCharacters("\t\t");
        xmlWriter.writeComment(
                "Enable/Disable logback service; if disabled, output will not be logged.");
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeStartElement("log-file");
        xmlWriter.writeCharacters(this.logFile + "");
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters("\r\n");

        /*
         * XML - Displays log-path in the config.xml
         * String value to determine the folder path for log files
         */
        xmlWriter.writeCharacters("\t\t");
        xmlWriter.writeComment(
                "Sets the physical location on disk where log files will be stored.");
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeStartElement("log-path");
        xmlWriter.writeCharacters(this.logPath + "");
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters("\r\n");

        for (Map.Entry<LogEnum, LogLevel> module : this.modules.entrySet()) {
            xmlWriter.writeCharacters("\t\t");
            xmlWriter.writeStartElement(module.getKey().name());
            xmlWriter.writeCharacters(module.getValue().name());
            xmlWriter.writeEndElement();
            xmlWriter.writeCharacters("\r\n");
        }
        xmlWriter.writeCharacters("\t");
        xmlWriter.writeEndElement();
        xml = strWriter.toString();
        strWriter.flush();
        strWriter.close();
        xmlWriter.flush();
        xmlWriter.close();
        return xml;
    } catch (IOException | XMLStreamException e) {
        return "";
    }
}
 
Example 18
Source File: CfgApiRpc.java    From aion with MIT License 4 votes vote down vote up
String toXML() {
    final XMLOutputFactory output = XMLOutputFactory.newInstance();
    output.setProperty("escapeCharacters", false);
    XMLStreamWriter xmlWriter;
    String xml;
    try {
        // <rpc active="false" ip="127.0.0.1" port="8545"/>

        Writer strWriter = new StringWriter();
        xmlWriter = output.createXMLStreamWriter(strWriter);

        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeComment(
                "rpc config docs: https://github.com/aionnetwork/aion/wiki/JSON-RPC-API-Docs");

        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeStartElement("rpc");

        xmlWriter.writeAttribute("active", this.active ? "true" : "false");
        xmlWriter.writeAttribute("ip", this.ip);
        xmlWriter.writeAttribute("port", this.port + "");

        xmlWriter.writeCharacters("\r\n\t\t\t");
        xmlWriter.writeStartElement("cors-enabled");
        xmlWriter.writeCharacters(String.valueOf(this.isCorsEnabled()));
        xmlWriter.writeEndElement();

        xmlWriter.writeCharacters("\r\n\t\t\t");
        xmlWriter.writeComment(
                "comma-separated list, APIs available: web3,net,debug,personal,eth,stratum");
        xmlWriter.writeCharacters("\r\n\t\t\t");
        xmlWriter.writeStartElement("apis-enabled");
        xmlWriter.writeCharacters(String.join(",", this.getEnabled()));
        xmlWriter.writeEndElement();

        if (this.getEnabledMethods() != null) {
            xmlWriter.writeStartElement("api-methods-enabled");
            xmlWriter.writeCharacters(String.join(",", this.getEnabledMethods()));
            xmlWriter.writeEndElement();
        }

        if (this.getDisabledMethods() != null) {
            xmlWriter.writeStartElement("api-methods-disabled");
            xmlWriter.writeCharacters(String.join(",", this.getDisabledMethods()));
            xmlWriter.writeEndElement();
        }

        // don't write-back ssl. (keep it hidden for now)
        // xmlWriter.writeCharacters(this.ssl.toXML());

        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeEndElement();
        xml = strWriter.toString();
        strWriter.flush();
        strWriter.close();
        xmlWriter.flush();
        xmlWriter.close();
        return xml;
    } catch (IOException | XMLStreamException e) {
        e.printStackTrace();
        return "";
    }
}
 
Example 19
Source File: DocumentStaxUtils.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void writeRelationSet(RelationSet relations,
        XMLStreamWriter xsw, String namespaceURI) throws XMLStreamException {

  // if there are no relations then don't write the set, this means
  // that docs without relations will remain compatible with earlier
  // versions of GATE
  if(relations == null || relations.size() == 0) return;

  xsw.writeComment(" Relation Set for "
          + relations.getAnnotationSet().getName() + " ");
  newLine(xsw);
  newLine(xsw);

  xsw.writeStartElement(namespaceURI, "RelationSet");

  if(relations.getAnnotationSet().getName() != null) {
    xsw.writeAttribute("Name", relations.getAnnotationSet().getName());
  }
  newLine(xsw);

  for(Relation relation : relations.get()) {

    StringBuilder str = new StringBuilder();
    int[] members = relation.getMembers();
    for(int i = 0; i < members.length; i++) {
      if(i > 0) str.append(";");
      str.append(members[i]);
    }
    xsw.writeStartElement(namespaceURI, "Relation");
    xsw.writeAttribute("Id", String.valueOf(relation.getId()));
    xsw.writeAttribute("Type", relation.getType());
    xsw.writeAttribute("Members", str.toString());
    newLine(xsw);

    xsw.writeStartElement(namespaceURI, "UserData");
    if(relation.getUserData() != null) {
      ObjectWrapper userData = new ObjectWrapper(relation.getUserData());
      writeCharactersOrCDATA(xsw,
              replaceXMLIllegalCharactersInString(userData.toString()));
    }
    xsw.writeEndElement();
    newLine(xsw);

    writeFeatures(relation.getFeatures(), xsw, namespaceURI);
    xsw.writeEndElement();
    newLine(xsw);
  }

  // end RelationSet element
  xsw.writeEndElement();
  newLine(xsw);
}
 
Example 20
Source File: WadlWriter.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
private static final void writeComment(final DmComment comment, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeComment(comment.getStringValue());
}