Examples of OdfFileEntry


Examples of org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry

    }else{
      documentDirectory = internalPath;
    }
    Set<String> entryNameList = entryMapToCopy.keySet();
    for (String entryName : entryNameList) {
      OdfFileEntry entry = entryMapToCopy.get(entryName);
      if (entry != null) {
        try {
          // if entry is a directory (e.g. an ODF document root)
          if (entryName.endsWith(SLASH)) {
            // insert directory
            if (entryName.equals(SLASH)) {
              insert((byte[]) null, documentDirectory, sourceDocument.getMediaTypeString());
            } else {
              insert((byte[]) null, documentDirectory + entry.getPath(), entry.getMediaTypeString());
            }
          } else {
            String packagePath = documentDirectory + entry.getPath();
            insert(sourceDocument.getPackage().getInputStream(entryName), packagePath, entry.getMediaTypeString());
          }
        } catch (Exception ex) {
          Logger.getLogger(OdfPackage.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    }
    //make sure the media type of embedded Document is right set.
    OdfFileEntry embedDocumentRootEntry = new OdfFileEntry(internalPath, sourceDocument.getMediaTypeString());
    mManifestEntries.put(internalPath, embedDocumentRootEntry);
    // the new document will be attached to its new package (it has been inserted to)
    sourceDocument.setPackage(this);
    cacheDocument(sourceDocument, internalPath);
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry

      if (entryName.startsWith(directory)) {
        String newEntryName = entryName.substring(directory.length());
        if (newEntryName.length() == 0) {
          continue;
        }
        OdfFileEntry srcFileEntry = allEntries.get(entryName);
        OdfFileEntry newFileEntry = new OdfFileEntry();
        newFileEntry.setEncryptionData(srcFileEntry.getEncryptionData());
        newFileEntry.setMediaTypeString(srcFileEntry.getMediaTypeString());
        newFileEntry.setPath(newEntryName);
        newFileEntry.setSize(srcFileEntry.getSize());
        subEntries.put(entryName, newFileEntry);
      }
    }
    return subEntries;
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry

   * Adding a manifest:file-entry to be saved in manifest.xml.
   * In addition, sub directories will be added as well to the manifest.
   */
  private OdfFileEntry ensureFileEntryExistence(String internalPath) {
    // if it is NOT the resource "/META-INF/manifest.xml"
    OdfFileEntry fileEntry = null;
    if (!OdfPackage.OdfFile.MANIFEST.internalPath.equals(internalPath) ||
      !internalPath.equals(EMPTY_STRING)) {
      if (mManifestEntries == null) {
        mManifestEntries = new HashMap<String, OdfFileEntry>();
      }
      fileEntry = mManifestEntries.get(internalPath);
      // for every new file entry
      if (fileEntry == null) {
        fileEntry = new OdfFileEntry(internalPath);
        mManifestEntries.put(internalPath, fileEntry);
        // creates recursive file entries for all sub directories
        createSubEntries(internalPath);
      }
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry

                        buf.append(" >\n");
      Iterator<String> it = new TreeSet<String>(mManifestEntries.keySet()).iterator();
      while (it.hasNext()) {
        String key = it.next();
        String s = null;
        OdfFileEntry fileEntry = mManifestEntries.get(key);
        if (fileEntry != null) {
          s = fileEntry.getPath();
          // only directories with a mimetype (documents) will be written into the manifest.xml
          if (s != null && !s.endsWith(SLASH) || !fileEntry.getMediaTypeString().equals(EMPTY_STRING)) {
            buf.append(" <manifest:file-entry");
            if (s != null) {
              buf.append(" manifest:full-path=\"");
              buf.append(encodeXMLAttributes(s));
              buf.append("\"");

            }
            s = fileEntry.getMediaTypeString();
            buf.append(" manifest:media-type=\"");
            buf.append(encodeXMLAttributes(s));
            buf.append("\"");

            int i = fileEntry.getSize();
            if (i > 0) {
              buf.append(" manifest:size=\"");
              buf.append(i);
              buf.append("\"");
            }
            EncryptionData enc = fileEntry.getEncryptionData();
            if (enc != null) {
              buf.append(">\n");
              buf.append("  <manifest:encryption-data>\n");
              Algorithm alg = enc.getAlgorithm();
              if (alg != null) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry

   */
  public OutputStream insertOutputStream(String internalPath, String mediaType)
      throws Exception {
    internalPath = normalizeFilePath(internalPath);
    final String fPath = internalPath;
    final OdfFileEntry fFileEntry = getFileEntry(internalPath);
    final String fMediaType = mediaType;

    ByteArrayOutputStream baos = new ByteArrayOutputStream() {

      @Override
      public void close() {
        try {
          byte[] data = this.toByteArray();
          if (fMediaType == null || fMediaType.length() == 0) {
            insert(data, fPath, fFileEntry == null ? null
                : fFileEntry.getMediaTypeString());
          } else {
            insert(data, fPath, fMediaType);
          }
          super.close();
        } catch (Exception ex) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry

      int embDocsNumber = embDocs.size();
      // the document "Object 1/
      Document embDoc = embDocs.get(0);
      String pathOfSecondInnerDoc = "Object in Object1/";
      embDoc.insertDocument(TextDocument.newTextDocument(), pathOfSecondInnerDoc);
      OdfFileEntry fileEntry = embDoc.getPackage().getFileEntry(embDoc.getDocumentPath() + pathOfSecondInnerDoc);
      Assert.assertNotNull(fileEntry);

      // get "Object 1/content.xml"
      OdfContentDom contentDom = embDoc.getContentDom();
      XPath xpath = contentDom.getXPath();
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry

        }
      }
      path = OdfPackage.normalizePath(path);
      _currentFileEntry = entries.get(path);
      if (_currentFileEntry == null) {
        _currentFileEntry = new OdfFileEntry();
      }
      if (path != null) {
        entries.put(path, _currentFileEntry);
      }
      _currentFileEntry.setPath(atts.getValue("manifest:full-path"));
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry

    try {
      FileInputStream docStream = new FileInputStream(TEST_FILE_FOLDER + Test_File);
      OdfPackage pkg = OdfPackage.loadPackage(docStream);
      docStream.close();

      OdfFileEntry imagefile = pkg.getFileEntry("Pictures/10000000000000B400000050FF285AE0.png");
      Assert.assertNotNull(imagefile);
      Assert.assertEquals("image/png", imagefile.getMediaTypeString());

      byte[] bytes = pkg.getBytes("Pictures/10000000000000B400000050FF285AE0.png");
      Assert.assertEquals(5551, bytes.length);

    } catch (Exception e) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry

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

Examples of org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry

          .getTestResourceAsStream(TEST_PRESENTATION_FILE_ANOTHER));

      // copy slide at index 2 of doc to the index 2 of doc2
      int nEmbedDoc = doc2.getEmbeddedDocuments().size();
      String embedDocName = "Object 3/";
      OdfFileEntry fileEntry = doc2.getPackage().getFileEntry(embedDocName);
      Assert.assertNull(fileEntry);
      Slide newPage1 = doc2.copyForeignSlide(2, doc, 2);
      Assert.assertTrue(2 == newPage1.getSlideIndex());
      // slide at index 2 of doc contains an embedded document called
      // "Object 3"
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.