Package org.odftoolkit.simple

Examples of org.odftoolkit.simple.Document


  }

  private String getFontFamilyNameFromFontName(String aFontName) {
    try {
      // try if the font has been defined.
      Document mDocument = ((Document) ((OdfFileDom) mElement.getOwnerDocument()).getDocument());
      // find <office:font-face-decls> in content dom
      OdfContentDom contentDom = mDocument.getContentDom();
      OfficeFontFaceDeclsElement fontfaceDecls = OdfElement.findFirstChildNode(OfficeFontFaceDeclsElement.class,
          contentDom.getRootElement());
      if (fontfaceDecls == null) {
        // find <office:font-face-decls> in style dom
        OdfStylesDom styleDom = mDocument.getStylesDom();
        fontfaceDecls = OdfElement.findFirstChildNode(OfficeFontFaceDeclsElement.class, styleDom
            .getRootElement());
      }
      if (fontfaceDecls == null)
        return null;
View Full Code Here


  private String getFontNameFromFamilyName(String aFamilyName) {
    String aFontName = aFamilyName;
    boolean duplicated = false;
    try {
      // try if the font has been defined.
      Document mDocument = ((Document) ((OdfFileDom) mElement.getOwnerDocument()).getDocument());
      // find <office:font-face-decls> in content dom
      OdfContentDom contentDom = mDocument.getContentDom();
      OfficeFontFaceDeclsElement fontfaceDecls = OdfElement.findFirstChildNode(OfficeFontFaceDeclsElement.class,
          contentDom.getRootElement());
      if (fontfaceDecls == null) {
        // find <office:font-face-decls> in style dom
        OdfStylesDom styleDom = mDocument.getStylesDom();
        fontfaceDecls = OdfElement.findFirstChildNode(OfficeFontFaceDeclsElement.class, styleDom
            .getRootElement());
        if (fontfaceDecls == null)
          fontfaceDecls = contentDom.getRootElement().newOfficeFontFaceDeclsElement();
      }
View Full Code Here

  public boolean removeList(List list) {
    OdfElement containerElement = getListContainerElement();
    Node child = containerElement.getFirstChild();
    OdfFileDom ownerDocument = (OdfFileDom) containerElement.getOwnerDocument();
    Document doc = (Document) ownerDocument.getDocument();
    while (child != null) {
      if (child instanceof TextListElement) {
        TextListElement listElement1 = (TextListElement) child;
        String id1 = listElement1.getXmlIdAttribute();
        TextListElement listElement2 = list.getOdfElement();
        String id2 = listElement2.getXmlIdAttribute();
        if ((listElement1 == listElement2) || ((id1 != null) && (id2 != null) && (id1.equals(id2)))) {
          doc.removeElementLinkedResource(listElement1);
          containerElement.removeChild(child);
          return true;
        }
      }
      child = child.getNextSibling();
View Full Code Here

    }
  }

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

    if (TEST_FILE_NAME == null) {
      return;
    }

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

    try {
      memoryfile = new FileInputStream(memory_spreadsheet);
      memorydoc = Document.loadDocument(memoryfile);
    } catch (FileNotFoundException e) {
      //Create an empty spreadsheet
      memorydoc = SpreadsheetDocument.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

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

  private void firsttry() throws Exception {
    Document 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 = Document.loadDocument(filename);
      dom = doc.getContentDom();
      doc.save(filename);
    }
  }
View Full Code Here

    }
  }

  private void test() throws Exception {
    long start, end;
    Document 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 = Document.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

   * function.
   */
  @Test
  public void testToString() {
    try {
      Document doc = Document.loadDocument(ResourceUtilities.getTestResourceAsStream("text-extract.odt"));
      EditableTextExtractor extractor = EditableTextExtractor.newOdfEditableTextExtractor(doc);
      String output = extractor.getText();
      LOG.info(output);
      int count = 0;
      int index = output.indexOf("SIMPLE");
View Full Code Here

  public OdfElement getListContainerElement() {
    return getListContainerImpl().getListContainerElement();
  }

  public org.odftoolkit.simple.text.list.List addList() {
    Document ownerDocument = getTable().getOwnerDocument();
    if (ownerDocument instanceof SpreadsheetDocument) {
      throw new UnsupportedOperationException(
          "Open Office and Symphony can't show a list in spreadsheet document cell.");
    } else {
      return getListContainerImpl().addList();
View Full Code Here

      return getListContainerImpl().addList();
    }
  }

  public org.odftoolkit.simple.text.list.List addList(ListDecorator decorator) {
    Document ownerDocument = getTable().getOwnerDocument();
    if (ownerDocument instanceof SpreadsheetDocument) {
      throw new UnsupportedOperationException(
          "Open Office and Symphony can't show a list in spreadsheet document cell.");
    } else {
      return getListContainerImpl().addList(decorator);
View Full Code Here

  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////// private methods ///////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
  private TableContentValidationElement getContentValidationEle() throws Exception {
    Document ownerDocument = getOwnerDocument();
    OdfElement contentRootElement = ownerDocument.getContentRoot();
    TableContentValidationsElement validations = OdfElement.findFirstChildNode(
        TableContentValidationsElement.class, contentRootElement);
    if (validations == null) {
      validations = (TableContentValidationsElement) OdfXMLFactory.newOdfElement(ownerDocument
          .getContentDom(), OdfName.newName(OdfDocumentNamespace.TABLE, "content-validations"));
      contentRootElement.insertBefore(validations, contentRootElement.getFirstChild());
    }
    String validationName = getOdfElement().getTableContentValidationNameAttribute();
    TableContentValidationElement validationElement = null;
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.Document

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.