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

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


      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);
      Assert.assertEquals(documentStyle.getStyleNameAttribute(), "myStyle");
      Assert.assertEquals(documentStyle.getFamilyName(), "paragraph");

      documentStyle.setProperty(StyleTextPropertiesElement.FontWeight, "bold");
      documentStyle.setProperty(StyleParagraphPropertiesElement.BackgroundColor, "#14EA5D");

      // SAVE / LOAD
      docWithEmbeddedObjects.save(TEST_FILE_ACCESS_EMBEDDED);

      OdfDocument doc2 = OdfDocument.loadDocument(TEST_FILE_ACCESS_EMBEDDED);
      OdfDocument embDoc2 = doc2.loadSubDocument("Object 1/");
      embDoc2.getStylesDom();
      OdfStyle documentStyle2 = embDoc2.getDocumentStyles().getStyle("myStyle", OdfStyleFamily.Paragraph);
      String prop2 = documentStyle2.getProperty(StyleTextPropertiesElement.FontWeight);
      Assert.assertEquals(prop2, "bold");

      TextSpanElement spanTest = (TextSpanElement) xpath.evaluate("//text:p[1]/text:span[1]", contentDom, XPathConstants.NODE);
      Assert.assertEquals(spanTest.getTextContent(), TEST_SPAN_TEXT);
View Full Code Here


    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(
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

        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

    if (dom instanceof OdfContentDom) {
      styles = ((OdfContentDom) dom).getAutomaticStyles();
    } else if (dom instanceof OdfStylesDom) {
      styles = ((OdfStylesDom) dom).getAutomaticStyles();
    }
    OdfStyle textStyle = styles.newStyle(OdfStyleFamily.Text);
    StyleTextPropertiesElement styleTextPropertiesElement = textStyle.newStyleTextPropertiesElement(null);
    styleTextPropertiesElement.setStyleFontNameAttribute("Tahoma");
    styleTextPropertiesElement.setFoFontSizeAttribute("10pt");
    styleTextPropertiesElement.setStyleFontNameAsianAttribute("Lucida Sans Unicode");
    styleTextPropertiesElement.setStyleFontSizeAsianAttribute("12pt");
    noteSpanElement.setStyleName(textStyle.getStyleNameAttribute());
    // set comment content
    noteSpanElement.setTextContent(content);
  }
View Full Code Here

      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);
      Assert.assertEquals(documentStyle.getStyleNameAttribute(), "myStyle");
      Assert.assertEquals(documentStyle.getFamilyName(), "paragraph");

      documentStyle.setProperty(StyleTextPropertiesElement.FontWeight, "bold");
      documentStyle.setProperty(StyleParagraphPropertiesElement.BackgroundColor, "#14EA5D");

      // SAVE / LOAD
      docWithEmbeddedObjects.save(TEST_FILE_ACCESS_EMBEDDED);

      Document doc2 = Document.loadDocument(TEST_FILE_ACCESS_EMBEDDED);
      Document embDoc2 = doc2.getEmbeddedDocument("Object 1/");
      embDoc2.getStylesDom();
      OdfStyle documentStyle2 = embDoc2.getDocumentStyles().getStyle("myStyle", OdfStyleFamily.Paragraph);
      String prop2 = documentStyle2.getProperty(StyleTextPropertiesElement.FontWeight);
      Assert.assertEquals(prop2, "bold");

      TextSpanElement spanTest = (TextSpanElement) xpath.evaluate("//text:p[1]/text:span[1]", contentDom,
          XPathConstants.NODE);
      Assert.assertEquals(spanTest.getTextContent(), TEST_SPAN_TEXT);
View Full Code Here

    if (dom instanceof OdfContentDom) {
      styles = ((OdfContentDom) dom).getAutomaticStyles();
    } else if (dom instanceof OdfStylesDom) {
      styles = ((OdfStylesDom) dom).getAutomaticStyles();
    }
    OdfStyle textStyle = styles.newStyle(OdfStyleFamily.Text);
    StyleTextPropertiesElement styleTextPropertiesElement = textStyle.newStyleTextPropertiesElement(null);
    styleTextPropertiesElement.setStyleFontNameAttribute("Tahoma");
    styleTextPropertiesElement.setFoFontSizeAttribute("10pt");
    styleTextPropertiesElement.setStyleFontNameAsianAttribute("Lucida Sans Unicode");
    styleTextPropertiesElement.setStyleFontSizeAsianAttribute("12pt");
    noteSpanElement.setStyleName(textStyle.getStyleNameAttribute());
    // set comment content
    noteSpanElement.setTextContent(content);
  }
View Full Code Here

        defaultStyles.put(defStyle.getFamilyName(), defStyle);
      }

      NodeList styleList = mTextDocument.getDocumentStyles().getElementsByTagName("style:style");
      for (int i = 0; i < styleList.getLength(); i++) {
        OdfStyle sStyle = (OdfStyle) styleList.item(i);
        //get default properties and style properties
        Map<OdfStyleProperty, String> map = sStyle.getStylePropertiesDeep();
        //check if properties include all search properties and value equal
        Iterator<OdfStyleProperty> pIter = mProps.keySet().iterator();
        boolean isStyle = false;
        while (pIter.hasNext()) {
          isStyle = false;
          OdfStyleProperty p = pIter.next();
          if (map.containsKey(p)) {
            if (map.get(p).equals(mProps.get(p))) {
              isStyle = true;
            } else {
              break;
            }
          } else {
            break;
          }
        }
        //put all match style names
        if (isStyle) {
          sname = sStyle.getStyleNameAttribute();
          //if(sname.contains("default"))sname="defaultstyle";
          styleNames.add(sname);
        }
      }
      //get all automatic styles
      Iterator<OdfStyle> cStyles = mTextDocument.getContentDom().getAutomaticStyles().getAllStyles().iterator();
      while (cStyles.hasNext()) {
        OdfStyle cStyle = cStyles.next();
        //get default properties and style properties
        Map<OdfStyleProperty, String> map = cStyle.getStylePropertiesDeep();

        if (cStyle.getParentStyle() == null) {
          if (cStyle.getFamilyName().equals("text")) {
            if (defaultStyles.containsKey("text")) {
              getTextDefaultProperties("text", defaultStyles, map);
            } else {
              getTextDefaultProperties("paragraph", defaultStyles, map);
            }
          }
        }

        //check if the search properties is in properties
        Iterator<OdfStyleProperty> pIter = mProps.keySet().iterator();
        boolean isStyle = false;
        while (pIter.hasNext()) {
          isStyle = false;
          OdfStyleProperty p = pIter.next();
          if (map.containsKey(p)) {
            if (map.get(p).equals(mProps.get(p))) {
              isStyle = true;
            } else {
              break;
            }
          } else {
            break;
          }
        }
        //put all match style names
        if (isStyle) {
          styleNames.add(cStyle.getStyleNameAttribute());
        }
      }

    } catch (Exception e1) {
      Logger.getLogger(TextStyleNavigation.class.getName()).log(Level.SEVERE, e1.getMessage(), e1);
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.