FolderFormEx theForm = (FolderFormEx)actionForm;
ActionForward fwd = mapping.findForward("importBookmarks.page");
RollerRequest rreq = RollerRequest.getRollerRequest(request);
RollerSession rses = RollerSession.getRollerSession(request);
BookmarkManager bm = RollerFactory.getRoller().getBookmarkManager();
BasePageModel pageModel = new BasePageModel(
"bookmarksImport.title", request, response, mapping);
request.setAttribute("model", pageModel);
WebsiteData website = getWebsite(request);
pageModel.setWebsite(website);
// if user authorized and a file is being uploaded
if (rses.isUserAuthorizedToAuthor(website) && theForm.getBookmarksFile() != null) {
// this line is here for when the input page is upload-utf8.jsp,
// it sets the correct character encoding for the response
String encoding = request.getCharacterEncoding();
if ((encoding != null) && (encoding.equalsIgnoreCase("utf-8"))) {
response.setContentType("text/html; charset=utf-8");
}
boolean writeFile = false;
//retrieve the file representation
FormFile file = theForm.getBookmarksFile();
String data = null;
InputStream stream = null;
try {
//retrieve the file data
ByteArrayOutputStream baos = new ByteArrayOutputStream();
stream = file.getInputStream();
if (!writeFile) {
//only write files out that are less than 1MB
if (file.getFileSize() < (4*1024000)) {
byte[] buffer = new byte[8192];
int bytesRead = 0;
while ((bytesRead=stream.read(buffer,0,8192)) != -1) {
baos.write(buffer, 0, bytesRead);
}
data = new String(baos.toByteArray());
SimpleDateFormat formatter =
new SimpleDateFormat("yyyyMMddHHmmss");
Date now = new Date();
String folderName = "imported-" + formatter.format(now);
// Use Roller BookmarkManager to import bookmarks
bm.importBookmarks(website, folderName, data);
RollerFactory.getRoller().flush();
CacheManager.invalidate(website);
ActionMessages messages = new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE,