Examples of OdfPackage


Examples of org.odftoolkit.odfdom.pkg.OdfPackage

      ChartDocument odcDoc2 = ChartDocument.newChartDocument();
      odcDoc2.getContentDom();
      odcDoc1.save(ResourceUtilities.newTestOutputFile("TestEmpty_OdfChartDocument.odc"));

      // loads the ODF document package from the path
      OdfPackage pkg = OdfPackage.loadPackage(ResourceUtilities
          .getTestResourceAsStream("TestEmpty_OdfTextDocument.odt"));

      // loads the images from the URLs and inserts the image in the
      // package, adapting the manifest
      pkg.insert(ResourceUtilities.getURI(TEST_PIC), "Pictures/" + TEST_PIC, null);
      // Deactivated as test fail, when test machine is not online
      // (painful for offline work)
      // pkg.insert(new
      // URI("http://odftoolkit.org/attachments/wiki_images/odftoolkit/Table_fruits_diagramm.jpg"),
      // "someweiredname/tableandfruits.jpg", null);
      pkg.save(ResourceUtilities.newTestOutputFile("simple-wiki-package.odt"));

      // loads the ODF document from the path
      Document odfDoc = Document.loadDocument(ResourceUtilities
          .getTestResourceAsStream("TestEmpty_OdfTextDocument.odt"));
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

   *      or NULL if the media type is not supported by ODFDOM.
   * @throws java.lang.Exception - if the document could not be created.
   */
  protected static OdfDocument loadTemplate(Resource res, OdfMediaType odfMediaType) throws Exception {
    InputStream in = res.createInputStream();
    OdfPackage pkg = null;
    try {
      pkg = OdfPackage.loadPackage(in);
    } finally {
      in.close();
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

  }
 
  @Test
  public void testLoadDocumentWithIllegalArgument() throws Exception {
    String filepath = ResourceUtilities.getAbsolutePath("presentation.odp");
    OdfPackage odfpackage = OdfPackage.loadPackage(filepath);
    // illegal internal patch
    try {
      Document.loadDocument(odfpackage, "odt");
    } catch (Exception e) {
      Assert.assertTrue(e instanceof IllegalArgumentException);
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

    //********************************************************************
    // WIKI EXAMPLE I from http://odftoolkit.org/projects/odfdom/pages/Layers

    // loads the ODF document package from the path
    OdfPackage pkg = OdfPackage.loadPackage("/home/myDocuments/myVacation.odt");

    // loads the image from the URL and inserts the image in the package,
    // adapting the manifest
    pkg.insert(new URI("./myHoliday.png"), "Pictures/myHoliday.png", "image/png");
    pkg.save("/home/myDocuments/myVacation.odt");



    //********************************************************************
    // WIKI EXAMPLE II from http://odftoolkit.org/projects/odfdom/pages/Layers
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

        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.OdfPackage

   * @throws java.lang.Exception
   *             - if the document could not be created.
   */
  protected static Document loadTemplate(Resource res, OdfMediaType odfMediaType) throws Exception {
    InputStream in = res.createInputStream();
    OdfPackage pkg = null;
    try {
      pkg = OdfPackage.loadPackage(in);
    } finally {
      in.close();
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

    ErrorHandlerStub handler1 = new ErrorHandlerStub(expectedWarning1, expectedErrors1, expectedFatalErrors1);
    handler1.setTestFilePath("testInvalidPkg1.odt");
    try {
      // First Test / Handler2
      OdfPackage pkg2 = OdfPackage.loadPackage(new File(ResourceUtilities.getAbsolutePath(handler2.getTestFilePath())), null, handler2);
      OdfDocument doc2 = OdfDocument.loadDocument(pkg2);
      Assert.assertNotNull(doc2);

      // Second Test / Handler3
      OdfPackage pkg3 = OdfPackage.loadPackage(new File(ResourceUtilities.getAbsolutePath(handler3.getTestFilePath())), null, handler3);
      OdfDocument doc3 = OdfDocument.loadDocument(pkg3);
      Assert.assertNotNull(doc3);
      Map subDocs = doc3.loadSubDocuments();
      Assert.assertNotNull(subDocs);
      Assert.assertEquals(PRESENTATION1_DOC_COUNT, subDocs.size());

      // Third Test / Handler1
      OdfPackage pkg1 = OdfPackage.loadPackage(new File(ResourceUtilities.getAbsolutePath(handler1.getTestFilePath())), null, handler1);
      OdfDocument.loadDocument(pkg1);
      Assert.fail();
    } catch (Exception e) {
      if (!e.getMessage().contains("is invalid for the ODF XML Schema document")) {
        Assert.fail();
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

  @Test
  @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) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

  }

  @Test
  public void testRemoveImage() throws Exception {
    OdfDocument doc = OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath("image.odt"));
    final OdfPackage pkg = doc.getPackage();
    NodeAction<?> removeImages = new NodeAction<Object>() {

      @Override
      protected void apply(Node node, Object arg, int depth) {
        if (node instanceof OdfDrawImage) {
          OdfDrawImage img = (OdfDrawImage) node;
          String ref = img.getAttributeNS(
              OdfDocumentNamespace.XLINK.getUri(), "href");
          pkg.remove(ref);
          img.getParentNode().removeChild(img);
        }
      }
    };
    removeImages.performAction(doc.getContentDom().getDocumentElement(),
        null);
    pkg.save(ResourceUtilities.getTestOutput("remove-images.odt"));

  }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

    public void getInformation( String aDocFileName ) throws ODFValidatorException
    {
        try
        {
            OdfPackage aDocFile = OdfPackage.loadPackage( aDocFileName );
           
            getGenerator( aDocFile );
        }
        catch( Exception e )
        {
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.