} 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);