Package org.apache.uima.util

Examples of org.apache.uima.util.XMLSerializer


      FileOutputStream out = new FileOutputStream(outputFile);
     
      try {
        // write XMI
        XmiCasSerializer ser = new XmiCasSerializer(aCAS.getTypeSystem());
        XMLSerializer xmlSer = new XMLSerializer(out, false);
        try {
          ser.serialize(aCAS, xmlSer.getContentHandler());
        } catch (SAXException e) {
          throw new IOException(e.getMessage());
        }
      } finally {
        if (out != null) {
View Full Code Here


   *
   * @param aWriter
   *          a Writer to which the XML string will be written
   */
  public void toXML(Writer aWriter) throws SAXException, IOException {
    XMLSerializer sax2xml = new XMLSerializer(aWriter);
    ContentHandler contentHandler = sax2xml.getContentHandler();
    contentHandler.startDocument();
    toXML(sax2xml.getContentHandler(), true);
    contentHandler.endDocument();
  }
View Full Code Here

   *
   * @param aOutputStream
   *          an OutputStream to which the XML string will be written
   */
  public void toXML(OutputStream aOutputStream) throws SAXException, IOException {
    XMLSerializer sax2xml = new XMLSerializer(aOutputStream);
    ContentHandler contentHandler = sax2xml.getContentHandler();
    contentHandler.startDocument();
    toXML(sax2xml.getContentHandler(), true);
    contentHandler.endDocument();
  }
View Full Code Here

   *           if an I/O failure occurs
   */
  public static void serialize(CAS aCAS, OutputStream aStream, boolean isFormattedOutput)
          throws SAXException, IOException {
    XCASSerializer xcasSerializer = new XCASSerializer(aCAS.getTypeSystem());
    XMLSerializer sax2xml = new XMLSerializer(aStream, isFormattedOutput);
    xcasSerializer.serialize(aCAS, sax2xml.getContentHandler());
  }
View Full Code Here

    if (DocumentFormat.XCAS.equals(format)) {
      XCASSerializer xcasSerializer = new XCASSerializer(mCAS
          .getTypeSystem());

      XMLSerializer xmlSerialzer = new XMLSerializer(out, true);

      try {
        xcasSerializer
            .serialize(mCAS, xmlSerialzer.getContentHandler());
      } catch (IOException e) {
        String message = (e.getMessage() != null ? e.getMessage() : "");

        IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
            IStatus.OK, message, e);

        throw new CoreException(s);
      } catch (SAXException e) {
        String message = (e.getMessage() != null ? e.getMessage() : "");

        IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
            IStatus.OK, message, e);

        throw new CoreException(s);
      }
    } else if (DocumentFormat.XMI.equals(format)) {
      XmiCasSerializer xmiSerializer = new XmiCasSerializer(mCAS
          .getTypeSystem());

      XMLSerializer xmlSerialzer = new XMLSerializer(out, true);

      try {
        xmiSerializer.serialize(mCAS, xmlSerialzer.getContentHandler());
      } catch (SAXException e) {
        String message = (e.getMessage() != null ? e.getMessage() : "");

        IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID,
            IStatus.OK, message, e);
View Full Code Here

   *          the stream to write the current <code>DotCorpus</code> instance.
   * @throws CoreException
   */
  public static void serialize(DotCorpus dotCorpus, OutputStream out) throws CoreException {

    XMLSerializer xmlSerializer = new XMLSerializer(out, true);
    ContentHandler xmlSerHandler = xmlSerializer.getContentHandler();

    try {
      xmlSerHandler.startDocument();
      xmlSerHandler.startElement("", CONFIG_ELEMENT, CONFIG_ELEMENT, new AttributesImpl());

View Full Code Here

    AnalysisEngineDescription desc = parser.parseAnalysisEngineDescription(new XMLInputSource(inFile), parsingOptions);

    // Write out descriptor
    File cloneFile = new File(inFile.getParentFile(), "CopyOfAggregateWithManyDelegates.xml");
    BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(cloneFile));
    XMLSerializer xmlSerializer = new XMLSerializer(true);
    xmlSerializer.setOutputStream(os);
    // set the amount to a value which will show up if used
    // indent should not be used because we're using a parser mode which preserves
    // comments and ignorable white space.
    xmlSerializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    ContentHandler contentHandler = xmlSerializer.getContentHandler();
    contentHandler.startDocument();
    desc.toXML(contentHandler, true);
    contentHandler.endDocument();
    os.close();
   
View Full Code Here

  public String prettyPrintModel() {
    StringWriter writer = new StringWriter();
    String parsedText = null;
    try {
      XMLSerializer xmlSerializer = new XMLSerializer(true);
      xmlSerializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", new Integer(
              MultiPageEditorContributor.getXMLindent()).toString());
      xmlSerializer.setWriter(writer);
      ContentHandler contentHandler = xmlSerializer.getContentHandler();
      contentHandler.startDocument();
      XMLizable trueDescriptor = getTrueDescriptor();
      if (trueDescriptor instanceof AnalysisEngineDescription) {
        AnalysisEngineDescription aed = (AnalysisEngineDescription) trueDescriptor;
        aed.toXML(contentHandler, true, true);
View Full Code Here

      assertTrue(tIndex.size() == 2); // document annot and this one
      assertTrue(t2Index.size() == 2); // ditto

      // serialize
      StringWriter sw = new StringWriter();
      XMLSerializer xmlSer = new XMLSerializer(sw, false);
      XmiCasSerializer xmiSer = new XmiCasSerializer(cas.getTypeSystem());
      xmiSer.serialize(cas, xmlSer.getContentHandler());
      String xml = sw.getBuffer().toString();

      // deserialize into another CAS (repeat twice to check it still works after reset)
      CAS newCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
              new FsIndexDescription[0]);
View Full Code Here

              .getTypeSystem();

      // reserialize as XMI, filtering out anything that doesn't fit in the
      // partialTypeSystem
      StringWriter sw = new StringWriter();
      XMLSerializer xmlSer = new XMLSerializer(sw, false);
      XmiCasSerializer xmiSer = new XmiCasSerializer(partialTypeSystem);
      xmiSer.serialize(cas, xmlSer.getContentHandler());
      String xml = sw.getBuffer().toString();
      // System.out.println(xml);

      // deserialize into another CAS (which has the whole type system)
      CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
View Full Code Here

TOP

Related Classes of org.apache.uima.util.XMLSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.