List of usage examples for javax.xml.stream XMLStreamWriter writeCharacters
public void writeCharacters(String text) throws XMLStreamException;
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 a2 s . c o 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()); {//from w w w. ja v a 2 s .c o 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.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 av a2s. c o 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$ {// ww w . j a v a 2s . co m 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(); } }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void writeAlert(final XMLStreamWriter writer, final String statusCode) throws XMLStreamException { writer.writeStartElement("Alert"); //$NON-NLS-1$ // CHECKSTYLE:OFF (imbricated blocks) {//from w ww . j a va2s . co m writer.writeStartElement("CmdID"); //$NON-NLS-1$ writer.writeCharacters(String.valueOf(this.idGenerator.nextCmdID())); writer.writeEndElement(); writer.writeStartElement("Data"); //$NON-NLS-1$ writer.writeCharacters(statusCode); writer.writeEndElement(); } // CHECKSTYLE:ON writer.writeEndElement(); }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void writeGenericAlert(final XMLStreamWriter writer, final DMGenericAlert[] genAlerts) throws XMLStreamException { for (final DMGenericAlert genericAlert : genAlerts) { final String cmdID = String.valueOf(this.idGenerator.nextCmdID()); final String alertCode = "1226"; //$NON-NLS-1$ final DMMeta meta = new DMMeta(); meta.put(DMMeta.TYPE, genericAlert.getType()); meta.put(DMMeta.FORMAT, genericAlert.getFormat()); meta.put(DMMeta.MARK, genericAlert.getMark()); this.commandSends.put(cmdID, new Object[] { alertCode, genericAlert.getCorrelator(), new DMItem[] { new DMItem(null, genericAlert.getSource(), meta, genericAlert.getData()) } }); writer.writeStartElement("Alert"); //$NON-NLS-1$ // CHECKSTYLE:OFF (imbricated blocks) {// w w w . j a v a2s .c o m writer.writeStartElement("CmdID"); //$NON-NLS-1$ writer.writeCharacters(cmdID); writer.writeEndElement(); writer.writeStartElement("Data"); //$NON-NLS-1$ writer.writeCharacters(alertCode); writer.writeEndElement(); if (genericAlert.getCorrelator() != null) { writer.writeStartElement("Correlator"); //$NON-NLS-1$ writer.writeCharacters(genericAlert.getCorrelator()); writer.writeEndElement(); } writer.writeStartElement("Item"); //$NON-NLS-1$ { if (genericAlert.getSource() != null) { writer.writeStartElement("Source"); //$NON-NLS-1$ { writer.writeStartElement("LocURI"); //$NON-NLS-1$ writer.writeCharacters(genericAlert.getSource()); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeStartElement("Meta"); //$NON-NLS-1$ { writer.writeStartElement("Type"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters(genericAlert.getType()); writer.writeEndElement(); writer.writeStartElement("Format"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters(genericAlert.getFormat()); writer.writeEndElement(); writer.writeStartElement("Mark"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters(genericAlert.getMark()); writer.writeEndElement(); } writer.writeEndElement(); writer.writeStartElement("Data"); //$NON-NLS-1$ writer.writeCharacters(genericAlert.getData()); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); } // CHECKSTYLE:ON }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void writeReplace(final XMLStreamWriter writer, final DMNode[] nodes) throws XMLStreamException { if (this.devInfoNodes.length >= 1) { boolean sameFormat = true; boolean sameType = true; if (this.devInfoNodes.length >= 2) { for (int i = 1; i < this.devInfoNodes.length; ++i) { if (sameFormat && !this.devInfoNodes[i].getFormat().equals(this.devInfoNodes[0].getFormat())) { sameFormat = false;/*from ww w .j a v a 2 s .c o m*/ } if (sameType && !this.devInfoNodes[i].getType().equals(this.devInfoNodes[0].getType())) { sameType = false; } } } writer.writeStartElement("Replace"); //$NON-NLS-1$ // CHECKSTYLE:OFF (imbricated blocks) { writer.writeStartElement("CmdID"); //$NON-NLS-1$ writer.writeCharacters(String.valueOf(this.idGenerator.nextCmdID())); writer.writeEndElement(); if (sameFormat || sameType) { writer.writeStartElement("Meta"); //$NON-NLS-1$ { if (sameFormat) { writer.writeStartElement("Format"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters(this.devInfoNodes[0].getFormat()); writer.writeEndElement(); } if (sameType) { writer.writeStartElement("Type"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters(this.devInfoNodes[0].getType()); writer.writeEndElement(); } } writer.writeEndElement(); } for (final DMNode devInfoNode : this.devInfoNodes) { writer.writeStartElement("Item"); //$NON-NLS-1$ { writer.writeStartElement("Source"); //$NON-NLS-1$ { writer.writeStartElement("LocURI"); //$NON-NLS-1$ writer.writeCharacters(devInfoNode.getURI()); writer.writeEndElement(); } writer.writeEndElement(); if (!sameFormat || !sameType) { writer.writeStartElement("Meta"); //$NON-NLS-1$ { if (!sameFormat) { writer.writeStartElement("Format"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters(devInfoNode.getFormat()); writer.writeEndElement(); } if (!sameType) { writer.writeStartElement("Type"); //$NON-NLS-1$ writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeCharacters(devInfoNode.getType()); writer.writeEndElement(); } } writer.writeEndElement(); } writer.writeStartElement("Data"); //$NON-NLS-1$ writer.writeCharacters(devInfoNode.getData()); writer.writeEndElement(); } writer.writeEndElement(); } } writer.writeEndElement(); // CHECKSTYLE:ON } }
From source file:org.eclipse.smila.datamodel.record.stax.RecordWriter.java
/** * write a text content.// ww w. jav a 2 s. c o m * * @param staxWriter * target XML stream * @param value * content characters * @throws XMLStreamException * StAX error */ private void writeText(final XMLStreamWriter staxWriter, final String value) throws XMLStreamException { staxWriter.writeCharacters(cleanText(value)); }
From source file:org.eclipse.smila.datamodel.record.stax.RecordWriter.java
/** * append a newline text if printPretty is activated. * * @param staxWriter//from w ww .j av a 2 s .com * target XML stream * @throws XMLStreamException * StAX error */ private void newline(final XMLStreamWriter staxWriter) throws XMLStreamException { if (_printPretty) { staxWriter.writeCharacters("\n"); } }
From source file:org.exist.webstart.JnlpWriter.java
/** * Write JNLP xml file to browser.//from w w w . j a v a 2 s . c o m * * @param response Object for writing to end user. * @throws java.io.IOException */ void writeJnlpXML(JnlpJarFiles jnlpFiles, HttpServletRequest request, HttpServletResponse response) throws IOException { logger.debug("Writing JNLP file"); // Format URL: "http://host:8080/CONTEXT/webstart/exist.jnlp" final String currentUrl = request.getRequestURL().toString(); // Find BaseUrl http://host:8080/CONTEXT final int webstartPos = currentUrl.indexOf("/webstart"); final String existBaseUrl = currentUrl.substring(0, webstartPos); // Find codeBase for jarfiles http://host:8080/CONTEXT/webstart/ final String codeBase = existBaseUrl + "/webstart/"; // Perfom sanity checks int counter = 0; for (final File jar : jnlpFiles.getAllWebstartJars()) { counter++; // debugging if (jar == null || !jar.exists()) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Missing Jar file! (" + counter + ")"); return; } } // Find URL to connect to with client final String startUrl = existBaseUrl.replaceFirst("http:", "xmldb:exist:") .replaceFirst("https:", "xmldb:exist:").replaceAll("-", "%2D") + "/xmlrpc"; // response.setDateHeader("Last-Modified", mainJar.lastModified()); response.setContentType("application/x-java-jnlp-file"); try { final XMLStreamWriter writer = XMLOutputFactory.newInstance() .createXMLStreamWriter(response.getOutputStream()); writer.writeStartDocument(); writer.writeStartElement("jnlp"); writer.writeAttribute("spec", "1.0+"); writer.writeAttribute("codebase", codeBase); writer.writeAttribute("href", "exist.jnlp"); writer.writeStartElement("information"); writer.writeStartElement("title"); writer.writeCharacters("eXist XML-DB client"); writer.writeEndElement(); writer.writeStartElement("vendor"); writer.writeCharacters("exist-db.org"); writer.writeEndElement(); writer.writeStartElement("homepage"); writer.writeAttribute("href", "http://exist-db.org"); writer.writeEndElement(); writer.writeStartElement("description"); writer.writeCharacters("Integrated command-line and gui client, " + "entirely based on the XML:DB API and provides commands " + "for most database related tasks, like creating and " + "removing collections, user management, batch-loading " + "XML data or querying."); writer.writeEndElement(); writer.writeStartElement("description"); writer.writeAttribute("kind", "short"); writer.writeCharacters("eXist XML-DB client"); writer.writeEndElement(); writer.writeStartElement("description"); writer.writeAttribute("kind", "tooltip"); writer.writeCharacters("eXist XML-DB client"); writer.writeEndElement(); writer.writeStartElement("icon"); writer.writeAttribute("href", "jnlp_logo.jpg"); writer.writeEndElement(); writer.writeStartElement("icon"); writer.writeAttribute("href", "jnlp_icon_128x128.gif"); writer.writeAttribute("width", "128"); writer.writeAttribute("height", "128"); writer.writeEndElement(); writer.writeStartElement("icon"); writer.writeAttribute("href", "jnlp_icon_64x64.gif"); writer.writeAttribute("width", "64"); writer.writeAttribute("height", "64"); writer.writeEndElement(); writer.writeStartElement("icon"); writer.writeAttribute("href", "jnlp_icon_32x32.gif"); writer.writeAttribute("width", "32"); writer.writeAttribute("height", "32"); writer.writeEndElement(); writer.writeEndElement(); // information writer.writeStartElement("security"); writer.writeEmptyElement("all-permissions"); writer.writeEndElement(); // ---------- writer.writeStartElement("resources"); writer.writeStartElement("property"); writer.writeAttribute("name", "jnlp.packEnabled"); writer.writeAttribute("value", "true"); writer.writeEndElement(); writer.writeStartElement("j2se"); writer.writeAttribute("version", "1.6+"); writer.writeEndElement(); for (final File jar : jnlpFiles.getAllWebstartJars()) { writer.writeStartElement("jar"); writer.writeAttribute("href", jar.getName()); writer.writeAttribute("size", "" + jar.length()); writer.writeEndElement(); } writer.writeEndElement(); // resources writer.writeStartElement("application-desc"); writer.writeAttribute("main-class", "org.exist.client.InteractiveClient"); writer.writeStartElement("argument"); writer.writeCharacters("-ouri=" + startUrl); writer.writeEndElement(); writer.writeStartElement("argument"); writer.writeCharacters("--no-embedded-mode"); writer.writeEndElement(); if (request.isSecure()) { writer.writeStartElement("argument"); writer.writeCharacters("--use-ssl"); writer.writeEndElement(); } writer.writeEndElement(); // application-desc writer.writeEndElement(); // jnlp writer.writeEndDocument(); writer.flush(); writer.close(); } catch (final Throwable ex) { logger.error(ex); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage()); } }