Examples of OdfDocument


Examples of org.odftoolkit.odfdom.doc.OdfDocument

    }
  }

  @Test
  public void displayActualFontForEachTextNode() throws Exception {
    OdfDocument odfDocument = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE));

    OdfElement documentRoot = (OdfElement) odfDocument.getContentDom().getDocumentElement();

    ArrayList<String> fontAndText = new ArrayList<String>();

    DumpPropertyAndText dumpFontAndText = new DumpPropertyAndText(StyleTextPropertiesElement.FontName);
    dumpFontAndText.performAction(documentRoot, fontAndText);
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

  @Test
  @SuppressWarnings("unchecked")
  public void dumpAllStyles() throws Exception {
    if (LOG.isLoggable(INFO)) {
      OdfDocument odfdoc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE));
      LOG.info("Parsed document.");

      OdfElement e = (OdfElement) odfdoc.getContentDom().getDocumentElement();
      NodeAction dumpStyles = new NodeAction() {

        @Override
        protected void apply(Node node, Object arg, int depth) {
          String indent = new String();
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

  }

  @Test
  public void testDefaultStyles() {
    try {
      OdfDocument doc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE));

      doc.getDocumentStyles();
      OdfDefaultStyle oDSG = doc.getDocumentStyles().getDefaultStyle(OdfStyleFamily.Graphic);
      Assert.assertEquals(oDSG.getFamilyName(), OdfStyleFamily.Graphic.getName());
      String prop1 = oDSG.getProperty(StyleGraphicPropertiesElement.ShadowOffsetX);
      Assert.assertEquals(prop1, "0.1181in");

      OdfDefaultStyle oDSP = doc.getDocumentStyles().getDefaultStyle(OdfStyleFamily.Paragraph);
      Assert.assertEquals(oDSP.getFamilyName(), OdfStyleFamily.Paragraph.getName());
      String prop2 = oDSP.getProperty(StyleTextPropertiesElement.FontName);
      Assert.assertEquals(prop2, "Thorndale");
      String prop3 = oDSP.getProperty(StyleTextPropertiesElement.LetterKerning);
      Assert.assertEquals(prop3, "true");

      OdfDefaultStyle oDST = doc.getDocumentStyles().getDefaultStyle(OdfStyleFamily.Table);
      Assert.assertEquals(oDST.getFamilyName(), OdfStyleFamily.Table.getName());
      String prop4 = oDST.getProperty(StyleTablePropertiesElement.BorderModel);
      Assert.assertEquals(prop4, "collapsing");


      OdfDefaultStyle oDSTR = doc.getDocumentStyles().getDefaultStyle(OdfStyleFamily.TableRow);
      Assert.assertEquals(oDSTR.getFamilyName(), OdfStyleFamily.TableRow.getName());
      String prop5 = oDSTR.getProperty(StyleTableRowPropertiesElement.KeepTogether);
      Assert.assertEquals(prop5, "auto");

    } catch (Exception e) {
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

  @Test
  public void testPackage() {
    File tmpFile1 = ResourceUtilities.newTestOutputFile(TARGET_STEP_1);
    File tmpFile2 = ResourceUtilities.newTestOutputFile(TARGET_STEP_2);
    File tmpFile3 = ResourceUtilities.newTestOutputFile(TARGET_STEP_3);
    OdfDocument doc = null;
    try {
      doc = OdfSpreadsheetDocument.newSpreadsheetDocument();
      doc.save(tmpFile1);
      doc.close();
    } catch (Exception ex) {
      LOG.log(Level.SEVERE, mImagePath, ex);
      Assert.fail();
    }
   
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

  }
 
  @Test
  public void testPackagePassword() {
    File tmpFile = ResourceUtilities.newTestOutputFile("PackagePassword.ods");
    OdfDocument doc = null;
    try {
      doc = OdfSpreadsheetDocument.newSpreadsheetDocument();
      doc.getPackage().setPassword("password");
      doc.save(tmpFile);
      doc.close();
      OdfPackage odfPackage = OdfPackage.loadPackage(tmpFile, "password", null);
      byte[] contentBytes = odfPackage.getBytes("content.xml");
      Assert.assertNotNull(contentBytes);
    } catch (Exception ex) {
      LOG.log(Level.SEVERE, "password test failed.", ex);
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

    }
  }

  private void writeToLog() throws Exception {
    FileInputStream timefile, memoryfile;
    OdfDocument timedoc, memorydoc;

    if (TEST_FILE_NAME == null) {
      return;
    }

    try {
      timefile = new FileInputStream(time_spreadsheet);
      timedoc = OdfDocument.loadDocument(timefile);
    } catch (FileNotFoundException e) {
      //Create an empty spreadsheet
      timedoc = OdfSpreadsheetDocument.newSpreadsheetDocument();
      OfficeSpreadsheetElement spreadsheet = (OfficeSpreadsheetElement) timedoc.getContentDom().getElementsByTagNameNS(
          OdfDocumentNamespace.OFFICE.getUri(), "spreadsheet").item(0);
      spreadsheet.removeChild(spreadsheet.getFirstChild());
    }

    try {
      memoryfile = new FileInputStream(memory_spreadsheet);
      memorydoc = OdfDocument.loadDocument(memoryfile);
    } catch (FileNotFoundException e) {
      //Create an empty spreadsheet
      memorydoc = OdfSpreadsheetDocument.newSpreadsheetDocument();
      OfficeSpreadsheetElement spreadsheet = (OfficeSpreadsheetElement) memorydoc.getContentDom().getElementsByTagNameNS(
          OdfDocumentNamespace.OFFICE.getUri(), "spreadsheet").item(0);
      spreadsheet.removeChild(spreadsheet.getFirstChild());
    }

    String[] summaryName = new String[]{"Load All Documents", "Parse All Documents", "Save All Documents"};
    updateTableCells(timedoc, "Summary", totalTime, summaryName);
    updateTableCells(timedoc, "Load ODF", totalLoadTimeForEach, TEST_FILE_NAME);
    updateTableCells(timedoc, "Parse ODF", totalParseTimeForEach, TEST_FILE_NAME);
    updateTableCells(timedoc, "Save ODF", totalSaveTimeForEach, TEST_FILE_NAME);

    String[] memorylabel = new String[TEST_FILE_NAME.length * 3];
    for (int i = 0; i < TEST_FILE_NAME.length; i++) {
      memorylabel[3 * i] = "load " + TEST_FILE_NAME[i];
      memorylabel[3 * i + 1] = "parse " + TEST_FILE_NAME[i];
      memorylabel[3 * i + 2] = "save " + TEST_FILE_NAME[i];
    }
    updateTableCells(memorydoc, "Memory footprint", memoryfootprint, memorylabel);

    timedoc.save(time_spreadsheet);
    LOG.log(Level.INFO, "[PerformaceTest] Test results are written to {0}", time_spreadsheet);
    memorydoc.save(memory_spreadsheet);
    LOG.log(Level.INFO, "[PerformaceTest] Test results are written to {0}", memory_spreadsheet);
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

      LOG.log(Level.SEVERE, null, e);
    }
  }

  private void firsttry() throws Exception {
    OdfDocument doc = null;
    OdfFileDom dom = null;
    String filename = null;

    for (int j = 0; j < TEST_FILE_NAME.length; j++) {
      filename = TEST_FILE_FOLDER + TEST_FILE_NAME[j];
      LOG.log(Level.INFO, "filename:{0}", filename);
      doc = OdfDocument.loadDocument(filename);
      dom = doc.getContentDom();
      doc.save(filename);
    }
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

    }
  }

  private void test() throws Exception {
    long start, end;
    OdfDocument doc = null;
    OdfFileDom dom = null;
    String filename = null;

    if (TEST_FILE_NAME == null) {
      return;
    }

    firsttry();

    for (int i = 0; i < count; i++) {
      for (int j = 0; j < TEST_FILE_NAME.length; j++) {
        filename = TEST_FILE_FOLDER + TEST_FILE_NAME[j];
        start = System.currentTimeMillis();
        doc = OdfDocument.loadDocument(filename);
        end = System.currentTimeMillis();
        totalLoadTimeForEach[j] += end - start;
        totalTime[0] += end - start;
        if (i == 0) {
          System.gc();
          memoryfootprint[3 * j] = Runtime.getRuntime().totalMemory()
              - Runtime.getRuntime().freeMemory();
        }

        start = System.currentTimeMillis();
        dom = doc.getContentDom();
        end = System.currentTimeMillis();
        totalParseTimeForEach[j] += end - start;
        totalTime[1] += end - start;
        if (i == 0) {
          System.gc();
          memoryfootprint[3 * j + 1] = Runtime.getRuntime().totalMemory()
              - Runtime.getRuntime().freeMemory();
        }

        start = System.currentTimeMillis();
        doc.save(filename);
        end = System.currentTimeMillis();
        totalSaveTimeForEach[j] += end - start;
        totalTime[2] += end - start;

        doc = null;
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

   * this test case is used to embed E1 to another document B
   */
  @Test
  public void testEmbedEmbeddedDocument() {
    try {
      OdfDocument doc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE_EMBEDDED));
      OdfDocument saveDoc = OdfTextDocument.newTextDocument();
      Map<String, OdfDocument> subDocs = doc.loadSubDocuments();
      List<String> subDocNames = new ArrayList<String>();
      for (String childDocPath : subDocs.keySet()) {
        OdfDocument childDoc = subDocs.get(childDocPath);
        String embeddedDocPath = childDoc.getDocumentPath();
        saveDoc.insertDocument(childDoc, embeddedDocPath);
        subDocNames.add(embeddedDocPath);
      }
      Set<String> paths = saveDoc.getPackage().getDocumentPaths();
      int docCount = paths.size();
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

  @Test
  public void testembeddedDocumentsLocatedSideBySide() {
    try {
      OdfTextDocument odtRootDoc = OdfTextDocument.newTextDocument();
      odtRootDoc.insertDocument(OdfTextDocument.newTextDocument(), "DOCA/");
      OdfDocument docA = odtRootDoc.loadSubDocument("DOCA");
      docA.newImage(ResourceUtilities.getURI(TEST_PIC));
      docA.insertDocument(OdfSpreadsheetDocument.newSpreadsheetDocument(), "../DOCB/");
      OdfFileDom contentA = docA.getContentDom();
      XPath xpath = contentA.getXPath();
      TextPElement lastPara = (TextPElement) xpath.evaluate("//text:p[last()]", contentA, XPathConstants.NODE);
      addFrameForEmbeddedDoc(contentA, lastPara, "DOCB");
      OdfDocument docB = odtRootDoc.loadSubDocument("DOCB/");
      Assert.assertNotNull(docB);
      Assert.assertNull(odtRootDoc.loadSubDocument("DOCA/DOCB/"));
      docB.newImage(ResourceUtilities.getURI(TEST_PIC_ANOTHER));
      OdfTable table1 = docB.getTableList().get(0);
      table1.setTableName("NewTable");
      updateFrameForEmbeddedDoc(contentA, "./DOCB", "DOCA/DOCB");
      //if user want to save the docA with the side by side embedded document
      //he has to insert it to the sub document of docA and update the xlink:href link
      docA.insertDocument(docB, "DOCB/");
      //save
      docA.save(TEST_FILE_FOLDER + TEST_FILE_EMBEDDED_SIDEBYSIDE_SAVE_OUT);
      OdfDocument testLoad = OdfDocument.loadDocument(TEST_FILE_FOLDER + TEST_FILE_EMBEDDED_SIDEBYSIDE_SAVE_OUT);
      OdfFileEntry imageEntry = testLoad.getPackage().getFileEntry(OdfPackage.OdfFile.IMAGE_DIRECTORY.getPath() + SLASH + TEST_PIC);
      Assert.assertNotNull(imageEntry);
      Map<String, OdfDocument> embDocs = testLoad.loadSubDocuments(OdfDocument.OdfMediaType.SPREADSHEET);
      for(String embedDocPath : embDocs.keySet()){
        OdfDocument doc1 = embDocs.get(embedDocPath);
        imageEntry = doc1.getPackage().getFileEntry(doc1.getDocumentPath() + OdfPackage.OdfFile.IMAGE_DIRECTORY.getPath() + SLASH + TEST_PIC_ANOTHER);
        Assert.assertNotNull(doc1.getTableByName("NewTable"));
      }
    } catch (Exception ex) {
      LOG.log(Level.SEVERE, null, ex);
      Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
    }
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.