wmgr.saveWeblog(website);
// now lets import all the theme resources
List resources = theme.getResources();
Iterator iterat = resources.iterator();
ThemeResource resource = null;
while (iterat.hasNext()) {
resource = (ThemeResource) iterat.next();
log.debug("Importing resource " + resource.getPath());
if (resource.isDirectory()) {
MediaFileDirectory mdir =
fileMgr.getMediaFileDirectoryByPath(website, resource.getPath());
if (mdir == null) {
log.debug(" Creating directory: " + resource.getPath());
mdir = fileMgr.createMediaFileDirectory(
fileMgr.getMediaFileRootDirectory(website), resource.getPath());
roller.flush();
} else {
log.debug(" No action: directory already exists");
}
} else {
String resourcePath = resource.getPath();
MediaFileDirectory mdir = null;
String justName = null;
String justPath = null;
if (resourcePath.indexOf("/") == -1) {
mdir = fileMgr.getMediaFileRootDirectory(website);
justPath = "";
justName = resourcePath;
} else {
justPath = resourcePath.substring(0, resourcePath.lastIndexOf("/"));
if (!justPath.startsWith("/")) justPath = "/" + justPath;
justName = resourcePath.substring(resourcePath.lastIndexOf("/") + 1);
mdir = fileMgr.getMediaFileDirectoryByPath(website, justPath);
if (mdir == null) {
log.debug(" Creating directory: " + justPath);
mdir = fileMgr.createMediaFileDirectoryByPath(website, justPath);
roller.flush();
}
}
MediaFile oldmf = fileMgr.getMediaFileByOriginalPath(website, justPath + "/" + justName);
if (oldmf != null) {
fileMgr.removeMediaFile(website, oldmf);
}
// save file without file-type, quota checks, etc.
InputStream is = resource.getInputStream();
MediaFile mf = new MediaFile();
mf.setDirectory(mdir);
mf.setWeblog(website);
mf.setName(justName);
mf.setOriginalPath(justPath + "/" + justName);
mf.setContentType(map.getContentType(justName));
mf.setInputStream(is);
mf.setLength(resource.getLength());
log.debug(" Saving file: " + justName);
log.debug(" Saviving in directory = " + mf.getDirectory());
RollerMessages errors = new RollerMessages();
fileMgr.createMediaFile(website, mf, errors);
try {
resource.getInputStream().close();
} catch (IOException ex) {
errors.addError("error.closingStream");
log.debug("ERROR closing inputstream");
}
if (errors.getErrorCount() > 0) {