Package org.odftoolkit.odfdom.incubator.doc.office

Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles


      //1.2. if the child element is an OdfStylableElement, get the style-name ref count
      ////////////////
      //method 2:
      //2.1. get the list of the style definition
      ArrayList<OdfElement> removeStyles = new ArrayList<OdfElement>();
      OdfOfficeAutomaticStyles autoStyles = getContentDom().getAutomaticStyles();

      NodeList stylesList = autoStyles.getChildNodes();
      OdfContentDom contentDom = getContentDom();
      XPath xpath = contentDom.getXPath();

      //2.2. get the reference of each style which occurred in the current page
      for (int i = 0; i < stylesList.getLength(); i++) {
        Node item = stylesList.item(i);
        if (item instanceof OdfElement) {
          OdfElement node = (OdfElement) item;
          String styleName = node.getAttributeNS(OdfDocumentNamespace.STYLE.getUri(), "name");
          if (styleName != null) {
            //search the styleName contained at the current page element
            NodeList styleNodes = (NodeList) xpath.evaluate("//*[@*='" + styleName + "']", contentDom, XPathConstants.NODESET);
            int styleCnt = styleNodes.getLength();
            if (styleCnt > 1) {
              //the first styleName is occurred in the style definition
              //so check if the second styleName and last styleName is occurred in the current page element
              //if yes, then remove it
              OdfElement elementFirst = (OdfElement) styleNodes.item(1);
              OdfElement elementLast = (OdfElement) styleNodes.item(styleCnt - 1);
              boolean isSamePage = false;
              if (elementFirst instanceof DrawPageElement) {
                DrawPageElement tempPage = (DrawPageElement) elementFirst;
                if (tempPage.equals(slideEle)) {
                  isSamePage = true;
                }
              }
              int relationFirst = slideEle.compareDocumentPosition(elementFirst);
              int relationLast = slideEle.compareDocumentPosition(elementLast);
              //if slide element contains the child element which has the styleName reference
              if (((relationFirst & Node.DOCUMENT_POSITION_CONTAINED_BY) > 0
                  && (relationLast & Node.DOCUMENT_POSITION_CONTAINED_BY) > 0)
                  || (isSamePage && (styleCnt == 1))) {
                if (node instanceof OdfStyleBase) {
                  removeStyles.add(node);
                }
              }
            } else {
              continue;
            }
          }
        }
      }
      for (int i = 0; i < removeStyles.size(); i++) {
        autoStyles.removeChild(removeStyles.get(i));
      }
    } catch (Exception e) {
      Logger.getLogger(OdfPresentationDocument.class.getName()).log(Level.SEVERE, null, e);
      success = false;
    }
View Full Code Here


    return unique_name;
  }

  private String getUniquePercentageStyleName() {
    String unique_name;
    OdfOfficeAutomaticStyles styles = mCellElement.getAutomaticStyles();
    do {
      unique_name = String.format("p%06x", (int) (Math.random() * 0xffffff));
    } while (styles.getPercentageStyle(unique_name) != null);
    return unique_name;
  }
View Full Code Here

//    } while (styles.getStyle(unique_name, OdfStyleFamily.TableCell) != null);
//      return unique_name;
//    } 
  private String getUniqueCurrencyStyleName() {
    String unique_name;
    OdfOfficeAutomaticStyles styles = mCellElement.getAutomaticStyles();
    do {
      unique_name = String.format("c%06x", (int) (Math.random() * 0xffffff));
    } while (styles.getCurrencyStyle(unique_name) != null);
    return unique_name;
  }
