Package org.odftoolkit.odfdom.utils

Examples of org.odftoolkit.odfdom.utils.NodeAction


  @SuppressWarnings("unchecked")
  public void testAddImageByUri() {
    try {
      OdfDocument doc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath("image.odt"));
      final OdfPackage pkg = doc.getPackage();
      NodeAction addImages = new NodeAction() {

        @Override
        protected void apply(Node node, Object arg, int depth) {
          if (node instanceof OdfDrawImage) {
            OdfDrawImage img = (OdfDrawImage) node;
            try {
              String packagePath = img.newImage(mImageUri_ODFDOM);
              if (packagePath == null || !pkg.contains(packagePath)) {
                Assert.fail("The folloing image could not be embedded:" + mImageUri_ODFDOM.toString());
              } else if (!packagePath.equals(mPackageGraphicsPath + mImageName_ODFDOM)) {
                Assert.fail("Instead of '" + mPackageGraphicsPath + mImageName_ODFDOM + "' the folloing image path was returned: '" + packagePath + "'");
              }
            } catch (Exception ex) {
              Logger.getLogger(ImageTest.class.getName()).log(
                  Level.SEVERE, null, ex);
              Assert.fail(ex.getMessage());
            }
          }
        }
      };
      addImages.performAction(doc.getContentDom().getDocumentElement(),
          null);     
      doc.save(ResourceUtilities.getTestOutput("add-images-by-uri.odt"));

    } catch (Exception e) {
      Logger.getLogger(ImageTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
View Full Code Here


    if (LOG.isLoggable(INFO)) {
      OdfDocument odfdoc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE));
      LOG.info("Parsed document.");

      OdfElement e = (OdfElement) odfdoc.getContentDom().getDocumentElement();
      NodeAction dumpStyles = new NodeAction() {

        @Override
        protected void apply(Node node, Object arg, int depth) {
          String indent = new String();
          for (int i = 0; i < depth; i++) {
            indent += "  ";
          }
          if (node.getNodeType() == Node.TEXT_NODE) {
            LOG.log(INFO, "{0}{1}", new Object[]{indent, node.getNodeName()});
            LOG.log(INFO, ": {0}\n", node.getNodeValue());
          }
          if (node instanceof OdfStylableElement) {
            try {
              //LOG.info(indent + "-style info...");
              OdfStylableElement se = (OdfStylableElement) node;
              OdfStyleBase as = se.getAutomaticStyle();
              OdfStyle ds = se.getDocumentStyle();
              if (as != null) {
                LOG.log(INFO, "{0}-AutomaticStyle: {1}", new Object[]{indent, as});
              }
              if (ds != null) {
                LOG.log(INFO, "{0}-OdfDocumentStyle: {1}", new Object[]{indent, ds});
              }
            } catch (Exception ex) {
              LOG.log(Level.SEVERE, ex.getMessage(), ex);
            }
          }
        }
      };
      dumpStyles.performAction(e, null);
    }
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  public void testAddImageByUri() {
    try {
      OdfDocument doc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath("image.odt"));
      final OdfPackage pkg = doc.getPackage();
      NodeAction addImages = new NodeAction() {

        @Override
        protected void apply(Node node, Object arg, int depth) {
          if (node instanceof OdfDrawImage) {
            OdfDrawImage img = (OdfDrawImage) node;
            try {
              String packagePath = img.newImage(mImageUri_ODFDOM);
              if (packagePath == null || !pkg.contains(packagePath)) {
                Assert.fail("The folloing image could not be embedded:" + mImageUri_ODFDOM.toString());
              } else if (!packagePath.equals(mPackageGraphicsPath + mImageName_ODFDOM)) {
                Assert.fail("Instead of '" + mPackageGraphicsPath + mImageName_ODFDOM + "' the folloing image path was returned: '" + packagePath + "'");
              }
            } catch (Exception ex) {
              Logger.getLogger(ImageTest.class.getName()).log(
                  Level.SEVERE, null, ex);
              Assert.fail(ex.getMessage());
            }
          }
        }
      };
      addImages.performAction(doc.getContentDom().getDocumentElement(),
          null);     
      doc.save(ResourceUtilities.getTestOutput("add-images-by-uri.odt"));

    } catch (Exception e) {
      Logger.getLogger(ImageTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.utils.NodeAction

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.