Examples of OdfStylesDom


Examples of org.odftoolkit.odfdom.dom.OdfStylesDom

      // count the initial date field count. should be 1.
      OdfContentDom contentDom = doc.getContentDom();
     
      NodeList nodeList = contentDom.getElementsByTagName(TextAuthorInitialsElement.ELEMENT_NAME.getQName());
      int i = nodeList.getLength();
      OdfStylesDom styleDom = doc.getStylesDom();
      nodeList = styleDom.getElementsByTagName(TextAuthorInitialsElement.ELEMENT_NAME.getQName());
      i += nodeList.getLength();
      // replace all the 3 "ReplaceDateTarget" to FixedDateField.
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        FieldSelection fieldSelection = new FieldSelection(item);
        fieldSelection.replaceWithSimpleField(Field.FieldType.AUTHOR_INITIALS_FIELD);
        i++;
      }
     
      //validate
      nodeList = contentDom.getElementsByTagName(TextAuthorInitialsElement.ELEMENT_NAME.getQName());
      int j = nodeList.getLength();
      nodeList = styleDom.getElementsByTagName(TextAuthorInitialsElement.ELEMENT_NAME.getQName());
      j += nodeList.getLength();
      Assert.assertEquals(j, i);
     
      //save
      doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE));
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfStylesDom

      // count the initial date field count. should be 1.
      OdfContentDom contentDom = doc.getContentDom();
     
      NodeList nodeList = contentDom.getElementsByTagName(TextChapterElement.ELEMENT_NAME.getQName());
      int i = nodeList.getLength();
      OdfStylesDom styleDom = doc.getStylesDom();
      nodeList = styleDom.getElementsByTagName(TextChapterElement.ELEMENT_NAME.getQName());
      i += nodeList.getLength();
      // replace all the 3 "ReplaceDateTarget" to FixedDateField.
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        FieldSelection fieldSelection = new FieldSelection(item);
        fieldSelection.replaceWithSimpleField(Field.FieldType.CHAPTER_FIELD);
        i++;
      }
     
      //validate
      nodeList = contentDom.getElementsByTagName(TextChapterElement.ELEMENT_NAME.getQName());
      int j = nodeList.getLength();
      nodeList = styleDom.getElementsByTagName(TextChapterElement.ELEMENT_NAME.getQName());
      j += nodeList.getLength();
      Assert.assertEquals(j, i);
     
      //save
      doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE));
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfStylesDom

      //Extract text from content.xml
      OdfEditableTextExtractor contentDomExtractor = newOdfEditableTextExtractor(mDocument.getContentRoot());
      builder.append(contentDomExtractor.getText());

      //Extract text from style.xml
      OdfStylesDom styleDom = mDocument.getStylesDom();
      if (styleDom != null) {
        StyleMasterPageElement masterpage = null;
        NodeList list = styleDom.getElementsByTagName("style:master-page");
        if (list.getLength() > 0) {
          masterpage = (StyleMasterPageElement) list.item(0);
        }
        if (masterpage != null) {
          builder.append(newOdfEditableTextExtractor(masterpage).getText());
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfStylesDom

      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

Examples of org.odftoolkit.odfdom.dom.OdfStylesDom

      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

Examples of org.odftoolkit.odfdom.dom.OdfStylesDom

  @Test
  public void testStylesDom() {
    try {
      Document odfdoc = Document.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE));

      OdfStylesDom stylesDom = odfdoc.getStylesDom();
      Assert.assertNotNull(stylesDom);

      // test styles.xml:styles
      OdfOfficeStyles styles = odfdoc.getDocumentStyles();
      Assert.assertNotNull(styles);

      Assert.assertNotNull(styles.getDefaultStyle(OdfStyleFamily.Graphic));
      Assert.assertNotNull(styles.getDefaultStyle(OdfStyleFamily.Paragraph));
      Assert.assertNotNull(styles.getDefaultStyle(OdfStyleFamily.Table));
      Assert.assertNotNull(styles.getDefaultStyle(OdfStyleFamily.TableRow));

      OdfStyle style = styles.getStyle("Standard", OdfStyleFamily.Paragraph);
      Assert.assertNotNull(style);
      Assert.assertEquals(style.getStyleClassAttribute(), "text");

      style = styles.getStyle("List", OdfStyleFamily.Paragraph);
      Assert.assertNotNull(style);
      Assert.assertEquals(style.getProperty(StyleTextPropertiesElement.FontNameComplex), "Tahoma1");
      Assert.assertTrue(style.hasProperty(StyleTextPropertiesElement.FontNameComplex));
      Assert.assertFalse(style.hasProperty(StyleTextPropertiesElement.FontNameAsian));

      Assert.assertNull(styles.getStyle("foobar", OdfStyleFamily.Chart));

      // test styles.xml:automatic-styles
      OdfOfficeAutomaticStyles autostyles = stylesDom.getAutomaticStyles();
      Assert.assertNotNull(autostyles);

      OdfStylePageLayout pageLayout = autostyles.getPageLayout("pm1");
      Assert.assertNotNull(pageLayout);
      Assert.assertEquals(pageLayout.getProperty(StylePageLayoutPropertiesElement.PageWidth), "8.5in");
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfStylesDom

      //Extract text from content.xml
      OdfEditableTextExtractor contentDomExtractor = newOdfEditableTextExtractor(mDocument.getContentRoot());
      builder.append(contentDomExtractor.getText());

      //Extract text from style.xml
      OdfStylesDom styleDom = mDocument.getStylesDom();
      if (styleDom != null) {
        StyleMasterPageElement masterpage = null;
        NodeList list = styleDom.getElementsByTagName("style:master-page");
        if (list.getLength() > 0) {
          masterpage = (StyleMasterPageElement) list.item(0);
        }
        if (masterpage != null) {
          builder.append(newOdfEditableTextExtractor(masterpage).getText());
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfStylesDom

  public void testStyleUsageCount() {
    try {
      OdfOfficeAutomaticStyles s = odfdoc.getStylesDom().getAutomaticStyles();
      OdfStyle pr1 = s.getStyle("pr1", OdfStyleFamily.Presentation);
      int styleUserCount = pr1.getStyleUserCount();
      OdfStylesDom stylesDom = odfdoc.getStylesDom();
      XPath xpath = stylesDom.getXPath();
      NodeList elementsWithStyle = (NodeList) xpath.evaluate("//draw:frame[@presentation:style-name='pr1']",
          stylesDom, XPathConstants.NODESET);
      int elementsWithStyleCount = elementsWithStyle.getLength();
      Assert.assertTrue(styleUserCount == elementsWithStyleCount);
//      //#bug51,the bug will be induced by using set attribute method
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfStylesDom

    for (int i = 0; i < num; i++) {
      try {
        long t1 = System.currentTimeMillis();
        OdfDocument doc = OdfDocument.loadDocument("src/test/resources/test1.odt");
        OdfContentDom dom1 = doc.getContentDom();
        OdfStylesDom dom2 = doc.getStylesDom();
        long t2 = System.currentTimeMillis() - t1;
        t = t + t2;
        LOG.info("Open in " + t2 + " milliseconds");
        long f1 = Runtime.getRuntime().freeMemory();
        doc.close();
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfStylesDom

    try {
      // Extract text from content.xml
      EditableTextExtractor contentDomExtractor = newOdfEditableTextExtractor(mDocument.getContentRoot());
      builder.append(contentDomExtractor.getText());
      // Extract text from style.xml
      OdfStylesDom styleDom = mDocument.getStylesDom();
      if (styleDom != null) {
        StyleMasterPageElement masterpage = null;
        NodeList list = styleDom.getElementsByTagName("style:master-page");
        if (list.getLength() > 0) {
          masterpage = (StyleMasterPageElement) list.item(0);
        }
        if (masterpage != null) {
          builder.append(newOdfEditableTextExtractor(masterpage).getText());
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.