User: milesparker
Date: 04/08/25 12:31:01
Modified: nukes/src/main/org/jboss/nukes/core/modules/html
HtmlModule.java
Log:
Anotheer missing file from last submission (see below)
_________________________
Ability to add entire directory structure as archive (.zip formatted) file.
Possible to do: 1) Currently does not support "syncronization" -- that is new files are added and existing one's updated, but missing files are not removed from the existing Nukes repository. 2) Might also support export, but that does not seem to fit with managehtml design.
Revision Changes Path
1.85 +250 -295 nukes/nukes/src/main/org/jboss/nukes/core/modules/html/HtmlModule.java
Index: HtmlModule.java
===================================================================
RCS file: /cvsroot/jboss/nukes/nukes/src/main/org/jboss/nukes/core/modules/html/HtmlModule.java,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- HtmlModule.java 9 Jul 2004 22:14:18 -0000 1.84
+++ HtmlModule.java 25 Aug 2004 19:31:00 -0000 1.85
@@ -6,6 +6,7 @@
* See terms of license at gnu.org. *
* *
***************************************/
+
package org.jboss.nukes.core.modules.html;
import org.jboss.nukes.module.ModuleSupport;
@@ -35,16 +36,8 @@
import org.jboss.nukes.core.FileNotFoundException;
import org.jboss.nukes.core.InvalidNameException;
import org.jboss.nukes.core.DuplicateFileException;
-import org.jboss.nukes.core.modules.html.plugins.LinkPlugin;
-import org.jboss.nukes.core.modules.html.plugins.FilePlugin;
-import org.jboss.nukes.core.modules.html.plugins.TextPlugin;
-import org.jboss.nukes.core.modules.html.commands.StoreCommand;
-import org.jboss.nukes.core.modules.html.commands.RenameCommand;
-import org.jboss.nukes.core.modules.html.commands.MoveCommand;
-import org.jboss.nukes.core.modules.html.commands.CopyCommand;
-import org.jboss.nukes.core.modules.html.commands.MakeProdCommand;
-import org.jboss.nukes.core.modules.html.commands.UnmakeProdCommand;
-import org.jboss.nukes.core.modules.html.commands.DeleteCommand;
+import org.jboss.nukes.core.modules.html.plugins.*;
+import org.jboss.nukes.core.modules.html.commands.*;
import org.jboss.nukes.core.modules.index.Indexable;
import org.jboss.nukes.core.modules.index.Index;
import org.jboss.nukes.core.modules.index.DocumentIterator;
@@ -98,7 +91,7 @@
* DELETE/$id:: - delete $id
*
* @author <a href="mailto:julien@... Viet</a>
- * @version $Revision: 1.84 $
+ * @version $Revision: 1.85 $
*/
public class HtmlModule
extends ModuleSupport
@@ -111,7 +104,7 @@
public static final ObjectName OBJECT_NAME = ObjectNameFactory.create("nukes.modules:name=html");
/** Actions enumeration. */
- private static final String[] ACTIONS = {"rename","move","copy","view","edit","makeprod","unmakeprod","delete","deleteall"};
+ private static final String[] ACTIONS = {"rename", "move", "copy", "view", "edit", "makeprod", "unmakeprod", "delete", "deleteall"};
/** Actions index. */
private static final int ACTION_RENAME = 0;
@@ -227,7 +220,7 @@
{
if (signature instanceof ModuleOperationSignature)
{
- ModuleOperationSignature mos = (ModuleOperationSignature)signature;
+ ModuleOperationSignature mos = (ModuleOperationSignature) signature;
String operation = mos.getOperation();
if ("display".equals(operation))
{
@@ -237,29 +230,25 @@
{
// File not found
next.process(signature, req, resp);
- }
- else
+ } else
{
Resource res = getResource(fileId);
if (res == null || res.getContentType().startsWith("text/"))
{
// File found and is text
next.process(signature, req, resp);
- }
- else
+ } else
{
// File found and must be streamed
ResourceResult result = new ResourceResult(res);
resp.setResult(result);
}
}
- }
- else
+ } else
{
next.process(signature, req, resp);
}
- }
- else
+ } else
{
next.process(signature, req, resp);
}
@@ -369,8 +358,8 @@
try
{
Calendar c = Calendar.getInstance();
- c.add(Calendar.DATE, - days);
- DataSource ds = (DataSource)new InitialContext().lookup("java:NukesDS");
+ c.add(Calendar.DATE, -days);
+ DataSource ds = (DataSource) new InitialContext().lookup("java:NukesDS");
conn = ds.getConnection();
ps1 = conn.prepareStatement("SELECT sum(pn_view_count), pn_id FROM nuke_filestat WHERE pn_from>? AND pn_from<? GROUP BY pn_id");
ps2 = conn.prepareStatement("UPDATE nuke_filestat SET pn_view_count=pn_view_count+? WHERE pn_id=? AND pn_vmid=? AND pn_from=?");
@@ -399,8 +388,7 @@
ps2.setString(3, "CAFEBABECAFEBABE");
ps2.setLong(4, 0);
ps2.executeUpdate();
- }
- else
+ } else
{
ps3.setString(1, "CAFEBABECAFEBABE");
ps3.setLong(2, id);
@@ -413,12 +401,10 @@
ps4.setLong(1, 0);
ps4.setLong(2, c.getTimeInMillis());
ps4.executeUpdate();
- }
- catch (Exception exception)
+ } catch (Exception exception)
{
ctx.setRollbackOnly();
- }
- finally
+ } finally
{
Tools.safeClose(rs1);
Tools.safeClose(ps1);
@@ -449,8 +435,7 @@
int days = page.getParameterAsInt("days", -1);
optimize(days);
page.print("Done");
- }
- catch (Exception e)
+ } catch (Exception e)
{
page.print("An exception occured : <br/>");
page.print(Tools.prettyThrowable(e));
@@ -480,7 +465,7 @@
// If we have a query recompute it
Hits hits = index.search(QueryParser.parse(query, "TEXT", analyzer));
documents = new ArrayList();
- for (int i = 0;i < hits.length();i++)
+ for (int i = 0; i < hits.length(); i++)
{
org.apache.lucene.document.Document doc = hits.doc(i);
String fileId = doc.get("FILE_ID");
@@ -490,37 +475,34 @@
}
}
page.getSession().setAttribute("HTML_HITS", documents);
- }
- else
+ } else
{
// Otherwise get the result from the session
- documents = (ArrayList)page.getSession().getAttribute("HTML_HITS");
+ documents = (ArrayList) page.getSession().getAttribute("HTML_HITS");
}
if (documents == null)
{
// If we have no hits, display the search page
search(page);
- }
- else
+ } else
{
// Otherwise display the current result
DelegateContext ctx = new DelegateContext();
int from = Math.min(Math.max(page.getParameterAsInt("offset", 0), 0), documents.size());
int to = Math.min(from + perPage, documents.size());
- for (int i = from;i < to;i++)
+ for (int i = from; i < to; i++)
{
- org.apache.lucene.document.Document doc = (org.apache.lucene.document.Document)documents.get(i);
+ org.apache.lucene.document.Document doc = (org.apache.lucene.document.Document) documents.get(i);
ctx.next("row").
- put("URL", doc.get("FILE_ID").substring(1)).
- put("LABEL", page.getServerBase() + doc.get("FILE_ID"));
+ put("URL", doc.get("FILE_ID").substring(1)).
+ put("LABEL", page.getServerBase() + doc.get("FILE_ID"));
}
GotoWithOffset gwo = new GotoWithOffset(documents.size(), from, perPage, "index.html?module=html&op=query&offset=", "Goto page ", "previous", "next");
ctx.put("RANGE", gwo.generate());
result.render(ctx, page.getBodyWriter());
}
- }
- catch (Exception e)
+ } catch (Exception e)
{
log.error("Cannot perform query", e);
}
@@ -543,7 +525,7 @@
}
// Get the plugin
- Plugin plugin = (Plugin)pluginKeyToPlugin.get(page.getParameter("plugin"));
+ Plugin plugin = (Plugin) pluginKeyToPlugin.get(page.getParameter("plugin"));
if (plugin == null)
{
page.printMessage("No plugin found");
@@ -553,8 +535,7 @@
// Display the page
menu(page);
plugin.blank(page);
- }
- catch (PluginException e)
+ } catch (PluginException e)
{
page.sendError("Cannot create file", e);
}
@@ -593,7 +574,7 @@
// Get the plugin
String pluginKey = page.getParameter("plugin", "");
- Plugin plugin = (Plugin)pluginKeyToPlugin.get(pluginKey);
+ Plugin plugin = (Plugin) pluginKeyToPlugin.get(pluginKey);
if (plugin == null)
{
page.printMessage("No plugin found");
@@ -606,28 +587,22 @@
// Redirect display
page.sendRedirect("index.html?module=html&op=list");
- }
- catch(IOException e)
+ } catch (IOException e)
{
page.sendError("Cannot create file", e);
- }
- catch(FinderException e)
+ } catch (FinderException e)
{
page.sendError("Cannot create file", e);
- }
- catch(InvalidNameException e)
+ } catch (InvalidNameException e)
{
- page.sendError("${html.FILEID_ERROR}");
- }
- catch(FileException e)
+ page.sendError("${html.FILEID_ERROR}");
+ } catch (FileException e)
{
page.sendError("Cannot create file", e);
- }
- catch(CommandException e)
+ } catch (CommandException e)
{
// todo
- }
- catch(PluginException e)
+ } catch (PluginException e)
{
page.sendError("Cannot create file", e);
}
@@ -656,7 +631,7 @@
// Get the plugin
String pluginKey = page.getParameter("plugin");
- Plugin plugin = (Plugin)pluginKeyToPlugin.get(pluginKey);
+ Plugin plugin = (Plugin) pluginKeyToPlugin.get(pluginKey);
if (plugin == null)
{
page.printMessage("No plugin found");
@@ -674,16 +649,13 @@
// Redirect to the list
page.sendRedirect("index.html?module=html&op=list");
- }
- catch(FileNotFoundException e)
+ } catch (FileNotFoundException e)
{
page.sendError("${html._HTMLPAGESNOSUCHITEM}");
- }
- catch(FileException e)
+ } catch (FileException e)
{
page.sendError("Problem during file creation", e);
- }
- catch(Exception e)
+ } catch (Exception e)
{
page.sendError("Problem during file creation", e);
}
@@ -720,20 +692,18 @@
}
// Get the associed plugin
- Plugin plugin = (Plugin)contentTypeToPlugin.get(fileEJB.getContentType());
+ Plugin plugin = (Plugin) contentTypeToPlugin.get(fileEJB.getContentType());
if (plugin == null)
{
- plugin = (Plugin)pluginKeyToPlugin.get("file");
+ plugin = (Plugin) pluginKeyToPlugin.get("file");
}
menu(page);
plugin.edit(page, level, fileEJB);
- }
- catch (IOException e)
+ } catch (IOException e)
{
page.sendError("Problem during file creation", e);
- }
- catch (PluginException e)
+ } catch (PluginException e)
{
page.sendError("Problem during file creation", e);
}
@@ -759,13 +729,12 @@
try
{
temp.add(new Integer(versions[i]));
- }
- catch(NumberFormatException e)
+ } catch (NumberFormatException e)
{
// Not valid, just skip
}
}
- ids = (Integer[])temp.toArray(new Integer[temp.size()]);
+ ids = (Integer[]) temp.toArray(new Integer[temp.size()]);
}
// Get the security level on source and target fileId
@@ -775,159 +744,155 @@
// Do security checks
switch (decode(page, ACTIONS))
{
- case ACTION_RENAME:
- case ACTION_MOVE:
- case ACTION_COPY:
- // We must check that both source and target match security
- if (sourceLevel.lesser(Level.ACCESS_EDIT) || targetLevel.lesser(Level.ACCESS_EDIT))
- {
- page.printMessage("${html._HTMLPAGESNOAUTH}");
- return;
- }
- break;
- case ACTION_VIEW:
- case ACTION_EDIT:
- case ACTION_MAKEPROD:
- if (sourceLevel.lesser(Level.ACCESS_EDIT))
- {
- page.printMessage("${html._HTMLPAGESNOAUTH}");
- return;
- }
- if (ids.length != 1)
- {
- page.printMessage("You must select one version exactly");
- return;
- }
- break;
- case ACTION_UNMAKEPROD:
- if (sourceLevel.lesser(Level.ACCESS_EDIT))
- {
- page.printMessage("${html._HTMLPAGESNOAUTH}");
- return;
- }
- break;
- case ACTION_DELETE:
- if (sourceLevel.lesser(Level.ACCESS_DELETE))
- {
- page.printMessage("${html._HTMLPAGESNOAUTH}");
- return;
- }
- if (!ok)
- {
- StringBuffer okHidden = new StringBuffer("<input type=\"hidden\" name=\"id\" value=\"").append(sourceFileId).append("\"/>");
- for (int i = 0;i < ids.length;i++)
+ case ACTION_RENAME:
+ case ACTION_MOVE:
+ case ACTION_COPY:
+ // We must check that both source and target match security
+ if (sourceLevel.lesser(Level.ACCESS_EDIT) || targetLevel.lesser(Level.ACCESS_EDIT))
{
- okHidden.append("<input type=\"hidden\" name=\"version\" value=\"").append(versions[i]).append("\">");
+ page.printMessage("${html._HTMLPAGESNOAUTH}");
+ return;
}
- DelegateContext root = new DelegateContext();
- root.put("TITLE", "Confirmation");
- root.put("MESSAGE", "Are you sure that you want to delete versions the file " + sourceFileId);
- root.put("OK_OP", "action");
- root.put("OK_SUBMIT", "delete");
- root.put("OK_LABEL", "Delete");
- root.put("OK_HIDDEN", okHidden.toString());
- root.put("CANCEL_OP", "details");
- root.put("CANCEL_SUBMIT", "cancel");
- root.put("CANCEL_LABEL", "Cancel");
- root.put("CANCEL_HIDDEN", "<input type=\"hidden\" name=\"id\" value=\"" + sourceFileId + "\"/>");
- confirm.render(root, page.getBodyWriter());
- return;
- }
- break;
- case ACTION_DELETE_ALL:
- if (sourceLevel.lesser(Level.ACCESS_DELETE))
- {
- page.printMessage("${html._HTMLPAGESNOAUTH}");
- return;
- }
- if (!ok)
- {
- StringBuffer okHidden = new StringBuffer("<input type=\"hidden\" name=\"id\" value=\"").append(sourceFileId).append("\"/>");
- DelegateContext root = new DelegateContext();
- root.put("TITLE", "Confirmation");
- root.put("MESSAGE", "Are you sure that you want to delete all versions of the file " + sourceFileId);
- root.put("OK_OP", "action");
- root.put("OK_SUBMIT", "deleteall");
- root.put("OK_LABEL", "Delete");
- root.put("OK_HIDDEN", okHidden.toString());
- root.put("CANCEL_OP", "details");
- root.put("CANCEL_SUBMIT", "cancel");
- root.put("CANCEL_LABEL", "Cancel");
- root.put("CANCEL_HIDDEN", "<input type=\"hidden\" name=\"id\" value=\"" + sourceFileId + "\"/>");
- confirm.render(root, page.getBodyWriter());
- return;
- }
- break;
- default:
- // Error
- throw new IllegalStateException();
+ break;
+ case ACTION_VIEW:
+ case ACTION_EDIT:
+ case ACTION_MAKEPROD:
+ if (sourceLevel.lesser(Level.ACCESS_EDIT))
+ {
+ page.printMessage("${html._HTMLPAGESNOAUTH}");
+ return;
+ }
+ if (ids.length != 1)
+ {
+ page.printMessage("You must select one version exactly");
+ return;
+ }
+ break;
+ case ACTION_UNMAKEPROD:
+ if (sourceLevel.lesser(Level.ACCESS_EDIT))
+ {
+ page.printMessage("${html._HTMLPAGESNOAUTH}");
+ return;
+ }
+ break;
+ case ACTION_DELETE:
+ if (sourceLevel.lesser(Level.ACCESS_DELETE))
+ {
+ page.printMessage("${html._HTMLPAGESNOAUTH}");
+ return;
+ }
+ if (!ok)
+ {
+ StringBuffer okHidden = new StringBuffer("<input type=\"hidden\" name=\"id\" value=\"").append(sourceFileId).append("\"/>");
+ for (int i = 0; i < ids.length; i++)
+ {
+ okHidden.append("<input type=\"hidden\" name=\"version\" value=\"").append(versions[i]).append("\">");
+ }
+ DelegateContext root = new DelegateContext();
+ root.put("TITLE", "Confirmation");
+ root.put("MESSAGE", "Are you sure that you want to delete versions the file " + sourceFileId);
+ root.put("OK_OP", "action");
+ root.put("OK_SUBMIT", "delete");
+ root.put("OK_LABEL", "Delete");
+ root.put("OK_HIDDEN", okHidden.toString());
+ root.put("CANCEL_OP", "details");
+ root.put("CANCEL_SUBMIT", "cancel");
+ root.put("CANCEL_LABEL", "Cancel");
+ root.put("CANCEL_HIDDEN", "<input type=\"hidden\" name=\"id\" value=\"" + sourceFileId + "\"/>");
+ confirm.render(root, page.getBodyWriter());
+ return;
+ }
+ break;
+ case ACTION_DELETE_ALL:
+ if (sourceLevel.lesser(Level.ACCESS_DELETE))
+ {
+ page.printMessage("${html._HTMLPAGESNOAUTH}");
+ return;
+ }
+ if (!ok)
+ {
+ StringBuffer okHidden = new StringBuffer("<input type=\"hidden\" name=\"id\" value=\"").append(sourceFileId).append("\"/>");
+ DelegateContext root = new DelegateContext();
+ root.put("TITLE", "Confirmation");
+ root.put("MESSAGE", "Are you sure that you want to delete all versions of the file " + sourceFileId);
+ root.put("OK_OP", "action");
+ root.put("OK_SUBMIT", "deleteall");
+ root.put("OK_LABEL", "Delete");
+ root.put("OK_HIDDEN", okHidden.toString());
+ root.put("CANCEL_OP", "details");
+ root.put("CANCEL_SUBMIT", "cancel");
+ root.put("CANCEL_LABEL", "Cancel");
+ root.put("CANCEL_HIDDEN", "<input type=\"hidden\" name=\"id\" value=\"" + sourceFileId + "\"/>");
+ confirm.render(root, page.getBodyWriter());
+ return;
+ }
+ break;
+ default:
+ // Error
+ throw new IllegalStateException();
}
// Execute action
switch (decode(page, ACTIONS))
{
- case ACTION_RENAME:
- RenameCommand renameCmd = new RenameCommand(fHome, sourceFileId, page.getParameter("name", ""));
- renameCmd.execute();
- page.sendRedirect("index.html?module=html&op=details&id=" + renameCmd.getTargetFileId());
- break;
- case ACTION_MOVE:
- MoveCommand moveCmd = new MoveCommand(fHome, sourceFileId, page.getParameter("dir", ""));
- moveCmd.execute();
- page.sendRedirect("index.html?module=html&op=details&id=" + moveCmd.getTargetFileId());
- break;
- case ACTION_COPY:
- CopyCommand copyCmd = new CopyCommand(fHome, sourceFileId, page.getParameter("dir", ""), page.getParameter("name", ""));
- copyCmd.execute();
- page.sendRedirect("index.html?module=html&op=details&id=" + copyCmd.getTargetFileId());
- break;
- case ACTION_VIEW:
- FileEJBLocal file = fHome.findByPrimaryKey(ids[0]);
- print(page, file.getFileId(), file.getContentType(), new String(file.getContent()), file.getId());
- return;
- case ACTION_EDIT:
- modify(page, fHome.findByPrimaryKey(ids[0]));
- return;
- case ACTION_MAKEPROD:
- MakeProdCommand makeProdCmd = new MakeProdCommand(fHome, sourceFileId, ids[0]);
- makeProdCmd.execute();
- page.sendRedirect("index.html?module=html&op=details&id=" + sourceFileId);
- break;
- case ACTION_UNMAKEPROD:
- UnmakeProdCommand unmakeProdCmd = new UnmakeProdCommand(fHome, sourceFileId, ids);
- unmakeProdCmd.execute();
- page.sendRedirect("index.html?module=html&op=details&id=" + sourceFileId);
- break;
- case ACTION_DELETE:
- DeleteCommand deleteCmd = new DeleteCommand(fHome, sourceFileId, ids);
- deleteCmd.execute();
- page.sendRedirect("index.html?module=html&op=list");
- break;
- case ACTION_DELETE_ALL:
- deleteCmd = new DeleteCommand(fHome, sourceFileId);
- deleteCmd.execute();
- page.sendRedirect("index.html?module=html&op=list");
- break;
- default:
- // error
+ case ACTION_RENAME:
+ RenameCommand renameCmd = new RenameCommand(fHome, sourceFileId, page.getParameter("name", ""));
+ renameCmd.execute();
+ page.sendRedirect("index.html?module=html&op=details&id=" + renameCmd.getTargetFileId());
+ break;
+ case ACTION_MOVE:
+ MoveCommand moveCmd = new MoveCommand(fHome, sourceFileId, page.getParameter("dir", ""));
+ moveCmd.execute();
+ page.sendRedirect("index.html?module=html&op=details&id=" + moveCmd.getTargetFileId());
+ break;
+ case ACTION_COPY:
+ CopyCommand copyCmd = new CopyCommand(fHome, sourceFileId, page.getParameter("dir", ""), page.getParameter("name", ""));
+ copyCmd.execute();
+ page.sendRedirect("index.html?module=html&op=details&id=" + copyCmd.getTargetFileId());
+ break;
+ case ACTION_VIEW:
+ FileEJBLocal file = fHome.findByPrimaryKey(ids[0]);
+ print(page, file.getFileId(), file.getContentType(), new String(file.getContent()), file.getId());
+ return;
+ case ACTION_EDIT:
+ modify(page, fHome.findByPrimaryKey(ids[0]));
+ return;
+ case ACTION_MAKEPROD:
+ MakeProdCommand makeProdCmd = new MakeProdCommand(fHome, sourceFileId, ids[0]);
+ makeProdCmd.execute();
+ page.sendRedirect("index.html?module=html&op=details&id=" + sourceFileId);
+ break;
+ case ACTION_UNMAKEPROD:
+ UnmakeProdCommand unmakeProdCmd = new UnmakeProdCommand(fHome, sourceFileId, ids);
+ unmakeProdCmd.execute();
+ page.sendRedirect("index.html?module=html&op=details&id=" + sourceFileId);
+ break;
+ case ACTION_DELETE:
+ DeleteCommand deleteCmd = new DeleteCommand(fHome, sourceFileId, ids);
+ deleteCmd.execute();
+ page.sendRedirect("index.html?module=html&op=list");
+ break;
+ case ACTION_DELETE_ALL:
+ deleteCmd = new DeleteCommand(fHome, sourceFileId);
+ deleteCmd.execute();
+ page.sendRedirect("index.html?module=html&op=list");
+ break;
+ default:
+ // error
}
// Invalidate the modified file
notifyResourceChange(sourceFileId);
- }
- catch(FileNotFoundException e)
+ } catch (FileNotFoundException e)
{
page.sendError("The file name " + e.getName() + " has not been found");
- }
- catch(InvalidNameException e)
+ } catch (InvalidNameException e)
{
page.sendError("The file name " + e.getName() + " is not valid");
- }
- catch(DuplicateFileException e)
+ } catch (DuplicateFileException e)
{
page.sendError("The name " + e.getName() + " already exist");
- }
- catch(Exception e)
+ } catch (Exception e)
{
log.error("Unexpected error", e);
page.sendError("An error has occured", e);
@@ -988,31 +953,30 @@
// Each version of the file
int count = 0;
StringBuffer versions = new StringBuffer();
- for (Iterator i = files.iterator();i.hasNext();)
+ for (Iterator i = files.iterator(); i.hasNext();)
{
- FileEJBLocal file = (FileEJBLocal)i.next();
+ FileEJBLocal file = (FileEJBLocal) i.next();
if (file.getPublic())
{
versions.append("<option value=\"").append(file.getId()).append("\" selected=\"selected\">").append(count++).append(" *").append("</option>");
- }
- else
+ } else
{
versions.append("<option value=\"").append(file.getId()).append("\">").append(count++).append("").append("</option>");
}
- if (count >= files.size() - 5)
+ if (count >= files.size() - 5)
{
- Double views = (Double)fsHome.selectGeneric("SELECT SUM(f.viewCount) FROM filestat AS f WHERE f.file=?1", new Object[]{file}).iterator().next();
+ Double views = (Double) fsHome.selectGeneric("SELECT SUM(f.viewCount) FROM filestat AS f WHERE f.file=?1", new Object[]{file}).iterator().next();
ctx.next("version").next(file.getPublic() ? "public" : "private").
- put("ID", file.getId().toString()).
- put("DATE", shortFormatter.format(file.getCreationDate())).
- put("OWNER", file.getOwner().getUserName()).
- put("CONTENT_TYPE", file.getContentType()).
- put("SIZE", Integer.toString(file.getContent().length)).
- put("VIEWS", views == null ? "0" : Integer.toString(views.intValue()));
+ put("ID", file.getId().toString()).
+ put("DATE", shortFormatter.format(file.getCreationDate())).
+ put("OWNER", file.getOwner().getUserName()).
+ put("CONTENT_TYPE", file.getContentType()).
+ put("SIZE", Integer.toString(file.getContent().length)).
+ put("VIEWS", views == null ? "0" : Integer.toString(views.intValue()));
}
if (!i.hasNext())
{
- Double views = (Double)fsHome.selectGeneric("SELECT SUM(f.viewCount) FROM filestat AS f WHERE f.file.fileId=?1", new Object[]{fileId}).iterator().next();
+ Double views = (Double) fsHome.selectGeneric("SELECT SUM(f.viewCount) FROM filestat AS f WHERE f.file.fileId=?1", new Object[]{fileId}).iterator().next();
ctx.put("DETAILS", "Details of " + matcher.group(2));
ctx.put("DIRS_LINKS", formatDir(matcher.group(1)));
ctx.put("ID", file.getFileId());
@@ -1031,8 +995,7 @@
// Finally render the page
menu(page);
details.render(ctx, page.getBodyWriter());
- }
- catch(FinderException e)
+ } catch (FinderException e)
{
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
@@ -1069,9 +1032,9 @@
parent.put("DIRECTORY", "<a href=\"index.html?module=html&op=list&prefix=" + dirMatcher.group(1) + "\">..</a>");
root.append("directories", parent);
- for (Iterator i = fHome.getDirectoriesByPrefix(prefix).iterator();i.hasNext();)
+ for (Iterator i = fHome.getDirectoriesByPrefix(prefix).iterator(); i.hasNext();)
{
- String dir = (String)i.next();
+ String dir = (String) i.next();
if (dirMatcher.matches(dir) && secAuthAction(dir + "::", Level.ACCESS_EDIT))
{
DelegateContext sub = new DelegateContext();
@@ -1083,9 +1046,9 @@
Set publicFileIds = new HashSet();
Matcher fileMatcher = FileEJB.FILE.matcher();
- for (Iterator i = fHome.findPublicByPrefix(prefix).iterator();i.hasNext();)
+ for (Iterator i = fHome.findPublicByPrefix(prefix).iterator(); i.hasNext();)
{
- FileEJBLocal file = (FileEJBLocal)i.next();
+ FileEJBLocal file = (FileEJBLocal) i.next();
String fileId = file.getFileId();
publicFileIds.add(fileId);
if (fileMatcher.matches(fileId) && secAuthAction(fileId + "::", Level.ACCESS_EDIT))
@@ -1101,9 +1064,9 @@
Collection allNotPublicFileIds = fHome.getFilesIdsByPrefix(prefix);
allNotPublicFileIds.removeAll(publicFileIds);
- for (Iterator i = allNotPublicFileIds.iterator();i.hasNext();)
+ for (Iterator i = allNotPublicFileIds.iterator(); i.hasNext();)
{
- String fileId = (String)i.next();
+ String fileId = (String) i.next();
if (fileMatcher.matches(fileId) && secAuthAction(fileId + "::", Level.ACCESS_EDIT))
{
DelegateContext sub = new DelegateContext();
@@ -1117,8 +1080,7 @@
menu(page);
list.render(root, page.getBodyWriter());
- }
- catch(FinderException e)
+ } catch (FinderException e)
{
log.error("", e);
}
@@ -1153,17 +1115,17 @@
{
super.start();
InitialContext ctx = new InitialContext();
- fHome = (FileEJBLocalHome)ctx.lookup(FileEJBLocalHome.JNDI_NAME);
- fsHome = (FileStatEJBLocalHome)ctx.lookup(FileStatEJBLocalHome.JNDI_NAME);
- utils = ((UtilsEJBLocalHome)ctx.lookup(UtilsEJBLocalHome.JNDI_NAME)).create();
+ fHome = (FileEJBLocalHome) ctx.lookup(FileEJBLocalHome.JNDI_NAME);
+ fsHome = (FileStatEJBLocalHome) ctx.lookup(FileStatEJBLocalHome.JNDI_NAME);
+ utils = ((UtilsEJBLocalHome) ctx.lookup(UtilsEJBLocalHome.JNDI_NAME)).create();
Document doc = repository.loadTemplate("/module.html");
- repository.addTemplate("list", (Element)doc.selectSingleNode("/node/loop[@name='list']/node"));
- repository.addTemplate("details", (Element)doc.selectSingleNode("/node/loop[@name='details']/node"));
- repository.addTemplate("css", (Element)doc.selectSingleNode("/node/loop[@name='css']/node"));
- repository.addTemplate("menu", (Element)doc.selectSingleNode("/node/loop[@name='menu']/node"));
- repository.addTemplate("search", (Element)doc.selectSingleNode("/node/loop[@name='search']/node"));
- repository.addTemplate("confirm", (Element)doc.selectSingleNode("/node/loop[@name='confirm']/node"));
- repository.addTemplate("result", (Element)doc.selectSingleNode("/node/loop[@name='result']/node"));
+ repository.addTemplate("list", (Element) doc.selectSingleNode("/node/loop[@name='list']/node"));
+ repository.addTemplate("details", (Element) doc.selectSingleNode("/node/loop[@name='details']/node"));
+ repository.addTemplate("css", (Element) doc.selectSingleNode("/node/loop[@name='css']/node"));
+ repository.addTemplate("menu", (Element) doc.selectSingleNode("/node/loop[@name='menu']/node"));
+ repository.addTemplate("search", (Element) doc.selectSingleNode("/node/loop[@name='search']/node"));
+ repository.addTemplate("confirm", (Element) doc.selectSingleNode("/node/loop[@name='confirm']/node"));
+ repository.addTemplate("result", (Element) doc.selectSingleNode("/node/loop[@name='result']/node"));
list = repository.createTemplate("list");
details = repository.createTemplate("details");
menu = repository.createTemplate("menu");
@@ -1176,13 +1138,15 @@
// Plugins setup
pluginContext.setFileHome(fHome);
- TextPlugin htmlPlugin = new TextPlugin();
- FilePlugin filePlugin = new FilePlugin();
- LinkPlugin linkPlugin = new LinkPlugin();
+ Plugin htmlPlugin = new TextPlugin();
+ Plugin filePlugin = new FilePlugin();
+ Plugin linkPlugin = new LinkPlugin();
+ Plugin archivePlugin = new ArchivePlugin();
pluginKeyToPlugin.put("html", htmlPlugin);
pluginKeyToPlugin.put("file", filePlugin);
pluginKeyToPlugin.put("link", linkPlugin);
+ pluginKeyToPlugin.put("archive", archivePlugin);
contentTypeToPlugin.put("text/html", htmlPlugin);
contentTypeToPlugin.put("text/plain", htmlPlugin);
@@ -1191,10 +1155,11 @@
contentTypeToPlugin.put("text/link", linkPlugin);
filePlugin.init(pluginContext);
+ archivePlugin.init(pluginContext);
- for (Iterator i = pluginKeyToPlugin.values().iterator();i.hasNext();)
+ for (Iterator i = pluginKeyToPlugin.values().iterator(); i.hasNext();)
{
- Plugin plugin = (Plugin)i.next();
+ Plugin plugin = (Plugin) i.next();
plugin.init(pluginContext);
}
@@ -1215,18 +1180,17 @@
{
public Object execute() throws Exception
{
- for (Iterator i = temp.entrySet().iterator();i.hasNext();)
+ for (Iterator i = temp.entrySet().iterator(); i.hasNext();)
{
- Map.Entry entry = (Map.Entry)i.next();
- Integer key = (Integer)entry.getKey();
- MuLong value = (MuLong)entry.getValue();
+ Map.Entry entry = (Map.Entry) i.next();
+ Integer key = (Integer) entry.getKey();
+ MuLong value = (MuLong) entry.getValue();
fsHome.create(key.intValue(), now, length, value.longValue());
}
return null;
}
});
- }
- catch(Exception e)
+ } catch (Exception e)
{
log.error("Problem when saving snapshots", e);
}
@@ -1252,12 +1216,10 @@
pluginKeyToPlugin.clear();
contentTypeToPlugin.clear();
pluginContext.setFileHome(null);
- }
- catch(Exception e)
+ } catch (Exception e)
{
log.error("Problem when stopping HTMLModule", e);
- }
- finally
+ } finally
{
super.stop();
}
@@ -1273,18 +1235,17 @@
// Components overrides ------------------------------------------
- public boolean isAuthorizedToGetResource (String fileId)
+ public boolean isAuthorizedToGetResource(String fileId)
{
return secAuthAction(fileId + "::", Level.ACCESS_READ);
}
public Resource getResource(String fileId)
{
- if (isAuthorizedToGetResource (fileId))
+ if (isAuthorizedToGetResource(fileId))
{
return getResourceNoCheck(fileId);
- }
- else
+ } else
{
return null;
}
@@ -1295,10 +1256,10 @@
// The returned resource
File res = null;
- for (int count = 1;count >= 0;count--)
+ for (int count = 1; count >= 0; count--)
{
// Look in the cache first
- res = (File)resourceManager.get(fileId);
+ res = (File) resourceManager.get(fileId);
// Not found so go to the database
if (res == null)
@@ -1311,8 +1272,7 @@
{
fileEJB = (FileEJBLocal) iterator.next();
}
- }
- catch (FinderException e)
+ } catch (FinderException e)
{
log.error("Cannot retrieve public file with id=" + fileId);
}
@@ -1329,7 +1289,7 @@
{
// Update statistics
Integer key = res.getId();
- MuLong value = (MuLong)statistics.get(key);
+ MuLong value = (MuLong) statistics.get(key);
if (value == null)
{
value = new MuLong();
@@ -1341,13 +1301,11 @@
if ("text/link".equals(res.getContentType()))
{
fileId = res.getContentAsString();
- }
- else
+ } else
{
break;
}
- }
- else
+ } else
{
break;
}
@@ -1363,10 +1321,11 @@
}
private static String LOAD_POSTS = null;
+
static
{
StringBuffer temp = new StringBuffer("SELECT f.pn_id, f.pn_fid, f.pn_uid, f.pn_content_type, f.pn_content, f.pn_timest, f.pn_public FROM nuke_file f");
- for (int i = 0;i < 100;i++)
+ for (int i = 0; i < 100; i++)
{
temp.append(i == 0 ? " WHERE f.pn_id=?" : " OR f.pn_id=?");
}
@@ -1377,17 +1336,19 @@
{
try
{
- DataSource ds = (DataSource)new InitialContext().lookup("java:NukesDS");
+ DataSource ds = (DataSource) new InitialContext().lookup("java:NukesDS");
return new DocumentIterator(ds, 100)
{
protected String createLoadAllIds()
{
return "SELECT f.pn_id FROM nuke_file f WHERE f.pn_content_type LIKE 'text/html' AND f.pn_public=1";
}
+
protected String createBatchLoader()
{
return LOAD_POSTS;
}
+
protected void handle(ResultSet rs) throws SQLException
{
while (rs.next())
@@ -1407,8 +1368,7 @@
}
}
};
- }
- catch (NamingException e)
+ } catch (NamingException e)
{
log.error("Cannot create HTML index", e);
return Collections.EMPTY_LIST.iterator();
@@ -1431,9 +1391,9 @@
if (level.greaterOrEquals(Level.ACCESS_ADD))
{
StringBuffer select = new StringBuffer("<form style=\"display:inline;\" action=\"index.html\" method=\"get\"><select name=\"plugin\">");
- for (Iterator i = pluginKeyToPlugin.keySet().iterator();i.hasNext();)
+ for (Iterator i = pluginKeyToPlugin.keySet().iterator(); i.hasNext();)
{
- String pluginKey = (String)i.next();
+ String pluginKey = (String) i.next();
select.append("<option value=\"").append(pluginKey).append("\">").append(pluginKey).append("</option>");
}
select.append("</select> ");
@@ -1451,7 +1411,7 @@
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < items.size(); i++)
{
- String item = (String)items.get(i);
+ String item = (String) items.get(i);
buffer.append(i == 0 ? "<li class=\"first\">" : "<li>");
buffer.append(item).append("</li>");
}
@@ -1466,8 +1426,7 @@
try
{
return fHome.findByPrimaryKey(id);
- }
- catch (FinderException e)
+ } catch (FinderException e)
{
log.error("Error when looking for file with id=" + id, e);
return null;
@@ -1479,8 +1438,7 @@
if (file == null)
{
page.sendError("${html._HTMLPAGESIDNOTINDICATED}");
- }
- else
+ } else
{
print(page, file.getFileId(), file.getContentType(), new String(file.getContent()), file.getId());
}
@@ -1492,10 +1450,9 @@
if (res == null || !(res instanceof File))
{
page.sendError("${html._HTMLPAGESIDNOTINDICATED}");
- }
- else
+ } else
{
- File file = (File)res;
+ File file = (File) res;
print(page, fileId, file.getContentType(), file.getContentAsString(), file.getId());
}
}
@@ -1512,7 +1469,7 @@
if (contentType == null || !contentType.startsWith("text/"))
{
page.openTable();
- page.print("<iframe width=\"100%\" height=\"600\" src=\"" + page.getServerBase() + fileId + "\">");
+ page.print("<iframe width=\"100%\" height=\"600\" src=\"" + page.getServerBase() + fileId + "\">");
page.print("Your browser do not support iframes");
page.print("</iframe>");
page.closeTable();
@@ -1529,9 +1486,9 @@
if (level.greaterOrEquals(Level.ACCESS_EDIT))
{
page.print("<div class=\"pn-normal\">" +
- "<a href=\"index.html?module=html&op=modify&id=" + id + "\">Edit</a> | " +
- "<a href=\"index.html?module=html&op=details&id=" + fileId + "\">Details</a>" +
- " - " + fileId + "</div>");
+ "<a href=\"index.html?module=html&op=modify&id=" + id + "\">Edit</a> | " +
+ "<a href=\"index.html?module=html&op=details&id=" + fileId + "\">Details</a>" +
+ " - " + fileId + "</div>");
}
page.print(content);
@@ -1561,12 +1518,10 @@
Matcher matcher = FileEJB.DIR.matcher();
if (!matcher.matches(dir))
{
- }
- else if (dir.length() == 1)
+ } else if (dir.length() == 1)
{
buffer.append("<a href=\"index.html?module=html&op=list&prefix=/\">/ </a>");
- }
- else
+ } else
{
String left = matcher.group(1);
String right = matcher.group(2);
|