Package org.odftoolkit.odfdom.dom

Examples of org.odftoolkit.odfdom.dom.OdfContentDom


  @Test
  public void testContentNode() {
    try {
      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");
View Full Code Here


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

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

  }

  private void copyForeignStyleRef(OdfElement sourceCloneEle,
      OdfPresentationDocument doc) {
    try {
      OdfContentDom contentDom = getContentDom();
      XPath xpath = contentDom.getXPath();
      //1. collect all the referred style element which has "style:name" attribute
      //1.1. style:name of content.xml
      String styleQName = "style:name";
      NodeList srcStyleDefNodeList = (NodeList) xpath.evaluate("//*[@" + styleQName + "]", contentDom, XPathConstants.NODESET);
      HashMap<OdfElement, List<OdfElement>> srcContentStyleCloneEleList = new HashMap<OdfElement, List<OdfElement>>();
View Full Code Here

    // before creating a new dom, make sure that there no DOM opened for this file already
    Document existingDom = packageDocument.getPackage().getCachedDom(packagePath);
    if (existingDom == null) {
      // ToDo: bug 264 - register OdfFileDom to this class
      if (packagePath.equals("content.xml") || packagePath.endsWith("/content.xml")) {
        newFileDom = new OdfContentDom((OdfSchemaDocument) packageDocument, packagePath);
      } else if (packagePath.equals("styles.xml") || packagePath.endsWith("/styles.xml")) {
        newFileDom = new OdfStylesDom((OdfSchemaDocument) packageDocument, packagePath);
      } else if (packagePath.equals("meta.xml") || packagePath.endsWith("/meta.xml")) {
        newFileDom = new OdfMetaDom((OdfSchemaDocument) packageDocument, packagePath);
      } else if (packagePath.equals("settings.xml") || packagePath.endsWith("/settings.xml")) {
View Full Code Here

   *                 If the imageURI is relative first the user.dir is taken to make it absolute.
   * @return         Returns the internal package path of the image, which was created based on the given URI.
   * */
  public String newImage(URI imageUri) {
    try {
      OdfContentDom contentDom = this.getContentDom();
      OdfDrawFrame drawFrame = contentDom.newOdfElement(OdfDrawFrame.class);
      XPath xpath = contentDom.getXPath();
      if (this instanceof OdfSpreadsheetDocument) {
        TableTableCellElement lastCell = (TableTableCellElement) xpath.evaluate("//table:table-cell[last()]", contentDom, XPathConstants.NODE);
        lastCell.appendChild(drawFrame);
        drawFrame.removeAttribute("text:anchor-type");

View Full Code Here

        LOG.log(Level.INFO, "Embedded file of {0} internal package path: {1} mediaType: {2}", new Object[]{TEST_FILE_EMBEDDED, embDoc.getDocumentPath(), embDoc.getMediaTypeString()});
        pathToEmbeddedObject = embDoc.getDocumentPath();
      }

      OdfDocument embDoc = docWithEmbeddedObjects.loadSubDocument(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);
View Full Code Here

      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

      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

      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

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.