Package org.odftoolkit.odfdom.dom

Examples of org.odftoolkit.odfdom.dom.OdfContentDom


  }

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


    // We have the following 1 triple in cache:
    // (http://dbpedia.org/page/J._R._R._Tolkien
    // http://www.w3.org/2006/vcard/ns#fn 'John Ronald Reuel Tolkien')
    TestCase.assertEquals(1, m1.size());

    OdfContentDom contentDom = odt.getContentDom();
    XPath xpath = contentDom.getXPath();
    TextMetaElement tm = (TextMetaElement) xpath.evaluate(
        "//text:p/text:meta[last()]", contentDom, XPathConstants.NODE);

    tm.setXhtmlAboutAttribute("http://dbpedia.org/page/J._K._Rowling");
    m1 = odt.getInContentMetadataFromCache();
    PrintUtil.printOut(m1.listStatements());
    TestCase.assertEquals("http://dbpedia.org/page/J._K._Rowling", m1
        .listStatements().nextStatement().getSubject().getURI());

    tm.setTextContent("Joanne Kathleen Rowling");
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals("Joanne Kathleen Rowling", m1.listStatements()
        .nextStatement().getObject().toString());

    tm.setXhtmlPropertyAttribute("dc:name");
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals("http://purl.org/dc/elements/1.1/name", m1
        .listStatements().nextStatement().getPredicate().getURI());

    Node parent = tm.getParentNode();
    parent.removeChild(tm);
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(0, m1.size());
    parent.appendChild(tm);
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(1, m1.size());
    parent.removeChild(tm);

    TextPElement pEle = contentDom.newOdfElement(TextPElement.class);
    parent.appendChild(pEle);
    pEle.setXhtmlAboutAttribute("[dbpedia:J._K._Rowling]");
    pEle.setXhtmlPropertyAttribute("dbpprop:birthDate dbpprop:dateOfBirth");
    pEle.setXhtmlDatatypeAttribute("xsd:date");
    pEle.setXhtmlContentAttribute("1965-07-31");
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(2, m1.size());
    StmtIterator iter = m1.listStatements();
    while (iter.hasNext()) {
      Statement stmt = iter.nextStatement();
      TestCase.assertEquals("http://dbpedia.org/page/J._K._Rowling", stmt
          .getSubject().getURI());
      TestCase.assertTrue(stmt.getObject().canAs(Literal.class));
      Literal literal = stmt.getObject().as(Literal.class);
      TestCase.assertEquals("http://www.w3.org/2001/XMLSchema#date",
          literal.getDatatypeURI());
      TestCase.assertEquals("1965-07-31", literal.getLexicalForm());
    }
    pEle.setXhtmlPropertyAttribute("dc:date");
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(1, m1.size());
    TestCase.assertEquals("http://purl.org/dc/elements/1.1/date", m1
        .listStatements().nextStatement().getPredicate().getURI());

    parent.removeChild(pEle);
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(0, m1.size());
    parent.appendChild(pEle);
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(1, m1.size());
    parent.removeChild(pEle);

    TextHElement hEle = contentDom.newOdfElement(TextHElement.class);
    parent.appendChild(hEle);
    hEle.setXhtmlAboutAttribute("[dbpedia:J._K._Rowling]");
    hEle.setXhtmlPropertyAttribute("dbpprop:children");
    hEle.setXhtmlDatatypeAttribute("xsd:integer");
    hEle.setTextContent("2");
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(1, m1.size());
    TestCase.assertEquals("http://dbpedia.org/page/J._K._Rowling", m1
        .listStatements().nextStatement().getSubject().getURI());
    TestCase.assertEquals("http://dbpedia.org/property/children", m1
        .listStatements().nextStatement().getPredicate().getURI());
    TestCase.assertTrue(m1.listStatements().nextStatement().getObject()
        .canAs(Literal.class));
    TestCase.assertEquals("2^^http://www.w3.org/2001/XMLSchema#integer", m1
        .listStatements().nextStatement().getObject().toString());
    hEle.setTextContent("3");
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals("3^^http://www.w3.org/2001/XMLSchema#integer", m1
        .listStatements().nextStatement().getObject().toString());

    parent.removeChild(hEle);
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(0, m1.size());
    parent.appendChild(hEle);
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(1, m1.size());
    parent.removeChild(hEle);

    TableTableCellElement ttce = contentDom
        .newOdfElement(TableTableCellElement.class);
    parent.appendChild(ttce);
    ttce.setXhtmlAboutAttribute("[dbpedia:J._K._Rowling]");
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(0, m1.size());
    ttce.setXhtmlPropertyAttribute("dbpprop:nationality");
    ttce.setTextContent("British");
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(1, m1.size());
    ttce.setXhtmlAboutAttribute("http://dbpedia.org/page/J._R._R._Tolkien");
    m1 = odt.getInContentMetadataFromCache();
    TestCase.assertEquals(1, m1.size());
    TestCase.assertEquals("http://dbpedia.org/page/J._R._R._Tolkien", m1
        .listStatements().nextStatement().getSubject().getURI());

    TableCoveredTableCellElement tctce = contentDom
        .newOdfElement(TableCoveredTableCellElement.class);
    parent.appendChild(tctce);
    tctce.setXhtmlAboutAttribute("[dbpedia:J._R._R._Tolkien]");
    tctce.setXhtmlPropertyAttribute("dbpprop:shortDescription");
    tctce.setXhtmlContentAttribute("British philologist and author");
