List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:org.dita.dost.module.GenMapAndTopicListModule.java
private void writeExportAnchors() throws DITAOTException { if (INDEX_TYPE_ECLIPSEHELP.equals(transtype)) { // Output plugin id final File pluginIdFile = new File(job.tempDir, FILE_NAME_PLUGIN_XML); final DelayConrefUtils delayConrefUtils = new DelayConrefUtils(); delayConrefUtils.writeMapToXML(exportAnchorsFilter.getPluginMap(), pluginIdFile); XMLStreamWriter export = null; try (OutputStream exportStream = new FileOutputStream(new File(job.tempDir, FILE_NAME_EXPORT_XML))) { export = XMLOutputFactory.newInstance().createXMLStreamWriter(exportStream, "UTF-8"); export.writeStartDocument(); export.writeStartElement("stub"); for (final ExportAnchor e : exportAnchorsFilter.getExportAnchors()) { export.writeStartElement("file"); export.writeAttribute("name", tempFileNameScheme.generateTempFileName(toFile(e.file).toURI()).toString()); for (final String t : sort(e.topicids)) { export.writeStartElement("topicid"); export.writeAttribute("name", t); export.writeEndElement(); }// w w w.j av a 2s . c om for (final String i : sort(e.ids)) { export.writeStartElement("id"); export.writeAttribute("name", i); export.writeEndElement(); } for (final String k : sort(e.keys)) { export.writeStartElement("keyref"); export.writeAttribute("name", k); export.writeEndElement(); } export.writeEndElement(); } export.writeEndElement(); export.writeEndDocument(); } catch (final IOException e) { throw new DITAOTException("Failed to write export anchor file: " + e.getMessage(), e); } catch (final XMLStreamException e) { throw new DITAOTException("Failed to serialize export anchor file: " + e.getMessage(), e); } finally { if (export != null) { try { export.close(); } catch (final XMLStreamException e) { logger.error("Failed to close export anchor file: " + e.getMessage(), e); } } } } }
From source file:org.eclipse.gyrex.logback.config.model.Appender.java
@Override public void toXml(final XMLStreamWriter writer) throws XMLStreamException { final boolean wrapIntoSiftingAppender = canSift() && isSeparateLogOutputsPerMdcProperty(); writer.writeStartElement("appender"); writer.writeAttribute("name", getName()); if (wrapIntoSiftingAppender) { writer.writeAttribute("class", SiftingAppender.class.getName()); } else {/*from w ww . jav a 2 s .com*/ writer.writeAttribute("class", getAppenderClassName()); } final Level threshold = getThreshold(); if (null != threshold) { writer.writeStartElement("filter"); writer.writeAttribute("class", ThresholdFilter.class.getName()); writer.writeStartElement("level"); writer.writeCharacters(threshold.toString()); writer.writeEndElement(); writer.writeEndElement(); } if (wrapIntoSiftingAppender) { // start discriminator and wrap regular appender into <sift><appender> writer.writeStartElement("discriminator"); writer.writeAttribute("class", MDCBasedDiscriminator.class.getName()); writer.writeStartElement("key"); writer.writeCharacters(getSiftingMdcPropertyName()); writer.writeEndElement(); writer.writeStartElement("defaultValue"); writer.writeCharacters(getSiftingMdcPropertyDefaultValue()); writer.writeEndElement(); writer.writeEndElement(); writer.writeStartElement("sift"); writer.writeStartElement("appender"); writer.writeAttribute("name", String.format("%s-${%s}", getName(), getSiftingMdcPropertyName())); } writeAppenderContent(writer); writeEncoder(writer); if (wrapIntoSiftingAppender) { // finish <sift><appender> writer.writeEndElement(); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.eclipse.gyrex.logback.config.model.FileAppender.java
private void writeSizeBasedRotation(final XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("rollingPolicy"); writer.writeAttribute("class", FixedWindowRollingPolicy.class.getName()); {/*from w w w . j a v a 2 s . co m*/ writer.writeStartElement("fileNamePattern"); writer.writeCharacters(StringUtils.substringBeforeLast(getFileName(), ".")); writer.writeCharacters(".%i"); final String extension = StringUtils.substringAfter(getFileName(), "."); if (StringUtils.isNotBlank(extension)) { writer.writeCharacters("."); writer.writeCharacters(extension); } if (isCompressRotatedLogs()) { writer.writeCharacters(".gz"); } writer.writeEndElement(); writer.writeStartElement("minIndex"); writer.writeCharacters("1"); writer.writeEndElement(); writer.writeStartElement("maxIndex"); writer.writeCharacters("3"); writer.writeEndElement(); } writer.writeEndElement(); writer.writeStartElement("triggeringPolicy"); writer.writeAttribute("class", SizeBasedTriggeringPolicy.class.getName()); { String maxFileSize = getMaxFileSize(); if (StringUtils.isBlank(maxFileSize)) { maxFileSize = "1MB"; } writer.writeStartElement("maxFileSize"); writer.writeCharacters(maxFileSize); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.eclipse.gyrex.logback.config.model.FileAppender.java
private void writeTimeBasedRotation(final XMLStreamWriter writer, final RotationPolicy policy) throws XMLStreamException { writer.writeStartElement("rollingPolicy"); writer.writeAttribute("class", TimeBasedRollingPolicy.class.getName()); {/* www . ja v a 2 s. co m*/ writer.writeStartElement("fileNamePattern"); writer.writeCharacters(StringUtils.substringBeforeLast(getFileName(), ".")); switch (policy) { case MONTHLY: writer.writeCharacters(".%d{yyyyMM}"); break; case WEEKLY: writer.writeCharacters(".%d{yyyyww}"); break; case DAILY: default: writer.writeCharacters(".%d{yyyyMMdd}"); break; } final String extension = StringUtils.substringAfter(getFileName(), "."); if (StringUtils.isNotBlank(extension)) { writer.writeCharacters("."); writer.writeCharacters(extension); } if (isCompressRotatedLogs()) { writer.writeCharacters(".gz"); } writer.writeEndElement(); writer.writeStartElement("maxHistory"); String maxHistory = getMaxHistory(); if (StringUtils.isBlank(maxHistory)) { maxHistory = policy == RotationPolicy.DAILY ? "30" : policy == RotationPolicy.WEEKLY ? "52" : "12"; } writer.writeCharacters(maxHistory); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.eclipse.gyrex.logback.config.model.LogbackConfig.java
static void writeProperty(final XMLStreamWriter writer, final String name, final String value) throws XMLStreamException { writer.writeEmptyElement("property"); writer.writeAttribute("name", name); writer.writeAttribute("value", value); }
From source file:org.eclipse.gyrex.logback.config.model.LogbackConfig.java
/** * Serializes the Logback configuration to the specified XML writer. * <p>/* www . j a v a 2s . c o m*/ * The XML is expected to be readable by Logback. As such, it depends * heavily on Logback and may be bound to different evolution/compatibility * rules. * </p> * * @param writer * the stream writer * @throws XMLStreamException */ @Override public void toXml(final XMLStreamWriter writer) throws XMLStreamException { writer.writeStartDocument(); writer.writeStartElement("configuration"); writer.writeAttribute("scan", "true"); writer.writeAttribute("scanPeriod", "2 minutes"); writeCommonProperties(writer); writeJulLevelChangePropagator(writer); for (final Appender appender : getAppenders().values()) { appender.toXml(writer); } for (final Logger logger : getLoggers().values()) { logger.toXml(writer); } writeRootLogger(writer); writer.writeEndElement(); writer.writeEndDocument(); }
From source file:org.eclipse.gyrex.logback.config.model.LogbackConfig.java
private void writeJulLevelChangePropagator(final XMLStreamWriter writer) throws XMLStreamException { writer.writeComment("propagate log level changes to JUL"); writer.writeStartElement("contextListener"); writer.writeAttribute("class", LevelChangePropagator.class.getName()); {/* w ww .j a v a 2 s .c o m*/ writer.writeStartElement("resetJUL"); writer.writeCData("true"); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.eclipse.gyrex.logback.config.model.LogbackConfig.java
private void writeRootLogger(final XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("root"); writer.writeAttribute("level", getDefaultLevel().toString()); for (final String appenderRef : getDefaultAppenders()) { writer.writeEmptyElement("appender-ref"); writer.writeAttribute("ref", appenderRef); }/*from w w w .j a v a 2 s .com*/ writer.writeEndElement(); }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void writeMessage(final OutputStream out) throws XMLStreamException { final XMLStreamWriter writer = this.dmClient.createXMLStreamWriter(out, ENCODING); writer.writeStartDocument(ENCODING, "1.0"); //$NON-NLS-1$ // CHECKSTYLE:OFF (imbricated blocks) {/* w w w. j ava 2 s . co m*/ writer.writeStartElement("SyncML"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "SYNCML:SYNCML1.2"); //$NON-NLS-1$//$NON-NLS-2$ { writer.writeStartElement("SyncHdr"); //$NON-NLS-1$ { writer.writeStartElement("VerDTD"); //$NON-NLS-1$ writer.writeCharacters("1.2"); //$NON-NLS-1$ writer.writeEndElement(); writer.writeStartElement("VerProto"); //$NON-NLS-1$ writer.writeCharacters("DM/1.2"); //$NON-NLS-1$ writer.writeEndElement(); writer.writeStartElement("SessionID"); //$NON-NLS-1$ writer.writeCharacters(this.sessionId); writer.writeEndElement(); writer.writeStartElement("MsgID"); //$NON-NLS-1$ writer.writeCharacters(String.valueOf(this.idGenerator.nextMsgID())); writer.writeEndElement(); writer.writeStartElement("Target"); //$NON-NLS-1$ { writer.writeStartElement("LocURI"); //$NON-NLS-1$ writer.writeCharacters(this.server.toString()); writer.writeEndElement(); } writer.writeEndElement(); writer.writeStartElement("Source"); //$NON-NLS-1$ { writer.writeStartElement("LocURI"); //$NON-NLS-1$ writer.writeCharacters(this.client.toString()); writer.writeEndElement(); } writer.writeEndElement(); /* * Add basic authentication */ writer.writeStartElement("Cred"); //$NON-NLS-1$ { writer.writeStartElement("Meta"); //$NON-NLS-1$ { writer.writeStartElement("Format"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters("b64"); //$NON-NLS-1$ writer.writeEndElement(); writer.writeStartElement("Type"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters("syncml:auth-basic"); //$NON-NLS-1$ writer.writeEndElement(); } writer.writeEndElement(); writer.writeStartElement("Data"); //$NON-NLS-1$ writer.writeCharacters(userAuth); writer.writeEndElement(); } writer.writeEndElement(); /* * End authentication */ } writer.writeEndElement(); writer.writeStartElement("SyncBody"); //$NON-NLS-1$ { writeStatus(writer); if (!this.isClientAuthenticated) { writeAlert(writer, "1201"); //$NON-NLS-1$ writeGenericAlert(writer, this.genericAlerts); writeReplace(writer, this.devInfoNodes); } writer.writeStartElement("Final"); //$NON-NLS-1$ writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); } // CHECKSTYLE:ON writer.writeEndDocument(); writer.flush(); writer.close(); }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void writeStatus(final XMLStreamWriter writer) throws XMLStreamException { while (this.statusManager.isValidStatus()) { // CHECKSTYLE:OFF (imbricated blocks) writer.writeStartElement("Status"); //$NON-NLS-1$ {/*from w w w . j a v a2 s .c om*/ writer.writeStartElement("CmdID"); //$NON-NLS-1$ writer.writeCharacters(String.valueOf(this.idGenerator.nextCmdID())); writer.writeEndElement(); writer.writeStartElement("MsgRef"); //$NON-NLS-1$ writer.writeCharacters(this.statusManager.getMsgRef()); writer.writeEndElement(); writer.writeStartElement("CmdRef"); //$NON-NLS-1$ writer.writeCharacters(this.statusManager.getCmdRef()); writer.writeEndElement(); writer.writeStartElement("Cmd"); //$NON-NLS-1$ writer.writeCharacters(this.statusManager.getCmd()); writer.writeEndElement(); for (final String targetRef : this.statusManager.getTargetRef()) { writer.writeStartElement("TargetRef"); //$NON-NLS-1$ writer.writeCharacters(targetRef); writer.writeEndElement(); } for (final String sourceRef : this.statusManager.getSourceRef()) { writer.writeStartElement("SourceRef"); //$NON-NLS-1$ writer.writeCharacters(sourceRef); writer.writeEndElement(); } writer.writeStartElement("Data"); //$NON-NLS-1$ writer.writeCharacters(this.statusManager.getStatusCode()); writer.writeEndElement(); } writer.writeEndElement(); if (!this.statusManager.getResults().isEmpty()) { writer.writeStartElement("Results"); //$NON-NLS-1$ { writer.writeStartElement("CmdID"); //$NON-NLS-1$ writer.writeCharacters(String.valueOf(this.idGenerator.nextCmdID())); writer.writeEndElement(); writer.writeStartElement("MsgRef"); //$NON-NLS-1$ writer.writeCharacters(this.statusManager.getMsgRef()); writer.writeEndElement(); writer.writeStartElement("CmdRef"); //$NON-NLS-1$ writer.writeCharacters(this.statusManager.getCmdRef()); writer.writeEndElement(); // final String globalFormat = this.statusManager.getGlobalFormat(); // final String globalType = this.statusManager.getGlobalType(); // if (globalFormat != null || globalType != null) { // writer.writeStartElement("Meta"); // { // if (globalFormat != null) { // writer.writeStartElement("Format"); // writer.writeAttribute("xmlns", "syncml:metinf"); // writer.writeCharacters(globalFormat); // writer.writeEndElement(); // } // if (globalType != null) { // writer.writeStartElement("Type"); // writer.writeAttribute("xmlns", "syncml:metinf"); // writer.writeCharacters(globalType); // writer.writeEndElement(); // } // } // writer.writeEndElement(); // } for (final Results results : this.statusManager.getResults()) { writer.writeStartElement("Item"); //$NON-NLS-1$ { writer.writeStartElement("Source"); //$NON-NLS-1$ { writer.writeStartElement("LocURI"); //$NON-NLS-1$ writer.writeCharacters(results.getSourceURI()); writer.writeEndElement(); } writer.writeEndElement(); // if (globalFormat == null || globalType == null) { writer.writeStartElement("Meta"); //$NON-NLS-1$ { // if (globalFormat == null) { writer.writeStartElement("Format"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters(results.getFormat()); writer.writeEndElement(); // } // if (globalType == null) { writer.writeStartElement("Type"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters(results.getType()); writer.writeEndElement(); // } } writer.writeEndElement(); // } writer.writeStartElement("Data"); //$NON-NLS-1$ writer.writeCharacters(results.getData()); writer.writeEndElement(); } writer.writeEndElement(); } } writer.writeEndElement(); } // CHECKSTYLE:ON this.statusManager.nextStatus(); } }