View Full Code Here

    OdfTextListStyle style = null;

    String listName = getTextStyleNameAttribute();
    if (listName != null && listName.length() > 0) {
      OdfFileDom fileDom = (OdfFileDom) this.ownerDocument;
      OdfOfficeAutomaticStyles autoStyles = null;
      if(fileDom instanceof OdfContentDom){
        autoStyles = ((OdfContentDom) fileDom).getAutomaticStyles();
      }else if(fileDom instanceof OdfStylesDom){
        autoStyles = ((OdfStylesDom) fileDom).getAutomaticStyles();
      }     
      if (autoStyles != null) {
        style = autoStyles.getListStyle(listName);
      }
      if (style == null) {
        OdfOfficeStyles styles = ((OdfSchemaDocument) fileDom.getDocument()).getDocumentStyles();
        if (styles != null) {
          style = styles.getListStyle(listName);
View Full Code Here

   * @return the <code>OdfTextListStyle</code> element
   */
  public OdfTextListStyle getOrCreateLocalListStyle() {
    OdfTextListStyle listStyle = getListStyle();
    if (listStyle == null) {
      OdfOfficeAutomaticStyles autoStyles = null;
      OdfFileDom fileDom = ((OdfFileDom) this.ownerDocument);
      if(fileDom instanceof OdfContentDom){
        autoStyles = ((OdfContentDom) fileDom).getOrCreateAutomaticStyles();
      }else if(fileDom instanceof OdfStylesDom){
        autoStyles = ((OdfStylesDom) fileDom).getOrCreateAutomaticStyles();
     
      if (autoStyles != null) {
        listStyle = autoStyles.newListStyle();
      }
    }
    return listStyle;
  }
View Full Code Here

      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");
      Assert.assertEquals(pageLayout.getProperty(StylePageLayoutPropertiesElement.PageHeight), "11in");

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

    } catch (Exception e) {
      LOG.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
View Full Code Here

      Document odfdoc = Document.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE));

      OdfContentDom contentDom = odfdoc.getContentDom();

      // test content.xml:automatic-styles
      OdfOfficeAutomaticStyles autoStyles = contentDom.getAutomaticStyles();
      Assert.assertNotNull(autoStyles);

      OdfStyle style = autoStyles.getStyle("P1", OdfStyleFamily.Paragraph);
      Assert.assertNotNull(style);
      Assert.assertEquals(style.getStyleNameAttribute(), "P1");
      Assert.assertEquals(style.getStyleParentStyleNameAttribute(), "Text_20_body");
      Assert.assertEquals(style.getStyleListStyleNameAttribute(), "L1");

      style = autoStyles.getStyle("T1", OdfStyleFamily.Text);
      Assert.assertNotNull(style);
      Assert.assertEquals(style.getStyleNameAttribute(), "T1");

      for (OdfStyle testStyle : autoStyles.getStylesForFamily(OdfStyleFamily.Paragraph)) {
        testStyle(testStyle);
      }

      for (OdfStyle testStyle : autoStyles.getStylesForFamily(OdfStyleFamily.Text)) {
        testStyle(testStyle);
      }

    } catch (Exception e) {
      LOG.log(Level.SEVERE, e.getMessage(), e);
View Full Code Here

    }
  }

  private void testStyle(OdfStyle testStyle) throws Exception {
    OdfFileDom fileDom = (OdfFileDom) testStyle.getOwnerDocument();
    OdfOfficeAutomaticStyles autoStyles = null;
    if (testStyle.getStyleParentStyleNameAttribute() != null) {
      if (fileDom instanceof OdfContentDom) {
        autoStyles = ((OdfContentDom) fileDom).getAutomaticStyles();
      } else if (fileDom instanceof OdfStylesDom) {
        autoStyles = ((OdfStylesDom) fileDom).getAutomaticStyles();
      }
      OdfStyle parentStyle = autoStyles.getStyle(testStyle.getStyleParentStyleNameAttribute(), testStyle.getFamily());
      if (parentStyle == null) {
        parentStyle = ((Document) fileDom.getDocument()).getDocumentStyles().getStyle(testStyle.getStyleParentStyleNameAttribute(), testStyle.getFamily());
      }

      Assert.assertNotNull(parentStyle);
    }
    if (testStyle.hasOdfAttribute(OdfName.newName(OdfDocumentNamespace.STYLE, "list-style-name"))) {
      if (testStyle.getStyleListStyleNameAttribute() != null) {
        OdfTextListStyle listStyle = autoStyles.getListStyle(testStyle.getStyleListStyleNameAttribute());
        if (listStyle == null) {
          listStyle = ((Document) fileDom.getDocument()).getDocumentStyles().getListStyle(testStyle.getStyleListStyleNameAttribute());
        }

        Assert.assertNotNull(listStyle);
View Full Code Here

  }

  @Test
  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);
View Full Code Here

      Paragraph paragraph, MasterPage masterPage) throws Exception {
    Node paragraphNode = paragraph.getOdfElement().getNextSibling();
    Assert.assertTrue(paragraphNode instanceof TextPElement);

    // check paragraph style
    OdfOfficeAutomaticStyles styles = newDoc.getContentDom()
        .getAutomaticStyles();
    OdfStyle style = styles.getStyle(((TextPElement) paragraphNode)
        .getStyleName(), OdfStyleFamily.Paragraph);
    Assert.assertNotNull(style);

    // check master page style
    String masterName = style.getStyleMasterPageNameAttribute();
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

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.