Examples of OdfContentDom


Examples of org.odftoolkit.odfdom.dom.OdfContentDom

      embDoc.insertDocument(OdfTextDocument.newTextDocument(), pathOfSecondInnerDoc);
      OdfFileEntry fileEntry = embDoc.getPackage().getFileEntry(embDoc.getDocumentPath() + pathOfSecondInnerDoc);
      Assert.assertNotNull(fileEntry);

      // get "Object 1/content.xml"
      OdfContentDom contentDom = embDoc.getContentDom();
      XPath xpath = contentDom.getXPath();
      TextPElement lastPara = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom, XPathConstants.NODE);
      addFrameForEmbeddedDoc(contentDom, lastPara, "Object in Object1");
      Map<String, OdfDocument> emb_embDocs = embDoc.loadSubDocuments();
      Assert.assertEquals(embDocsNumber + 1, emb_embDocs.size());
     
      OdfDocument emb_embDoc = rootDocument.loadSubDocument(embDoc.getDocumentPath()+ pathOfSecondInnerDoc);
      contentDom = emb_embDoc.getContentDom();
      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      OdfTextSpan spanElem = new OdfTextSpan(contentDom);
      spanElem.setTextContent(TEST_SPAN_TEXT);
      para.appendChild(spanElem);

      // embDoc.save(ResourceUtilities.newTestOutputFile("222debug.odt"));
      rootDocument.save(TEST_FILE_EMBEDDED_EMBEDDED);

      OdfDocument docWithdoubleEmbeddedDoc = OdfDocument.loadDocument(TEST_FILE_EMBEDDED_EMBEDDED);
      OdfDocument doubleEmbeddedDoc =docWithdoubleEmbeddedDoc.loadSubDocument("Object 1/Object in Object1");

      OdfContentDom dEDcontentDom = doubleEmbeddedDoc.getContentDom();
      TextSpanElement spanTest = (TextSpanElement) xpath.evaluate("//text:span[last()]", dEDcontentDom, XPathConstants.NODE);
      Assert.assertEquals(spanTest.getTextContent(), TEST_SPAN_TEXT);

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

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

      docWithEmbeddedObjects = OdfDocument.loadDocument(TEST_FILE_EMBEDDED);
      Map<String, OdfDocument> embDocs = docWithEmbeddedObjects.loadSubDocuments();
      for(String embDocPath : embDocs.keySet()){
        OdfDocument doc1 = embDocs.get(embDocPath);
        doc1.getDocumentPath();
        OdfContentDom contentDom1 = doc1.getContentDom();
        OdfDocument doc2 = doc1.loadSubDocument(".");
        OdfContentDom contentDom2 = doc2.getContentDom();
        Assert.assertEquals(doc2, doc1);
        Assert.assertEquals(contentDom1, contentDom2);
      }
    } catch (Exception ex) {
      Logger.getLogger(DocumentCreationTest.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

      Map<String, OdfDocument> embDocs = docWithEmbeddedObjects.loadSubDocuments(OdfDocument.OdfMediaType.GRAPHICS);
      // Graphics Doc
      for(String eDocPath : embDocs.keySet()){
        OdfDocument doc1 = embDocs.get(eDocPath);
        Assert.assertNotNull(doc1);
        OdfContentDom contentDom = doc1.getContentDom();
        XPath xpath = contentDom.getXPath();
        TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
        OdfTextSpan spanElem = new OdfTextSpan(contentDom);
        spanElem.setTextContent(TEST_SPAN_TEXT);
        para.appendChild(spanElem);
        //save the embed document to a stand alone document
        doc1.save(TEST_FILE_SAVE_EMBEDDED_OUT);
        // Load test
        OdfDocument loadedDoc = OdfDocument.loadDocument(TEST_FILE_SAVE_EMBEDDED_OUT);
        OdfContentDom contentDom2 = loadedDoc.getContentDom();
        OdfTextSpan span = (OdfTextSpan) xpath.evaluate("//text:span[last()]", contentDom2, XPathConstants.NODE);
        Assert.assertEquals(span.getTextContent(), TEST_SPAN_TEXT);
        Map<String, OdfDocument> embDocs3 = docWithEmbeddedObjects.loadSubDocuments(OdfDocument.OdfMediaType.TEXT);
        for(String eDocPath3 : embDocs3.keySet()){
          // Writer Doc
          OdfDocument doc3 = embDocs3.get(eDocPath3);
          Assert.assertNotNull(doc3);
          OdfContentDom contentDom3 = doc3.getContentDom();
          TextPElement para2 = (TextPElement) xpath.evaluate("//text:p[1]", contentDom3, XPathConstants.NODE);
          addImageToDocument(contentDom3, para2);
          TextPElement para3 = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom3, XPathConstants.NODE);
          addFrameForEmbeddedDoc(contentDom3, para3, "NewEmbedded");
          doc3.insertDocument(OdfTextDocument.newTextDocument(), "/NewEmbedded/");
          OdfDocument doc4 = doc3.loadSubDocument("NewEmbedded");
          Assert.assertNotNull(doc4);
          OdfContentDom contentDom4 = doc4.getContentDom();
          para = (TextPElement) xpath.evaluate("//text:p[1]",  contentDom4, XPathConstants.NODE);
          spanElem = new OdfTextSpan(contentDom4);
          spanElem.setTextContent(TEST_SPAN_TEXT);
          para.appendChild(spanElem);
          doc3.save(TEST_FILE_SAVE_EMBEDDED_OUT2);
View Full Code Here

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

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

            TEST_FILE_EMBEDDED, embDoc.getDocumentPath(), embDoc.getMediaTypeString() });
        pathToEmbeddedObject = embDoc.getDocumentPath();
      }

      Document embDoc = docWithEmbeddedObjects.getEmbeddedDocument(pathToEmbeddedObject);
      OdfContentDom contentDom = embDoc.getContentDom();
      XPath xpath = contentDom.getXPath();
      // Make sure the embedded document is being loaded

      // Add text element
      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      LOG.log(Level.INFO, "First para: {0}", para.getTextContent());
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

      embDoc.insertDocument(TextDocument.newTextDocument(), pathOfSecondInnerDoc);
      OdfFileEntry fileEntry = embDoc.getPackage().getFileEntry(embDoc.getDocumentPath() + pathOfSecondInnerDoc);
      Assert.assertNotNull(fileEntry);

      // get "Object 1/content.xml"
      OdfContentDom contentDom = embDoc.getContentDom();
      XPath xpath = contentDom.getXPath();
      TextPElement lastPara = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom, XPathConstants.NODE);
      addFrameForEmbeddedDoc(contentDom, lastPara, "Object in Object1");
      List<Document> emb_embDocs = embDoc.getEmbeddedDocuments();
      Assert.assertEquals(embDocsNumber + 1, emb_embDocs.size());

      Document emb_embDoc = rootDocument.getEmbeddedDocument(embDoc.getDocumentPath() + pathOfSecondInnerDoc);
      contentDom = emb_embDoc.getContentDom();
      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      OdfTextSpan spanElem = new OdfTextSpan(contentDom);
      spanElem.setTextContent(TEST_SPAN_TEXT);
      para.appendChild(spanElem);

      // embDoc.save(ResourceUtilities.newTestOutputFile("222debug.odt"));
      rootDocument.save(TEST_FILE_EMBEDDED_EMBEDDED);

      Document docWithdoubleEmbeddedDoc = Document.loadDocument(TEST_FILE_EMBEDDED_EMBEDDED);
      Document embeddedDoc = docWithdoubleEmbeddedDoc.getEmbeddedDocument("Object 1");
      Document doubleEmbeddedDoc = embeddedDoc.getEmbeddedDocument("Object in Object1");

      OdfContentDom dEDcontentDom = doubleEmbeddedDoc.getContentDom();
      TextSpanElement spanTest = (TextSpanElement) xpath.evaluate("//text:span[last()]", dEDcontentDom,
          XPathConstants.NODE);
      Assert.assertEquals(spanTest.getTextContent(), TEST_SPAN_TEXT);

    } catch (Exception ex) {
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

    Document docWithEmbeddedObjects;
    try {
      docWithEmbeddedObjects = Document.loadDocument(TEST_FILE_EMBEDDED);
      List<Document> embDocs = docWithEmbeddedObjects.getEmbeddedDocuments();
      Document doc1 = embDocs.get(0);
      OdfContentDom contentDom1 = doc1.getContentDom();
      Document doc2 = doc1.getEmbeddedDocument(".");
      OdfContentDom contentDom2 = doc2.getContentDom();
      Assert.assertEquals(doc2, doc1);
      Assert.assertEquals(contentDom1, contentDom2);
    } catch (Exception ex) {
      Logger.getLogger(DocumentCreationTest.class.getName()).log(Level.SEVERE, null, ex);
      Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

      List<Document> embDocs = docWithEmbeddedObjects.getEmbeddedDocuments(Document.OdfMediaType.GRAPHICS);
      // Graphics Doc
      Document doc1 = embDocs.get(0);
      Assert.assertNotNull(doc1);

      OdfContentDom contentDom = doc1.getContentDom();
      XPath xpath = contentDom.getXPath();
      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      OdfTextSpan spanElem = new OdfTextSpan(contentDom);
      spanElem.setTextContent(TEST_SPAN_TEXT);
      para.appendChild(spanElem);
      // save the embed document to a stand alone document
      doc1.save(TEST_FILE_SAVE_EMBEDDED_OUT);
      // Load test
      Document loadedDoc = Document.loadDocument(TEST_FILE_SAVE_EMBEDDED_OUT);
      OdfContentDom contentDom2 = loadedDoc.getContentDom();
      OdfTextSpan span = (OdfTextSpan) xpath.evaluate("//text:span[last()]", contentDom2, XPathConstants.NODE);
      Assert.assertEquals(span.getTextContent(), TEST_SPAN_TEXT);
      List<Document> embDocs3 = docWithEmbeddedObjects.getEmbeddedDocuments(Document.OdfMediaType.TEXT);

      // Writer Doc
      Document doc3 = embDocs3.get(0);
      Assert.assertNotNull(doc3);
      OdfContentDom contentDom3 = doc3.getContentDom();
      TextPElement para2 = (TextPElement) xpath.evaluate("//text:p[1]", contentDom3, XPathConstants.NODE);
      addImageToDocument(contentDom3, para2);
      TextPElement para3 = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom3, XPathConstants.NODE);
      addFrameForEmbeddedDoc(contentDom3, para3, "NewEmbedded");
      doc3.insertDocument(TextDocument.newTextDocument(), "/NewEmbedded/");
      Document doc4 = doc3.getEmbeddedDocument("NewEmbedded");
      Assert.assertNotNull(doc4);
      OdfContentDom contentDom4 = doc4.getContentDom();
      para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom4, XPathConstants.NODE);
      spanElem = new OdfTextSpan(contentDom4);
      spanElem.setTextContent(TEST_SPAN_TEXT);
      para.appendChild(spanElem);
      doc3.save(TEST_FILE_SAVE_EMBEDDED_OUT2);
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

      //2.1. get the list of the style definition
      ArrayList<OdfElement> removeStyles = new ArrayList<OdfElement>();
      OdfOfficeAutomaticStyles autoStyles = getContentDom().getAutomaticStyles();

      NodeList stylesList = autoStyles.getChildNodes();
      OdfContentDom contentDom = getContentDom();
      XPath xpath = contentDom.getXPath();

      //2.2. get the reference of each style which occurred in the current page
      for (int i = 0; i < stylesList.getLength(); i++) {
        Node item = stylesList.item(i);
        if (item instanceof OdfElement) {
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

  //delete all the xlink:href object which is contained in slideElement and does not referred by other slides
  private boolean deleteLinkRef(DrawPageElement slideEle) {
    boolean success = true;
    try {
      OdfContentDom contentDom = getContentDom();
      XPath xpath = contentDom.getXPath();
      NodeList linkNodes = (NodeList) xpath.evaluate("//*[@xlink:href]", contentDom, XPathConstants.NODESET);
      for (int i = 0; i < linkNodes.getLength(); i++) {
        OdfElement object = (OdfElement) linkNodes.item(i);
        String refObjPath = object.getAttributeNS(OdfDocumentNamespace.XLINK.getUri(), "href");
        int relation = slideEle.compareDocumentPosition(object);
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.