Examples of OdfOfficeAutomaticStyles


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

      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

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

      OdfDocument odfdoc = OdfDocument.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

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

    }
  }

  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 = ((OdfDocument) 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 = ((OdfDocument) fileDom.getDocument()).getDocumentStyles().getListStyle(testStyle.getStyleListStyleNameAttribute());
        }

        Assert.assertNotNull(listStyle);
View Full Code Here

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

      // Add frame and image element
      TextPElement paraLast = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom, XPathConstants.NODE);
      addImageToDocument(contentDom, paraLast);

      // Access/Update automatic styles
      OdfOfficeAutomaticStyles autoStyles = embDoc.getContentDom().getAutomaticStyles();
      OdfStyle autoStyle = autoStyles.getStyle("P1", OdfStyleFamily.Paragraph);
      Assert.assertEquals(autoStyle.getStyleNameAttribute(), "P1");
      Assert.assertEquals(autoStyle.getFamilyName(), "paragraph");

      // Access/Update styles.xml
      OdfStyle documentStyle = embDoc.getDocumentStyles().getStyle("myStyle", OdfStyleFamily.Paragraph);
View Full Code Here

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

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

    try {
      outputDocument = OdfSpreadsheetDocument.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");

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

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

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

    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

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

    return unique_name;
  }

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

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

    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

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

  // } 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

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

    NodeList nodeList = headerEle.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) headerEle.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
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.