Examples of OdfTextDocument


Examples of org.odftoolkit.odfdom.doc.OdfTextDocument

  /** Testing the XML helper and the OdfPackage to handle two files at the same time (have them open) */
  @Test
  public void testResolverWithXSLT() {
    try {
      OdfXMLHelper helper = new OdfXMLHelper();
      OdfTextDocument odt = (OdfTextDocument) OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(SIMPLE_ODT));
      InputSource inputSource = new InputSource(ResourceUtilities.getURI(XSL_CONCAT).toString());
      Templates multiFileAccessTemplate = TransformerFactory.newInstance().newTemplates(new SAXSource(inputSource));
      File xslOut = ResourceUtilities.newTestOutputFile(XSL_OUTPUT);
      helper.transform(odt.getPackage(), "content.xml", multiFileAccessTemplate, new StreamResult(xslOut));
      LOG.info("Transformed ODF document " + SIMPLE_ODT + " to " + xslOut.getAbsolutePath() + "!");
      File testOutputFile = new File(xslOut.getAbsolutePath());
      if (testOutputFile.length() < 100) {
        String errorMsg = "The file " + xslOut.getAbsolutePath() + " is smaller than it should be. \nIt was not created from multiple package files!";
        LOG.severe(errorMsg);
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfTextDocument

  }

  @Test
  public void testReadDocumentMeta() throws Exception {
    // create a new empty document
    OdfTextDocument textDoc = OdfTextDocument.newTextDocument(); // activiating metadata updates
    textDoc.save(ResourceUtilities.newTestOutputFile("DocForMetaTest.odt"));
    textDoc.close();
    // read empty document meta
    textDoc = (OdfTextDocument) OdfTextDocument.loadDocument(ResourceUtilities.getAbsolutePath("DocForMetaTest.odt"));
    OdfOfficeMeta meta = textDoc.getOfficeMetadata();
    Assert.assertNotNull(meta.getGenerator());
    Assert.assertNotNull(meta.getCreationDate());
    Assert.assertNotNull(meta.getCreator());
    Assert.assertNotNull(meta.getDate());
    Assert.assertTrue(meta.getEditingCycles() > 0);
    Assert.assertNotNull(meta.getEditingDuration());
    Assert.assertNull(meta.getLanguage());
    textDoc.close();
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfTextDocument

  @Test
  public void testGRDDL()  {
    try {
      OdfXMLHelper helper = new OdfXMLHelper();
      OdfTextDocument odt = (OdfTextDocument) OdfDocument
          .loadDocument(ResourceUtilities.getAbsolutePath(SIMPLE_ODT));
      InputSource inputSource = new InputSource(ResourceUtilities.getURI(
          "grddl/odf2rdf.xsl").toString());
      Templates multiFileAccessTemplate = TransformerFactory.newInstance()
          .newTemplates(new SAXSource(inputSource));
      ByteArrayOutputStream out = new ByteArrayOutputStream();
  
      helper.transform(odt.getPackage(), "content.xml",
          multiFileAccessTemplate, new StreamResult(out));

      Model m1 = createMemModel();
      m1.read(new InputStreamReader(new ByteArrayInputStream(out
          .toByteArray()), "utf-8"), odt.getPackage().getBaseURI());
      LOG.info("RDF Model:\n" + m1.toString());
      TestCase.assertEquals(5, m1.size());
    } catch (Exception ex) {
      Assert.fail(ex.getMessage());
      Logger.getLogger(GRDDLTest.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfTextDocument

    Collections.sort(samples, new AliasComparator(Sample.class));

    InputStream in = FormUtils.class.getResourceAsStream("/forms/odt/sampleDeliveryForm.odt");

    if (in != null) {
      OdfTextDocument oDoc = OdfTextDocument.loadDocument(in);
      OdfContentDom contentDom = oDoc.getContentDom();

      /*
      OfficeTextElement contentRoot = oDoc.getContentRoot();
      NodeList nl = contentRoot.getElementsByTagName("TABLE");
      for (int i = 0; i < nl.getLength(); i++) {
        Element e = (Element)nl.item(i);
        System.out.println(e.getTagName() + " :: " + e.toString());
      }

      List<OdfTable> cTables = contentDom.getTableList();
      for (OdfTable c : cTables) {
        System.out.println(c.getTableName() + " :: " + c.getRowCount() + " :: " + c.getColumnCount());
      }
      */
      /*
      OdfTable cTable = cTables.get(1);
      for (OdfTableRow ctr : cTable.getRowList()) {
        if (ctr.getRowIndex() == 0) {
          OdfTableCell ctc0 = ctr.getCellByIndex(1);
          OdfTextParagraph ctcp0 = new OdfTextParagraph(contentDom);
          User u = samples.get(0).getProject().getSecurityProfile().getOwner();
          ctcp0.setTextContent(u.getFullName() + " " + u.getEmail());
          ctcp0.setProperty(StyleTextPropertiesElement.FontSize, "12pt");
          ctc0.getOdfElement().appendChild(ctcp0);
        }
      }
      */

      OdfTable oTable = oDoc.getTableByName("SamplesTable");

      for (Sample s : samples) {
        OdfTableRow row = oTable.appendRow();

        OdfTableCell cell0 = row.getCellByIndex(0);
        OdfTextParagraph cp0 = new OdfTextParagraph(contentDom);
        cp0.setTextContent(s.getAlias());
        cp0.setProperty(StyleTextPropertiesElement.FontSize, "8pt");
        cell0.getOdfElement().appendChild(cp0);

        OdfTableCell cell1 = row.getCellByIndex(1);
        OdfTextParagraph cp1 = new OdfTextParagraph(contentDom);
        cp1.setTextContent(s.getScientificName());
        cp1.setProperty(StyleTextPropertiesElement.FontSize, "8pt");
        cell1.getOdfElement().appendChild(cp1);

        OdfTableCell cell2 = row.getCellByIndex(2);
        OdfTextParagraph cp2 = new OdfTextParagraph(contentDom);
        cp2.setTextContent(s.getIdentificationBarcode());
        cp2.setProperty(StyleTextPropertiesElement.FontSize, "8pt");
        cell2.getOdfElement().appendChild(cp2);

        OdfTableCell cell3 = row.getCellByIndex(3);
        OdfTextParagraph cp3 = new OdfTextParagraph(contentDom);
        cp3.setTextContent(s.getSampleType());
        cp3.setProperty(StyleTextPropertiesElement.FontSize, "8pt");
        cell3.getOdfElement().appendChild(cp3);
      }

      int count = 0;
      for (OdfTableRow row : oTable.getRowList()) {
        if (count % 2 != 0) {
          for (int i = 0; i < row.getCellCount(); i++) {
            row.getCellByIndex(i).setCellBackgroundColor("#EEEEEE");
          }
        }
        count++;
      }

      oDoc.save(outpath);
      return oDoc;
    }
    else {
      throw new Exception("Could not read from resource");
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfTextDocument

    }
  }

  public static List<Sample> importSampleDeliveryForm(File inPath) throws Exception {
    List<Sample> samples = new ArrayList<Sample>();
    OdfTextDocument oDoc = (OdfTextDocument) OdfDocument.loadDocument(inPath);
    OdfTable sampleTable = oDoc.getTableList().get(1);

    if (sampleTable != null) {
      DataObjectFactory df = new TgacDataObjectFactory();
      for (OdfTableRow row : sampleTable.getRowList()) {
        if (row.getRowIndex() != 0) {
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfTextDocument

  }

  @Test
  public void testConvertToPdf() {
    try {
      OdfTextDocument oDoc = uk.ac.bbsrc.tgac.miso.core.util.FormUtils.createSampleDeliveryForm(generateSamples(), testSampleDeliveryFile);
      uk.ac.bbsrc.tgac.miso.core.util.FormUtils.convertToPDF(oDoc);
    }
    catch (Exception e) {
      e.printStackTrace();
      TestCase.fail();
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfTextDocument

  }

  @Test
  public void testReadDocumentMeta() throws Exception {
    // create a new empty document
    OdfTextDocument textDoc = OdfTextDocument.newTextDocument(); // activiating metadata updates
    textDoc.save(ResourceUtilities.newTestOutputFile("DocForMetaTest.odt"));
    textDoc.close();
    // read empty document meta
    textDoc = (OdfTextDocument) OdfTextDocument.loadDocument(ResourceUtilities.getAbsolutePath("DocForMetaTest.odt"));
    OdfOfficeMeta meta = textDoc.getOfficeMetadata();
    Assert.assertNotNull(meta.getGenerator());
    Assert.assertNotNull(meta.getCreationDate());
    Assert.assertNotNull(meta.getCreator());
    Assert.assertNotNull(meta.getDate());
    Assert.assertTrue(meta.getEditingCycles() > 0);
    Assert.assertNotNull(meta.getEditingDuration());
    Assert.assertNull(meta.getLanguage());
    textDoc.close();
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfTextDocument

  public void testWikiExamples1() throws Exception {

    // WIKI EXAMPLE I from http://odftoolkit.org/projects/odfdom/pages/Home

    // Create a text document from a standard template (empty documents within the JAR)
    OdfTextDocument odt = OdfTextDocument.newTextDocument();

    // Append text to the end of the document.
    odt.addText("This is my very first ODF test");

    // Save document
    odt.save("MyFilename.odt");
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfTextDocument

    //********************************************************************
    // WIKI EXAMPLE II from http://odftoolkit.org/projects/odfdom/pages/Layers

    // Load file
    OdfTextDocument odt = (OdfTextDocument) OdfDocument.loadDocument("ImageIn.odt");

    // get root of all content of a text document
    OfficeTextElement officeText = odt.getContentRoot();

    // get first paragraph
    TextPElement firstParagraph =
      OdfElement.findFirstChildNode(TextPElement.class, officeText);

    // XPath alternative to get the first paragraph
    /*
      XPath xpath = XPathFactory.newInstance().newXPath();
      xpath.setNamespaceContext(new OdfNamespace());
      OdfFileDom dom = odt.getContentDom();
      firstParagraph = (TextPElement) xpath.evaluate("//text:p[1]", dom, XPathConstants.NODE);
    */

    // insert a frame
    DrawFrameElement frame = firstParagraph.newDrawFrameElement();

    // insert an image: This is a class from the Document API
    OdfDrawImage image = (OdfDrawImage) frame.newDrawImageElement();
    image.newImage(new URI("./MySampleImage.png"));

    // Save file
    odt.save("ImageOut.odt");

    //********************************************************************
    // WIKI EXAMPLE III from http://odftoolkit.org/projects/odfdom/pages/Layers

    // Load Image
    odt = (OdfTextDocument) OdfDocument.loadDocument("ImageIn.odt");

    // Play around with text
    odt.addText("When there is no paragraph, the text will be embedded in a new paragraph");
    odt.newParagraph("Create new paragraph");
    odt.addText("\nThis is a new line");

    // Insert Image and make last paragraph its anchor
    odt.newImage(new URI("./MySampleImage.png"));

    // Insert new spreadsheet as sub document into the package within directory  "myOdsDirectoryPath/"
    odt.insertDocument(OdfSpreadsheetDocument.newSpreadsheetDocument(), "myOdsDirectoryPath");

    // Save file
    odt.save("ImageOut.odt");
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfTextDocument

    @Test
  @Ignore
  /** Should there be a validation in the future? */
    public void testSetValue() throws Exception {
        OdfTextDocument odt = OdfTextDocument.newTextDocument();
        OdfContentDom dom = odt.getContentDom();
        OdfStyle style1 = new OdfStyle(dom);

        // No exception should be thrown here
        style1.setStyleFamilyAttribute(OdfStyleFamily.Paragraph.toString());
        assertEquals(style1.getStyleFamilyAttribute(), OdfStyleFamily.Paragraph.toString());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.