private void toFile(XMLizable desc, File destination) throws SAXException, FileNotFoundException { destination.getParentFile().mkdirs(); OutputStream out = new FileOutputStream(destination); XMLSerializer sax = new XMLSerializer(out); ContentHandler ch = sax.getContentHandler(); ch.startDocument(); desc.toXML(ch); ch.endDocument(); }
/** * Serializes CAS into a given OutputStream in Xmi format * * @param stream output stream * @param aCAS CAS to serialize * @param encoding encoding to use * @param typeSystem type system * @param otsd type system * @throws IOException io failure * @throws SAXException parsing error */ public void serializeToXMI(OutputStream stream, CAS aCAS, String encoding, TypeSystem typeSystem, OutOfTypeSystemData otsd) throws IOException, SAXException { if (typeSystem == null) typeSystem = aCAS.getTypeSystem(); XMLSerializer xmlSer = new XMLSerializer(stream, false); if (encoding != null) xmlSer.setOutputProperty(OutputKeys.ENCODING, encoding); XmiCasSerializer ser = new XmiCasSerializer(typeSystem); ser.serialize(aCAS, xmlSer.getContentHandler()); }
public XMLSerializer(Writer aWriter) { this(); setWriter(aWriter); }
String parsedText = null; try { XMLSerializer xmlSerializer = new XMLSerializer(true); xmlSerializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", Integer.valueOf( MultiPageEditorContributor.getXMLindent()).toString()); xmlSerializer.setIndent(true); xmlSerializer.setWriter(writer); ContentHandler contentHandler = xmlSerializer.getContentHandler(); contentHandler.startDocument(); XMLizable trueDescriptor = getTrueDescriptor();
/** * Writes out this object's XML representation. * * @param aWriter * a Writer to which the XML string will be written */ public void toXML(Writer aWriter) throws SAXException, IOException { toXML(new XMLSerializer(aWriter)); }
private void toXML(XMLSerializer sax2xml) throws SAXException, IOException { ContentHandler contentHandler = sax2xml.getContentHandler(); contentHandler.startDocument(); toXML(contentHandler, true); // no reason to create a new content handler contentHandler.endDocument(); }
/** * Writes out this object's XML representation. * * @param aOutputStream * an OutputStream to which the XML string will be written */ public void toXML(OutputStream aOutputStream) throws SAXException, IOException { toXML(new XMLSerializer(aOutputStream)); }
/** * Converts a TypeSystem object to XML. * Built-in types and Array types (e.g. Annotation[]) are not included. * * @param aTypeSystem * the TypeSystem to convert * @param aOutputStream * the stream to which XML output will be written * * @throws IOException * if there is a problem writing to the provided OutputStream * @throws SAXException * if an error occurs during the translation of the type system to XML */ public static void typeSystem2Xml(TypeSystem aTypeSystem, OutputStream aOutputStream) throws SAXException, IOException { XMLSerializer sax2xml = new XMLSerializer(aOutputStream); typeSystem2Xml(aTypeSystem, sax2xml.getContentHandler()); }
public XMLSerializer(Writer aWriter, boolean isFormattedOutput) { this(isFormattedOutput); setWriter(aWriter); }
/** * Generates inline XML from a CAS. * * @param aCAS * CAS to generate from * @param aFilter * constraint that determines which annotations are included in the output. If null (or * ommitted), all annotations are included. * @throws CASException - * @return the inline form */ public String generateXML(CAS aCAS, FSMatchConstraint aFilter) throws CASException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); XMLSerializer sax2xml = new XMLSerializer(byteArrayOutputStream, formattedOutput); generateXML(aCAS, aFilter, sax2xml.getContentHandler()); // return XML string return new String(byteArrayOutputStream.toByteArray()); }
@Override public void write(OutputStream aStream) throws Exception { XmiCasSerializer ser = new XmiCasSerializer(cas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(aStream, false); ser.serialize(cas, xmlSer.getContentHandler()); }
private static void writeXmi(CAS aCas, File name) throws IOException, SAXException { FileOutputStream out = null; try { // write XMI out = new FileOutputStream(name); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } finally { if (out != null) { out.close(); } } }
private String serializeCas(CAS aCas) throws RecommendationException { try (StringWriter out = new StringWriter()) { // Passing "null" as the type system to the XmiCasSerializer means that we want // to serialize all types (i.e. no filtering for a specific target type system). XmiCasSerializer xmiCasSerializer = new XmiCasSerializer(null); XMLSerializer sax2xml = new XMLSerializer(out, true); xmiCasSerializer.serialize(aCas, sax2xml.getContentHandler(), null, null, null); return out.toString(); } catch (CASRuntimeException | SAXException | IOException e) { throw new RecommendationException("Error while serializing CAS!", e); } }
private void writeXmi(CAS aCas, String id) throws IOException, SAXException { File outFile = new File(outputDirectory, id ); FileOutputStream out = null; try { out = new FileOutputStream(outFile); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } finally { if (out != null) { out.close(); } } }
private void writeXmi(CAS aCas, OutputStream out) throws IOException, SAXException { // seems like it is not necessary to buffer outputStream for SAX TransformationHandler // out = new BufferedOutputStream(out); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, xmlFormatted); ser.serialize(aCas, xmlSer.getContentHandler()); } }
@Override public void write(OutputStream aStream) throws Exception { XmiCasSerializer ser = new XmiCasSerializer(cas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(aStream, false); ser.serialize(cas, xmlSer.getContentHandler()); }
public String serializeCasToXmi(CAS aCAS, XmiSerializationSharedData serSharedData, Marker aMarker) throws Exception { Writer writer = new StringWriter(); try { XMLSerializer xmlSer = new XMLSerializer(writer, false); XmiCasSerializer ser = new XmiCasSerializer(aCAS.getTypeSystem()); ser.serialize(aCAS, xmlSer.getContentHandler(), null, serSharedData, aMarker); return writer.toString(); } catch (SAXException e) { throw e; } finally { writer.close(); } }
private static void writeXmi(CAS aCas, File name) throws Exception { FileOutputStream out = null; try { // write XMI out = new FileOutputStream(name); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } catch (Exception e) { throw e; } finally { if (out != null) { out.close(); } } }
private void writeXmi(CAS aCas, String id) throws IOException, SAXException { File outFile = new File(outputDirectory, id ); FileOutputStream out = null; try { out = new FileOutputStream(outFile); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } finally { if (out != null) { out.close(); } } }
private String serializeCas(CAS aCas) throws RecommendationException { try (StringWriter out = new StringWriter()) { // Passing "null" as the type system to the XmiCasSerializer means that we want // to serialize all types (i.e. no filtering for a specific target type system). XmiCasSerializer xmiCasSerializer = new XmiCasSerializer(null); XMLSerializer sax2xml = new XMLSerializer(out, true); xmiCasSerializer.serialize(aCas, sax2xml.getContentHandler(), null, null, null); return out.toString(); } catch (CASRuntimeException | SAXException | IOException e) { throw new RecommendationException("Error while serializing CAS!", e); } }