Package org.odftoolkit.odfdom.incubator.doc.style

Examples of org.odftoolkit.odfdom.incubator.doc.style.OdfStyle


    Iterable<OdfStyle> pstyles1 = target1.getStylesDom().getOfficeStyles().getStylesForFamily(OdfStyleFamily.Paragraph);
    Iterator<OdfStyle> ite = pstyles1.iterator();
    int i=0;
    System.out.println("Custom Styles in TestInsertDocumentWithStyleAfter.odt:");
    while(ite.hasNext()){
      OdfStyle odfStyle = ite.next();
      String sname = odfStyle.getAttribute("style:name");
      if(sname.startsWith("style"))
      {
        i++;
        System.out.println(sname);
      }
    } 
    Assert.assertEquals(6, i);
    target1.save(ResourceUtilities.newTestOutputFile("TestInsertDocumentWithStyleAfter.odt"));
   
   
   
    target2 = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("TestInsertDocument.odt"));
    Paragraph p2 = target2.getParagraphByIndex(2, true);
    target2.insertContentFromDocumentAfter(src2, p2, false);
   
    Iterable<OdfStyle> pstyles2 = target2.getStylesDom().getOfficeStyles().getStylesForFamily(OdfStyleFamily.Paragraph);
    Iterator<OdfStyle> ite2 = pstyles2.iterator();
    i=0;
    System.out.println("Custom Styles in TestInsertDocumentWithoutStyleAfter.odt:");
    while(ite2.hasNext()){
      OdfStyle odfStyle = ite2.next();
      String sname = odfStyle.getAttribute("style:name");
      if(sname.startsWith("style"))
      {
        i++;
        System.out.println(sname);
      }
View Full Code Here


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

    return ListType.NUMBER;
  }

  private OdfStyle getOrCreateStyleByName(OdfOfficeStyles documentStyles, OdfOfficeAutomaticStyles styles,
      String styleName, OdfStyleFamily styleFamily) {
    OdfStyle odfStyle = documentStyles.getStyle(styleName, styleFamily);
    if (odfStyle == null) {
      styles.getStyle(styleName, styleFamily);
    }
    if (odfStyle == null) {
      odfStyle = styles.newStyle(styleFamily);
      odfStyle.setStyleNameAttribute(styleName);
      odfStyle.setStyleDisplayNameAttribute(styleName);
    }
    return odfStyle;
  }
View Full Code Here

          if (node instanceof OdfStylableElement) {
            try {
              //LOG.info(indent + "-style info...");
              OdfStylableElement se = (OdfStylableElement) node;
              OdfStyleBase as = se.getAutomaticStyle();
              OdfStyle ds = se.getDocumentStyle();
              if (as != null) {
                LOG.log(INFO, "{0}-AutomaticStyle: {1}", new Object[]{indent, as});
              }
              if (ds != null) {
                LOG.log(INFO, "{0}-OdfDocumentStyle: {1}", new Object[]{indent, ds});
View Full Code Here

  @Ignore
  /** Should there be a validation in the future? */
    public void testSetValue() throws Exception {
        OdfTextDocument odt = OdfTextDocument.newTextDocument();
        OdfContentDom dom = odt.getContentDom();
        OdfStyle style1 = new OdfStyle(dom);

        // No exception should be thrown here
        style1.setStyleFamilyAttribute(OdfStyleFamily.Paragraph.toString());
        assertEquals(style1.getStyleFamilyAttribute(), OdfStyleFamily.Paragraph.toString());

        // Catch only IllegalArgumentException
        try {
            style1.setStyleFamilyAttribute("ImSoInvalid");
        } catch (IllegalArgumentException e) {
            return;   // test passed
        }
        // We need an exception from the setValue method! Otherwise we don't know that an empty attribute node has to be removed
        fail("An IllegalArgumentException has to be thrown for invalid attributes so the attribute node can be removed afterwards.");
View Full Code Here

   * @param style
   *            the cell style of the document
   */
  public void setDefaultCellStyle(OdfStyle style) {
    splitRepeatedColumns();
    OdfStyle defaultStyle = getDefaultCellStyle();
    if (defaultStyle != null) {
      defaultStyle.removeStyleUser(maColumnElement);
    }

    if (style != null) {
      style.addStyleUser(maColumnElement);
      maColumnElement.setTableDefaultCellStyleNameAttribute(style.getStyleNameAttribute());
View Full Code Here

   *
   * @return the default cell style of this column
   */
  public OdfStyle getDefaultCellStyle() {
    String styleName = maColumnElement.getTableDefaultCellStyleNameAttribute();
    OdfStyle style = maColumnElement.getAutomaticStyles().getStyle(styleName, OdfStyleFamily.TableCell);

    if (style == null) {
      style = mDocument.getDocumentStyles().getStyle(styleName, OdfStyleFamily.TableCell);
    }
    return style;
View Full Code Here

        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)) {
View Full Code Here

    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);
        cell.setStyleName(cellStyleName);
      }
    }
View Full Code Here

      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
          .newStyleColumnsElement(1);
      columnEle.setFoColumnGapAttribute("0in");

      newSectionEle = footerEle.newTextSectionElement("true", name);
      newSectionEle.setStyleName(style.getStyleNameAttribute());
      return Section.getInstance(newSectionEle);

    } catch (Exception e) {
      Logger.getLogger(TextDocument.class.getName()).log(Level.SEVERE,
          null, e);
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.incubator.doc.style.OdfStyle

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.