List of usage examples for javax.xml.stream XMLStreamWriter close
public void close() throws XMLStreamException;
From source file:com.norconex.jef4.log.FileLogManager.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {//from w w w. j a v a 2s .com XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("logManager"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("logDir"); writer.writeCharacters(new File(logdir).getAbsolutePath()); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:microsoft.exchange.webservices.data.core.EwsUtilities.java
/** * .//from w w w . j a v a 2 s .c o m * * @param entryKind the entry kind * @param logEntry the log entry * @return the string * @throws XMLStreamException the XML stream exception * @throws IOException signals that an I/O exception has occurred. */ public static String formatLogMessage(String entryKind, String logEntry) throws XMLStreamException, IOException { String lineSeparator = System.getProperty("line.separator"); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(outStream); EwsUtilities.writeTraceStartElement(writer, entryKind, false); writer.writeCharacters(lineSeparator); writer.writeCharacters(logEntry); writer.writeCharacters(lineSeparator); writer.writeEndElement(); writer.writeCharacters(lineSeparator); writer.flush(); writer.close(); outStream.flush(); String formattedLogMessage = outStream.toString(); formattedLogMessage = formattedLogMessage.replaceAll("'", "'"); formattedLogMessage = formattedLogMessage.replaceAll(""", "\""); formattedLogMessage = formattedLogMessage.replaceAll(">", ">"); formattedLogMessage = formattedLogMessage.replaceAll("<", "<"); formattedLogMessage = formattedLogMessage.replaceAll("&", "&"); outStream.close(); return formattedLogMessage; }
From source file:com.norconex.collector.http.url.impl.DefaultURLExtractor.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/* w ww . j ava 2s. c om*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("urlExtractor"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("maxURLLength"); writer.writeCharacters(Integer.toString(maxURLLength)); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.norconex.collector.http.robot.impl.DefaultRobotsMetaProvider.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/* ww w . j a v a2 s . c om*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("robotsMeta"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("headersPrefix"); if (headersPrefix != null) { writer.writeCharacters(headersPrefix); } writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.norconex.collector.core.filter.impl.RegexMetadataFilter.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/*w ww . j a v a 2s. c o m*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("filter"); writer.writeAttribute("class", getClass().getCanonicalName()); super.saveToXML(writer); writer.writeAttribute("caseSensitive", Boolean.toString(caseSensitive)); writer.writeAttribute("field", field); writer.writeCharacters(regex == null ? "" : regex); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.norconex.jef4.status.FileJobStatusStore.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/* w w w . java 2s.c o m*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("statusStore"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("statusDir"); writer.writeCharacters(new File(statusDir).getAbsolutePath()); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.norconex.collector.http.fetch.impl.GenericMetadataFetcher.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/*from w ww. jav a 2 s .c om*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("httpHeadersFetcher"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("validStatusCodes"); writer.writeCharacters(StringUtils.join(validStatusCodes, ",")); writer.writeEndElement(); writer.writeStartElement("headersPrefix"); writer.writeCharacters(headersPrefix); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.norconex.collector.http.filter.impl.SegmentCountURLFilter.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {//from w w w. j ava 2 s. c o m XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("filter"); writer.writeAttribute("class", getClass().getCanonicalName()); super.saveToXML(writer); writer.writeAttribute("count", Integer.toString(count)); writer.writeAttribute("duplicate", Boolean.toString(duplicate)); writer.writeAttribute("separator", separator); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.microsoft.tfs.core.memento.XMLMemento.java
/** * Writes this {@link XMLMemento} as an XML element (with child elements for * child {@link Memento}s) to the specified {@link OutputStream}. * * @param outputStream/*from w w w . ja va 2s .c o m*/ * the output stream to write the document to * @param encoding * the encoding to use when writing the {@link OutputStream}, * <code>null</code> to use the default encoding ( * {@link #DEFAULT_ENCODING}). * @throws MementoException * if there is a problem serializing the document to the stream. */ public synchronized void write(final OutputStream outputStream, final String encoding) throws MementoException { Check.notNull(outputStream, "outputStream"); //$NON-NLS-1$ try { final XMLStreamWriter writer = StaxFactoryProvider.getXMLOutputFactory() .createXMLStreamWriter(outputStream, (encoding != null) ? encoding : DEFAULT_ENCODING); writeAsElement(writer); writer.close(); } catch (final XMLStreamException e) { log.error("Error saving", e); //$NON-NLS-1$ throw new MementoException(e); } }
From source file:de.shadowhunt.subversion.internal.LockOperation.java
@Override protected HttpUriRequest createRequest() { final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("LOCK", uri); if (steal) {/*from w w w . ja v a2s.co m*/ request.addHeader("X-SVN-Options", "lock-steal"); } final Writer body = new StringBuilderWriter(); try { final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("lockinfo"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeStartElement("lockscope"); writer.writeEmptyElement("exclusive"); writer.writeEndElement(); // lockscope writer.writeStartElement("locktype"); writer.writeEmptyElement("write"); writer.writeEndElement(); // locktype writer.writeEndElement(); //lockinfo writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }