Package org.odftoolkit.odfdom.dom.element.draw

Examples of org.odftoolkit.odfdom.dom.element.draw.DrawImageElement


      }
      containerElement.removeChild(nextElement.getOdfElement());
    }

    private Image findNext(Image thisImage) {
      DrawImageElement nextFrame = null;
      if (thisImage == null) {
        nextFrame = OdfElement.findFirstChildNode(DrawImageElement.class, containerElement);
      } else {
        nextFrame = OdfElement.findNextChildNode(DrawImageElement.class, thisImage.getOdfElement());
      }
View Full Code Here


          .loadDocument(ResourceUtilities.getTestResourceAsStream("NewSection.odt"));
      theSec = newDoc.getSectionByName("ImageSection");
      Section newSec = newDoc.getSectionByName(newName);

      XPath xpath = newDoc.getContentDom().getXPath();
      DrawImageElement oldImage = (DrawImageElement) xpath.evaluate(".//draw:image", theSec.getOdfElement(),
          XPathConstants.NODE);
      DrawImageElement newImage = (DrawImageElement) xpath.evaluate(".//draw:image", newSec.getOdfElement(),
          XPathConstants.NODE);
      Assert.assertEquals(oldImage.getXlinkHrefAttribute(), newImage.getXlinkHrefAttribute());

      OdfPackage packageDocument = newDoc.getPackage();
      String imagePathPrefix = "Pictures/";
      int count = 0;
      Iterator<String> filePaths = packageDocument.getFilePaths().iterator();
      while (filePaths.hasNext()) {
        String path = filePaths.next();
        if (path.startsWith(imagePathPrefix) && path.length() > imagePathPrefix.length())
          count++;
        if (count > 2)
          break;
      }
      Assert.assertEquals(1, count);
      // ---------resource copied------
      doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("Sections.odt"));
      theSec = doc.getSectionByName("ImageSection");
      newName = doc.appendSection(theSec, true).getName();
      doc.save(ResourceUtilities.newTestOutputFile("NewSection1.odt"));

      newDoc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("NewSection1.odt"));
      theSec = newDoc.getSectionByName("ImageSection");
      newSec = newDoc.getSectionByName(newName);

      xpath = newDoc.getContentDom().getXPath();
      oldImage = (DrawImageElement) xpath.evaluate(".//draw:image", theSec.getOdfElement(), XPathConstants.NODE);
      newImage = (DrawImageElement) xpath.evaluate(".//draw:image", newSec.getOdfElement(), XPathConstants.NODE);
      if (oldImage.getXlinkHrefAttribute().equals(newImage.getXlinkHrefAttribute()))
        Assert.fail();

      packageDocument = newDoc.getPackage();
      count = 0;
      filePaths = packageDocument.getFilePaths().iterator();
