Examples of OdfPackage


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

      /////////////////////////////////////////
      // ODFDOM PACKAGE LAYER - WIKI EXAMPLE //
      /////////////////////////////////////////

      // 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("odfdom-wiki-package.odt"));


      /////////////////////////////////////
      // ODFDOM XML LAYER - WIKI EXAMPLE //
      /////////////////////////////////////
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

    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

        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

    {
        boolean bError = false;
        URIResolver aURIResolver = null;

        InputSource aInputSource = null;
        OdfPackage aInputPkg = null;
        String aMediaType ="text/xml";
        aLogger.setName( aInputFile.getAbsolutePath() );
        try
        {
            if( INPUT_MODE_FILE == aInputMode )
            {
                aInputSource = new InputSource( new FileInputStream(aInputFile) );
            }
            else
            {
                aInputPkg = OdfPackage.loadPackage( aInputFile );
                aLogger.setName( aInputFile.getAbsolutePath(), aPathInPackage );
                aInputSource = new InputSource( aInputPkg.getInputStream(aPathInPackage) );
                aInputSource.setSystemId( aInputFile.toURI().toString() + '/' + aPathInPackage );
                OdfFileEntry aFileEntry =  aInputPkg.getFileEntry(aPathInPackage);
                if( aFileEntry != null )
                    aMediaType = aFileEntry.getMediaTypeString();
                aURIResolver =
                    new ODFURIResolver( aInputPkg, aInputFile.toURI().toString(), aPathInPackage, aLogger );
            }
        }
        catch( Exception e )
        {
            aLogger.logFatalError(e.getMessage());
            return true;
        }
        String aInputName = aLogger.getName();

        Result aOutputResult = null;
        OdfPackage aOutputPkg = null;
        OutputStream aOutputStream = null;
        aLogger.setName( aOutputFile != null ? aOutputFile.getAbsolutePath() : "(none)" );
        boolean bMkOutputDirs = false;
        try
        {
            switch( aOutputMode )
            {
                case OUTPUT_MODE_FILE:
                    bMkOutputDirs = true;
                    aOutputResult = new StreamResult( aOutputFile );
                    break;
                case OUTPUT_MODE_STDOUT:
                    aOutputResult = new StreamResult( System.out );
                    break;
                case OUTPUT_MODE_REPLACE_INPUT_PACKAGE:
                    aOutputPkg = aInputPkg;
                    aOutputFile = aInputFile;
                    break;
                case OUTPUT_MODE_COPY_INPUT_PACKAGE:
                    bMkOutputDirs = true;
                    aOutputPkg = aInputPkg;
                    break;
                case OUTPUT_MODE_TEMPLATE_PACKAGE:
                    aOutputPkg = OdfPackage.loadPackage( aOutputFile );
                    break;
            }
            if( aOutputResult == null )
            {
                aLogger.setName( aOutputFile.getAbsolutePath(), aPathInPackage );               
                aOutputStream =
                    aOutputPkg.insertOutputStream(aPathInPackage, aMediaType );
                aOutputResult = new StreamResult( aOutputStream );
            }
        }
        catch( Exception e )
        {
            aLogger.logFatalError(e.getMessage());
            return true;
        }

        if( bMkOutputDirs )
        {
            File aOutputDir = aOutputFile.getParentFile();
            if( aOutputDir != null )
                aOutputDir.mkdirs();
        }

        String aOutputName = aLogger.getName();

        aLogger.setName( aStyleSheetFile.getAbsolutePath() );
        aLogger.logInfo( "Applying stylesheet to '" + aInputName + "'");
        bError = runXSLT( aStyleSheetFile, aParams, aInputSource, aOutputResult,
                          aTransformerFactoryClassName, aURIResolver, aLogger );
        if( bError )
            return true;
       
        aLogger.setName( aOutputFile != null ? aOutputFile.getAbsolutePath() : "(none)" );
        try
        {
            aLogger.logInfo( "Storing transformation result to '" + aOutputName + "'");
            if( !bError && aOutputStream != null )
                aOutputStream.close();
            if( !bError && aOutputPkg != null )
                aOutputPkg.save(aOutputFile);
            if( aOutputMode == OUTPUT_MODE_FILE && aExtractFileNames != null && aInputPkg != null )
            {
                File aTargetDir = aOutputFile.getParentFile();
                extractFiles( aInputPkg, aTargetDir, aExtractFileNames, aLogger );
            }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

          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();
      while (filePaths.hasNext()) {
        String path = filePaths.next();
        if (path.startsWith(imagePathPrefix) && path.length() > imagePathPrefix.length())
          count++;
        if (count > 2)
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

        i++;
      }
      // an embed section is counted two times
      Assert.assertEquals(count + 1, i);

      OdfPackage packageDocument = newDoc.getPackage();
      String imagePathPrefix = "Pictures/";
      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)
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

      }
      Assert.assertEquals(count - 1, i);

      theSec = doc.getSectionByName("ImageSection");
      theSec.remove();
      OdfPackage packageDocument = doc.getPackage();
      String imagePathPrefix = "Pictures/";
      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 > 1)
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.