Examples of OdfPackage


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

   * @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

          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

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

  }
 
  private boolean _validate(Logger aLogger) throws ODFValidatorException {
    boolean bHasErrors = false;

    OdfPackage aPkg = getPackage(aLogger);
    if (aPkg == null) {
      return true;
    }

    try {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

  }

  protected boolean validateEntry(XMLFilter aFilter,
      Validator aValidator, Logger aLogger,
      String aEntryName) throws IOException, ZipException, IllegalStateException, ODFValidatorException {
    OdfPackage aPkg = getPackage(aLogger);

    if (!aEntryName.equals(OdfPackage.OdfFile.MANIFEST.getPath()) && isEncrypted(aEntryName, aLogger)) {
      return false;
    }

    InputStream aInStream = null;
    try {
      aInStream = aPkg.getInputStream(aEntryName, true);
    } catch (Exception e) {
      throw new ODFValidatorException(e);
    }

View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

  }

  protected boolean parseEntry(XMLFilter aFilter,
      Logger aLogger,
      String aEntryName, boolean bValidating) throws IOException, ZipException, IllegalStateException, ODFValidatorException {
    OdfPackage aPkg = getPackage(aLogger);

    if (isEncrypted(aEntryName, aLogger)) {
      return false;
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfPackage

  private String getVersion(Logger aLogger) throws ODFValidatorException {
    String aVersion = null;

    InputStream aInStream = null;
    try {
      OdfPackage aPkg = getPackage(aLogger);
      aInStream = aPkg.getInputStream(getStreamName(OdfDocument.OdfXMLFile.META.getFileName()), true);
      if (aInStream == null) {
        aInStream = aPkg.getInputStream(getStreamName(OdfDocument.OdfXMLFile.SETTINGS.getFileName()), true);
      }
      if (aInStream == null) {
        aInStream = aPkg.getInputStream(getStreamName(OdfDocument.OdfXMLFile.CONTENT.getFileName()), true);
      }
      if (aInStream == null) {
        return null;
      }
    } catch (Exception e) {
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())), handler2);
      OdfDocument doc2 = OdfDocument.loadDocument(pkg2);
      Assert.assertNotNull(doc2);

      // Second Test / Handler3
      OdfPackage pkg3 = OdfPackage.loadPackage(new File(ResourceUtilities.getAbsolutePath(handler3.getTestFilePath())), 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())), 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
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.