Examples of OdfFileDom


Examples of org.odftoolkit.odfdom.pkg.OdfFileDom

   */
  @Test
  public void testXPathIsMissingXLinkButItWillPassBecauseItTheSecondTestInThisUnitTest() throws Exception {
    try {
      OdfPresentationDocument odpWithSlides = OdfPresentationDocument.loadDocument(ResourceUtilities.getAbsolutePath(SOURCE_FILE_1));
      OdfFileDom contentDom = odpWithSlides.getContentDom();
      XPath xpath = contentDom.getXPath();

      Node node = odpWithSlides.getContentDom().getRootElement();
      NodeList linkNodes = (NodeList) xpath.evaluate(".//*[@xlink:href]", node, XPathConstants.NODESET);
      Assert.assertNotNull(linkNodes);
      Assert.assertEquals("urn:oasis:names:tc:opendocument:xmlns:office:1.0", xpath.getNamespaceContext().getNamespaceURI("office"));
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom

    // trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

    LOG.log(Level.INFO, "---------- {0}.xml transformed and compared ---------", odfFileNamePrefix);
    // The XML file (e.g. content.xml) is transformed by XSLT into the similar/identical XML file
    ByteArrayOutputStream xmlBytes = new ByteArrayOutputStream();
    OdfFileDom fileDom = null;
    if (odfFileNamePrefix.equals("content")) {
      fileDom = odfdoc.getContentDom();
    } else {
      fileDom = odfdoc.getStylesDom();
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom

      Assert.fail(e.getMessage());
    }
  }

  private void testStyle(OdfStyle testStyle) throws Exception {
    OdfFileDom fileDom = (OdfFileDom) testStyle.getOwnerDocument();
    OdfOfficeAutomaticStyles autoStyles = null;
    if (testStyle.getStyleParentStyleNameAttribute() != null) {
      if (fileDom instanceof OdfContentDom) {
        autoStyles = ((OdfContentDom) fileDom).getAutomaticStyles();
      } else if (fileDom instanceof OdfStylesDom) {
        autoStyles = ((OdfStylesDom) fileDom).getAutomaticStyles();
      }
      OdfStyle parentStyle = autoStyles.getStyle(testStyle.getStyleParentStyleNameAttribute(), testStyle.getFamily());
      if (parentStyle == null) {
        parentStyle = ((OdfDocument) fileDom.getDocument()).getDocumentStyles().getStyle(testStyle.getStyleParentStyleNameAttribute(), testStyle.getFamily());
      }

      Assert.assertNotNull(parentStyle);
    }
    if (testStyle.hasOdfAttribute(OdfName.newName(OdfDocumentNamespace.STYLE, "list-style-name"))) {
      if (testStyle.getStyleListStyleNameAttribute() != null) {
        OdfTextListStyle listStyle = autoStyles.getListStyle(testStyle.getStyleListStyleNameAttribute());
        if (listStyle == null) {
          listStyle = ((OdfDocument) fileDom.getDocument()).getDocumentStyles().getListStyle(testStyle.getStyleListStyleNameAttribute());
        }

        Assert.assertNotNull(listStyle);
      }
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom

      // loads the ODF document from the path
      OdfDocument odfDoc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath("TestEmpty_OdfTextDocument.odt"));

      // get the ODF content as DOM tree representation
      OdfFileDom odfContent = odfDoc.getContentDom();

      //// W3C XPath initialization ''(JDK5 functionality)''  - XPath is the path within the XML file
      //// (Find XPath examples here: http://www.w3.org/TR/xpath#path-abbrev)
      XPath xpath2 = odfContent.getXPath();

      // receiving the first paragraph "//text:p[1]" ''(JDK5 functionality)''
      TextPElement para = (TextPElement) xpath2.evaluate("//text:p[1]", odfContent, XPathConstants.NODE);

      // adding an image - expecting the user to know that
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom

    try {
      OdfDocument odfDocument = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(SOURCE));
      Assert.assertTrue(odfDocument.getPackage().contains("content.xml"));
      String baseURI = odfDocument.getBaseURI();
      Assert.assertTrue(ResourceUtilities.getURI(SOURCE).toString().compareToIgnoreCase(baseURI) == 0);
      OdfFileDom odfContent = odfDocument.getContentDom();
      String odf12 = OfficeVersionAttribute.Value._1_2.toString();
      OfficeDocumentContentElement content = (OfficeDocumentContentElement) odfContent.getDocumentElement();
      String version = content.getOfficeVersionAttribute();
      Assert.assertFalse(version.equals(odf12));

      NodeList lst = odfContent.getElementsByTagNameNS(OdfDocumentNamespace.TEXT.getUri(), "p");
      Node node = lst.item(0);
      String oldText = "Changed!!!";
      node.setTextContent(oldText);

      odfDocument.save(ResourceUtilities.newTestOutputFile(TARGET));
      odfDocument = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(TARGET));

      odfContent = odfDocument.getContentDom();
      // ToDo: Will be used for issue 60: Load & Save of previous ODF versions (ie. ODF 1.0, ODF 1.1)
      //Assert.assertTrue(odfContent.getRootElement().getOfficeVersionAttribute().equals(odf12));
      lst = odfContent.getElementsByTagNameNS(OdfDocumentNamespace.TEXT.getUri(), "p");
      node = lst.item(0);
      String newText = node.getTextContent();
      Assert.assertTrue(newText.equals(oldText));

      node = lst.item(1);
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom

  }

  public boolean removeList(List list) {
    OdfElement containerElement = getListContainerElement();
    Node child = containerElement.getFirstChild();
    OdfFileDom ownerDocument = (OdfFileDom) containerElement.getOwnerDocument();
    Document doc = (Document) ownerDocument.getDocument();
    while (child != null) {
      if (child instanceof TextListElement) {
        TextListElement listElement1 = (TextListElement) child;
        String id1 = listElement1.getXmlIdAttribute();
        TextListElement listElement2 = list.getOdfElement();
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom

   */
  public void setNoteText(String note) {
    splitRepeatedCells();
    OfficeAnnotationElement annotation = OdfElement.findFirstChildNode(OfficeAnnotationElement.class, mCellElement);
    if (annotation == null) {
      OdfFileDom dom = (OdfFileDom) mCellElement.getOwnerDocument();
      annotation = (OfficeAnnotationElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(
          OdfDocumentNamespace.OFFICE, "annotation"));
    }
    TextPElement noteElement = OdfElement.findFirstChildNode(TextPElement.class, annotation);
    if (noteElement == null) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom

      }

      if (mOwnerTable.mIsSpreadsheet) {
        newImage = Image.newImage(this, imageUri);
      } else {
        OdfFileDom dom = (OdfFileDom) mCellElement.getOwnerDocument();
        TextPElement pElement = dom.newOdfElement(TextPElement.class);
        mCellElement.appendChild(pElement);
        newImage = Image.newImage(Paragraph.getInstanceof(pElement), imageUri);
      }
      if (imageUri != null) {
        FrameRectangle rect = newImage.getRectangle();
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom

        DrawFrameElement drawFrame = OdfElement.findFirstChildNode(DrawFrameElement.class, pElement);
        if (drawFrame != null) {
          DrawImageElement imageElement = OdfElement.findFirstChildNode(DrawImageElement.class, drawFrame);
          if (imageElement != null) {
            String packagePath = imageElement.getXlinkHrefAttribute();
            OdfFileDom dom = (OdfFileDom) mCellElement.getOwnerDocument();
            OdfPackage mOdfPackage = dom.getDocument().getPackage();
            InputStream is = mOdfPackage.getInputStream(packagePath);
            BufferedImage image = ImageIO.read(is);
            return image;
          }
        }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom

   */
  public void applyHeading(boolean isHeading, int level) {
    if (isHeading) {
      if (!isHeading()) {
        // create new heading element, clone children nodes.
        OdfFileDom ownerDocument = (OdfFileDom) getOdfElement().getOwnerDocument();
        mHeadingElement = ownerDocument.newOdfElement(TextHElement.class);
        Node firstChild = mParagraphElement.getFirstChild();
        while (firstChild != null) {
          // mHeadingElement.appendChild(firstChild.cloneNode(true));
          // firstChild = firstChild.getNextSibling();
          Node thisChild = firstChild;
          firstChild = firstChild.getNextSibling();
          mParagraphElement.removeChild(thisChild);
          mHeadingElement.appendChild(thisChild);
        }
        // update style
        mHeadingElement.setStyleName(mParagraphElement.getStyleName());
        // unregister component
        Component.unregisterComponent(mParagraphElement);
        // replace paragraph with heading
        OdfElement parentOdfElement = (OdfElement) mParagraphElement.getParentNode();
        parentOdfElement.replaceChild(mHeadingElement, mParagraphElement);
        mParagraphElement = null;
        // re-register component.
        Component.registerComponent(this, mHeadingElement);
      }
      // update outline level.
      mHeadingElement.setTextOutlineLevelAttribute(level);
    } else {
      if (isHeading()) {
        // need create new paragraph element and clone content.
        OdfFileDom ownerDocument = (OdfFileDom) getOdfElement().getOwnerDocument();
        mParagraphElement = ownerDocument.newOdfElement(TextPElement.class);
        Node firstChild = mHeadingElement.getFirstChild();
        while (firstChild != null) {
          Node thisChild = firstChild;
          firstChild = firstChild.getNextSibling();
          mHeadingElement.removeChild(thisChild);
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.