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

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


 
  private void validPageBreakExist(TextDocument newDoc, Paragraph paragraph) throws Exception {
    Node paragraphNode = paragraph.getOdfElement().getNextSibling();
    Assert.assertTrue(paragraphNode instanceof TextPElement);
    OdfContentDom contentDocument = newDoc.getContentDom();
    OdfOfficeAutomaticStyles styles = contentDocument.getAutomaticStyles();
    OdfStyle style = styles.getStyle(((TextPElement) paragraphNode).getStyleName(), OdfStyleFamily.Paragraph);
    Assert.assertNotNull(style);
    Node paragraphPropertiesNode = style.getFirstChild();
    Assert.assertNotNull(paragraphPropertiesNode instanceof StyleParagraphPropertiesElement);
    Assert.assertEquals(((StyleParagraphPropertiesElement) paragraphPropertiesNode).getFoBreakBeforeAttribute(),
        "page");
View Full Code Here


  @Test
  public void testSetDefaultCellStyle() {
    SpreadsheetDocument outputDocument;
    OdfContentDom contentDom; // the document object model for content.xml
    // the office:automatic-styles element in content.xml
    OdfOfficeAutomaticStyles contentAutoStyles;
    OdfStyle style;
    String noaaDateStyleName;
    String noaaTempStyleName;

    try {
      outputDocument = SpreadsheetDocument.newSpreadsheetDocument();
      contentDom = outputDocument.getContentDom();
      contentAutoStyles = contentDom.getOrCreateAutomaticStyles();

      OdfNumberDateStyle dateStyle = new OdfNumberDateStyle(contentDom, "yyyy-MM-dd", "numberDateStyle", null);
      OdfNumberStyle numberStyle = new OdfNumberStyle(contentDom, "#0.00", "numberTemperatureStyle");

      contentAutoStyles.appendChild(dateStyle);
      contentAutoStyles.appendChild(numberStyle);

      style = contentAutoStyles.newStyle(OdfStyleFamily.TableCell);
      noaaDateStyleName = style.getStyleNameAttribute();
      style.setStyleDataStyleNameAttribute("numberDateStyle");

      // and for time cells
      style = contentAutoStyles.newStyle(OdfStyleFamily.TableCell);
      noaaTempStyleName = style.getStyleNameAttribute();
      style.setStyleDataStyleNameAttribute("numberTemperatureStyle");
      style.setProperty(StyleParagraphPropertiesElement.TextAlign, "end");

      Table table = Table.newTable(outputDocument);
      List<Column> columns = table.insertColumnsBefore(0, 3);
      Column column = columns.get(0);
      column.setDefaultCellStyle(contentAutoStyles.getStyle(noaaDateStyleName, OdfStyleFamily.TableCell));
      Cell aCell = column.getCellByIndex(0);
      aCell.setValueType("date");
      String format = aCell.getFormatString();
      Assert.assertEquals("yyyy-MM-dd", format);

      List<Row> rows = table.insertRowsBefore(0, 1);
      Row row = rows.get(0);
      row.setDefaultCellStyle(contentAutoStyles.getStyle(noaaTempStyleName, OdfStyleFamily.TableCell));
      Cell bCell = row.getCellByIndex(0);
      bCell.setValueType("float");
      String bformat = bCell.getFormatString();
      Assert.assertEquals("#0.00", bformat);
      Assert.assertEquals("end", bCell.getHorizontalAlignment());
View Full Code Here

    } else {
      try {
        String textStyleName = listElement.getTextStyleNameAttribute();
        Document doc = (Document) (((OdfFileDom) listElement.getOwnerDocument()).getDocument());
        OdfContentDom contentDocument = doc.getContentDom();
        OdfOfficeAutomaticStyles styles = contentDocument.getAutomaticStyles();
        OdfOfficeStyles documentStyles = doc.getDocumentStyles();
        OdfTextListStyle listStyle = styles.getListStyle(textStyleName);
        if (listStyle == null) {
          listStyle = documentStyles.getListStyle(textStyleName);
        }
        if (listStyle != null) {
          TextListLevelStyleElementBase listLevelStyle = listStyle.getLevel(1);
View Full Code Here

     */
    protected OdfStylePageLayout getWritableStyleElementByName(
        String styleName, boolean isShared) throws Exception {
      boolean createNew = isShared;
      OdfStylePageLayout pageLayout = null;
      OdfOfficeAutomaticStyles styles = mOdfElement.getAutomaticStyles();
      if (styleName == null || (styleName.equals(""))) {
        createNew = true;
        // TODO: get default page layout style
      } else {
        styles = mOdfElement.getAutomaticStyles();
        pageLayout = styles.getPageLayout(styleName);
        if (pageLayout == null || pageLayout.getStyleUserCount() > 1) {
          createNew = true;
        }
      }
      // if style name is null or this style are used by many users,
      // should create a new one.
      if (createNew) {
        OdfStylePageLayout newPageLayout = null;
        if (pageLayout != null) {
          newPageLayout = (OdfStylePageLayout) pageLayout
              .cloneNode(true);
        }
        newPageLayout = (OdfStylePageLayout) mDocument.getStylesDom()
            .newOdfElement(StylePageLayoutElement.class);
        String newname = newUniquePageLayoutName();
        newPageLayout.setStyleNameAttribute(newname);
        styles.appendChild(newPageLayout);
        mOdfElement.setAttributeNS(OdfDocumentNamespace.STYLE.getUri(),
            "style:page-layout-name", newname);
        newPageLayout.addStyleUser(mOdfElement);
        return newPageLayout;
      }
View Full Code Here

      return pageLayout;
    }

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

    NodeList nodeList = footerEle.getElementsByTagName(TextPElement.ELEMENT_NAME.getQName());
    for (int i = 0; i < nodeList.getLength(); i++) {
      TextPElement textEle = (TextPElement) nodeList.item(i);
      String stylename = textEle.getStyleName();
      OdfFileDom dom = (OdfFileDom) footerEle.getOwnerDocument();
      OdfOfficeAutomaticStyles styles = null;
      if (dom instanceof OdfContentDom) {
        styles = ((OdfContentDom) dom).getAutomaticStyles();
      } else if (dom instanceof OdfStylesDom) {
        styles = ((OdfStylesDom) dom).getAutomaticStyles();
      }
     
      OdfStyle newStyle = styles.newStyle(OdfStyleFamily.Paragraph);
      OdfStyle style = styles.getStyle(stylename, OdfStyleFamily.Paragraph);
      if (style != null) {
        String styleName = newStyle.getStyleNameAttribute();
        styles.removeChild(newStyle);
        newStyle = (OdfStyle) style.cloneNode(true);
        newStyle.setStyleNameAttribute(styleName);
        styles.appendChild(newStyle);
      }
      if (isVisible) {
        if (newStyle.hasProperty(StyleTextPropertiesElement.Display)) {
          newStyle.removeProperty(StyleTextPropertiesElement.Display);
        }
View Full Code Here

  private void updateTableToNone(Table table) {
    OdfFileDom dom = (OdfFileDom) getTableContainerElement().getOwnerDocument();
    TableTableElement tableEle = table.getOdfElement();
    String stylename = tableEle.getStyleName();
    OdfOfficeAutomaticStyles styles = null;
    if (dom instanceof OdfContentDom) {
      styles = ((OdfContentDom) dom).getAutomaticStyles();
    } else if (dom instanceof OdfStylesDom) {
      styles = ((OdfStylesDom) dom).getAutomaticStyles();
    }
    OdfStyle tableStyle = styles.getStyle(stylename, OdfStyleFamily.Table);
    tableStyle.setProperty(StyleTablePropertiesElement.Shadow, "none");
    NodeList cells = tableEle.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table-cell");
    if (cells != null && cells.getLength() > 0) {
      OdfStyle cellStyleWithoutBorder = styles.newStyle(OdfStyleFamily.TableCell);
      cellStyleWithoutBorder.setProperty(StyleTableCellPropertiesElement.Border, "none");
      cellStyleWithoutBorder.removeProperty(StyleTableCellPropertiesElement.Padding);
      String cellStyleName = cellStyleWithoutBorder.getStyleNameAttribute();
      for (int i = 0; i < cells.getLength(); i++) {
        TableTableCellElement cell = (TableTableCellElement) cells.item(i);
View Full Code Here

    TextSectionElement newSectionEle = null;
    try {
      Document doc = (Document) ((OdfFileDom) footerEle
          .getOwnerDocument()).getDocument();
      OdfContentDom contentDocument = doc.getContentDom();
      OdfOfficeAutomaticStyles styles = contentDocument
          .getAutomaticStyles();
      OdfStyle style = styles.newStyle(OdfStyleFamily.Section);
      StyleSectionPropertiesElement sProperties = style
          .newStyleSectionPropertiesElement();
      sProperties.setTextDontBalanceTextColumnsAttribute(false);
      sProperties.setStyleEditableAttribute(false);
      StyleColumnsElement columnEle = sProperties
View Full Code Here

    if (styleName == null || (styleName.equals(""))) {
      createNew = true;
      // get from default style element
      defaultStyleElement = mDocument.getDocumentStyles().getDefaultStyle(mOdfElement.getStyleFamily());
    } else {
      OdfOfficeAutomaticStyles styles = mOdfElement.getAutomaticStyles();
      styleElement = styles.getStyle(styleName, mOdfElement.getStyleFamily());

      // If not default cell style definition,
      // Try to find if the style is defined in document styles
      if (styleElement == null && defaultStyleElement == null) {
        styleElement = mDocument.getDocumentStyles().getStyle(styleName, mOdfElement.getStyleFamily());
View Full Code Here

    return datadisplayStylename;
  }

  private String getUniqueNumberStyleName() {
    String unique_name;
    OdfOfficeAutomaticStyles styles = mCellElement.getAutomaticStyles();
    do {
      unique_name = String.format("n%06x", (int) (Math.random() * 0xffffff));
    } while (styles.getNumberStyle(unique_name) != null);
    return unique_name;
  }
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.