View Full Code Here

    try {
      OdfElement parent = container.getFrameContainerElement();
      OdfFileDom ownerDom = (OdfFileDom) parent.getOwnerDocument();
      DrawFrameElement fElement = ownerDom.newOdfElement(DrawFrameElement.class);
      parent.appendChild(fElement);
      DrawImageElement imageElement = fElement.newDrawImageElement();
      // set uri and copy resource
      String packagePath = insertImageResourceIntoPackage((OdfSchemaDocument) ownerDom.getDocument(), uri);
      packagePath = packagePath.replaceFirst(ownerDom.getDocument().getDocumentPath(), "");
      URI newURI = configureInsertedImage((OdfSchemaDocument) ownerDom.getDocument(), imageElement, packagePath,
          false);
View Full Code Here

    Image mImage;

    try {
      DrawFrameElement fElement = (DrawFrameElement) frame.getDrawFrameElement();
      OdfFileDom ownerDom = (OdfFileDom) fElement.getOwnerDocument();
      DrawImageElement imageElement = fElement.newDrawImageElement();
      // set uri and copy resource
      String packagePath = insertImageResourceIntoPackage((OdfSchemaDocument) ownerDom.getDocument(), uri);
      packagePath = packagePath.replaceFirst(ownerDom.getDocument().getDocumentPath(), "");
      URI newURI = configureInsertedImage((OdfSchemaDocument) ownerDom.getDocument(), imageElement, packagePath,
          true);
View Full Code Here

    fcell.removeContent();
    Assert.assertEquals(0, fcell.mCellElement.getChildNodes().getLength());

    fcell.setDisplayText("hello");
    DrawFrameElement drawEle = new DrawFrameElement(odsdoc.getContentDom());
    DrawImageElement imageEle = drawEle.newDrawImageElement();
    fcell.mCellElement.appendChild(drawEle);

    Assert.assertEquals(2, fcell.mCellElement.getChildNodes().getLength());

    fcell.removeTextContent();
View Full Code Here

    try {
      TextPElement pElement = OdfElement.findFirstChildNode(TextPElement.class, mCellElement);
      if (pElement != null) {
        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

    try {
      TextPElement pElement = OdfElement.findFirstChildNode(TextPElement.class, mCellElement);
      if (pElement != null) {
        DrawFrameElement drawFrame = OdfElement.findFirstChildNode(DrawFrameElement.class, pElement);
        if (drawFrame != null) {
          DrawImageElement imageElement = OdfElement.findFirstChildNode(DrawImageElement.class, drawFrame);
          return Image.getInstanceof(imageElement);
        }
      } else {
        DrawFrameElement drawFrame = OdfElement.findFirstChildNode(DrawFrameElement.class, mCellElement);
        if (drawFrame != null) {
          DrawImageElement imageElement = OdfElement.findFirstChildNode(DrawImageElement.class, drawFrame);
          return Image.getInstanceof(imageElement);
        }
      }
    } catch (Exception ex) {
      Logger.getLogger(Cell.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

      XPath xpath = contentDom.getXPath();
      DrawFrameElement frame = contentDom.newOdfElement(DrawFrameElement.class);
      frame.setSvgHeightAttribute("3in");
      frame.setSvgWidthAttribute("7in");
      DrawImageElement image = contentDom.newOdfElement(DrawImageElement.class);
      image.setXlinkHrefAttribute("Pictures/myHoliday.jpg");
      frame.appendChild(image);

      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      para.appendChild(frame);
      doc.save(TEST_FILE_FOLDER + New_File);
      doc.close();

      //Test if the image has been inserted
      doc = OdfDocument.loadDocument(TEST_FILE_FOLDER + New_File);
      contentDom = doc.getContentDom();
      DrawFrameElement frameobj = (DrawFrameElement) xpath.evaluate("//text:p[1]/draw:frame", contentDom, XPathConstants.NODE);
      Assert.assertEquals("3in", frameobj.getSvgHeightAttribute());
      Assert.assertEquals("7in", frameobj.getSvgWidthAttribute());
      DrawImageElement imageobj = (DrawImageElement) frameobj.getFirstChild();
      Assert.assertEquals("Pictures/myHoliday.jpg", imageobj.getXlinkHrefAttribute());
    } catch (Exception e) {
      Logger.getLogger(NoTempFileTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
    }
  }
View Full Code Here

    try {
      TextPElement pElement = OdfElement.findFirstChildNode(TextPElement.class, mCellElement);
      if (pElement != null) {
        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

    try {
      TextPElement pElement = OdfElement.findFirstChildNode(TextPElement.class, mCellElement);
      if (pElement != null) {
        DrawFrameElement drawFrame = OdfElement.findFirstChildNode(DrawFrameElement.class, pElement);
        if (drawFrame != null) {
          DrawImageElement imageElement = OdfElement.findFirstChildNode(DrawImageElement.class, drawFrame);
          return Image.getInstanceof(imageElement);
        }
      } else {
        DrawFrameElement drawFrame = OdfElement.findFirstChildNode(DrawFrameElement.class, mCellElement);
        if (drawFrame != null) {
          DrawImageElement imageElement = OdfElement.findFirstChildNode(DrawImageElement.class, drawFrame);
          return Image.getInstanceof(imageElement);
        }
      }
    } catch (Exception ex) {
      Logger.getLogger(Cell.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.dom.element.draw.DrawImageElement

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.