Examples of OdfFileEntry


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

   *             - if the package could not be saved
   */
  private void save(OutputStream odfStream, String baseURL) throws Exception {
    // try {
    mBaseURI = baseURL;
    OdfFileEntry rootEntry = mManifestEntries.get(SLASH);
    if (rootEntry == null) {
      rootEntry = new OdfFileEntry(getManifestDom().getRootElement().newFileEntryElement(SLASH, mMediaType));
      mManifestEntries.put(SLASH, rootEntry);
    } else {
      rootEntry.setMediaTypeString(mMediaType);
    }
    ZipOutputStream zos = new ZipOutputStream(odfStream);
    try {
      // remove mediatype path and use it as first
      this.mManifestEntries.remove(OdfFile.MEDIA_TYPE.getPath());
View Full Code Here

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

    } else {
      ze.setMethod(ZipEntry.STORED);
    }
    crc.reset();
    if (data != null) {
      OdfFileEntry fileEntry = mManifestEntries.get(path);
      // encrypt file
      if (data.length > 0 && fileNeedsEncryption(path)) {
        data = encryptData(data, fileEntry);
        // encrypted file entries shall be flagged as 'STORED'.
        ze.setMethod(ZipEntry.STORED);
        // the size of the encrypted file should replace the real
        // size value.
        ze.setCompressedSize(data.length);
      } else {
        if (fileEntry != null) {
          fileEntry.setSize(null);
          FileEntryElement fileEntryEle = fileEntry.getOdfElement();
          EncryptionDataElement encryptionDataElement = OdfElement.findFirstChildNode(EncryptionDataElement.class, fileEntryEle);
          while (encryptionDataElement != null) {
            fileEntryEle.removeChild(encryptionDataElement);
            encryptionDataElement = OdfElement.findFirstChildNode(EncryptionDataElement.class, fileEntryEle);
          }
View Full Code Here

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

        if (getErrorHandler() != null) {
          logValidationError(OdfPackageConstraint.MANIFEST_WITH_EMPTY_PATH, getBaseURI());
        }
      }
      path = normalizePath(path);
      OdfFileEntry currentFileEntry = entries.get(path);
      if (currentFileEntry == null) {
        currentFileEntry = new OdfFileEntry(fileEntryEle);
      }
      if (path != null) {
        entries.put(path, currentFileEntry);
      }
      fileEntryEle = OdfElement.findNextChildNode(FileEntryElement.class, fileEntryEle);
View Full Code Here

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

      while (tok.hasMoreTokens()) {
        String directory = tok.nextToken();
        // it is a directory, if there are more token
        if (tok.hasMoreTokens()) {
          path = path + directory + SLASH;
          OdfFileEntry fileEntry = mManifestEntries.get(path);
          if (fileEntry == null) {
            mManifestEntries.put(path, new OdfFileEntry(manifestEle.newFileEntryElement(path, null)));
          }
        }
      }
    }
  }
View Full Code Here

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.
    ManifestElement manifestEle = mManifestDom.getRootElement();
    OdfFileEntry embedDocumentRootEntry = new OdfFileEntry(manifestEle.newFileEntryElement(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) {
          newEntryName = SLASH;
        }
        OdfFileEntry srcFileEntry = allEntries.get(entryName);
        OdfFileEntry newFileEntry = new OdfFileEntry(manifestEle.newFileEntryElement(newEntryName, srcFileEntry.getMediaTypeString()));
        newFileEntry.setEncryptionData(srcFileEntry.getEncryptionData());
        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 (!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) {
        ManifestElement manifestEle = getManifestDom().getRootElement();
        if (manifestEle == null)
          return null;
        fileEntry = new OdfFileEntry(manifestEle.newFileEntryElement(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

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            StreamHelper.transformStream(inputStream, out);
            data = out.toByteArray();
            // decrypt data as needed
            if (!(internalPath.equals(OdfFile.MEDIA_TYPE.getPath()) || internalPath.equals(OdfFile.MANIFEST.getPath()))) {
              OdfFileEntry manifestEntry = getManifestEntries().get(internalPath);
              EncryptionDataElement encryptionDataElement = manifestEntry.getEncryptionData();
              if (encryptionDataElement != null) {
                data = decryptData(data, manifestEntry, encryptionDataElement);
              }
            }
            // store for further usage; do not care about manifest:
View Full Code Here

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

   *             when the DOM tree could not be inserted
   */
  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

    internalPath = normalizePath(internalPath);
    if (mZipEntries != null && mZipEntries.containsKey(internalPath)) {
      mZipEntries.remove(internalPath);
    }
    if (mManifestEntries != null && mManifestEntries.containsKey(internalPath)) {
      OdfFileEntry manifestEntry = mManifestEntries.remove(internalPath);
      FileEntryElement manifestEle = manifestEntry.getOdfElement();
      manifestEle.getParentNode().removeChild(manifestEle);
    }
  }
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.