View Full Code Here

    OdfTextDocument odt = (OdfTextDocument) OdfDocument
        .loadDocument(ResourceUtilities.getAbsolutePath(SIMPLE_ODT));
    Model m = odt.getBookmarkRDFMetadata();
    TestCase.assertEquals(2, m.size());

    OdfContentDom contentDom = odt.getContentDom();
    XPath xpath = contentDom.getXPath();
    TextBookmarkStartElement tm = (TextBookmarkStartElement) xpath
        .evaluate("//text:bookmark-start[last()]", contentDom,
            XPathConstants.NODE);
    BookmarkRDFMetadataExtractor extractor = BookmarkRDFMetadataExtractor
        .newBookmarkTextExtractor();
View Full Code Here

   *             if content DOM could not be initialized
   */
  public Section appendSection(String name) {
    TextSectionElement newSectionEle = null;
    try {
      OdfContentDom contentDocument = getContentDom();
      OdfOfficeAutomaticStyles styles = contentDocument
          .getAutomaticStyles();
      OdfStyle style = styles.newStyle(OdfStyleFamily.Section);
      StyleSectionPropertiesElement sProperties = style
          .newStyleSectionPropertiesElement();
      sProperties.setTextDontBalanceTextColumnsAttribute(false);
View Full Code Here

   *       the attribute name (page or column)
   */
  private void addPageOrColumnBreak(Paragraph refParagraph, String breakAttribute) {
    TextPElement pEle = null;
    try {
      OdfContentDom contentDocument = getContentDom();
      OdfOfficeAutomaticStyles styles = contentDocument.getAutomaticStyles();
      OdfStyle style = styles.newStyle(OdfStyleFamily.Paragraph);
      style.newStyleParagraphPropertiesElement().setFoBreakBeforeAttribute(breakAttribute);
      if(refParagraph == null){
        pEle = getContentRoot().newTextPElement();
      } else {
View Full Code Here

   */

  public void addPageBreak(Paragraph refParagraph, MasterPage master) {
    TextPElement pEle = null;
    try {
      OdfContentDom contentDocument = getContentDom();
      OdfOfficeAutomaticStyles styles = contentDocument
          .getAutomaticStyles();
      OdfStyle style = styles.newStyle(OdfStyleFamily.Paragraph);
      style.setStyleMasterPageNameAttribute(master.getName());

      if (refParagraph == null) {
View Full Code Here

      throw new RuntimeException("Failed to create Default TOC, The refParagraph where the TOC be inserted is null");
    }
    Node refparagraphNode = refParagraph.getOdfElement();
    Node rootNode = refparagraphNode.getParentNode();   
    try {
      OdfContentDom content = getContentDom();
      textTableOfContent = content
          .newOdfElement(TextTableOfContentElement.class);
      textTableOfContent.setTextNameAttribute("Table of Contents");
      textTableOfContent.setTextProtectedAttribute(true);
      TextTableOfContentSourceElement textTableOfContentSource = textTableOfContent
          .newTextTableOfContentSourceElement();
View Full Code Here

    // end of Additional Styles support

    Node refparagraphNode = refParagraph.getOdfElement();
    Node rootNode = refparagraphNode.getParentNode();
    try {
      OdfContentDom content = getContentDom();
      textTableOfContent = content
          .newOdfElement(TextTableOfContentElement.class);
      textTableOfContent.setTextNameAttribute("Table of Contents");
      textTableOfContent.setTextProtectedAttribute(true);

      TextTableOfContentSourceElement textTableOfContentSource = textTableOfContent
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.dom.OdfContentDom

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.