. Fixes to the various servlets to allow any number of elements in the web-app context path

- currently anything other than exactly 1 element (e.g. /alfresco) will fail
  - now correctly supports any length including the root context of "/"
. Clipboard copy/move op correctly uses FileFolderService for folders (which means "Copy of…" gets prepended correctly)
. Added more explicit IDs for JbossPortal pages

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2901 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-05-16 16:22:52 +00:00
parent 7b51096510
commit 76c566db61
7 changed files with 30 additions and 24 deletions

View File

@@ -84,14 +84,14 @@ public class CommandServlet extends BaseServlet
return; return;
} }
uri = uri.substring(req.getContextPath().length());
StringTokenizer t = new StringTokenizer(uri, "/"); StringTokenizer t = new StringTokenizer(uri, "/");
int tokenCount = t.countTokens(); int tokenCount = t.countTokens();
if (tokenCount < 4) if (tokenCount < 3)
{ {
throw new IllegalArgumentException("Command Servlet URL did not contain all required args: " + uri); throw new IllegalArgumentException("Command Servlet URL did not contain all required args: " + uri);
} }
t.nextToken(); // skip web app name
t.nextToken(); // skip servlet name t.nextToken(); // skip servlet name
// get the command processor to execute the command e.g. "workflow" // get the command processor to execute the command e.g. "workflow"
@@ -101,8 +101,8 @@ public class CommandServlet extends BaseServlet
String command = t.nextToken(); String command = t.nextToken();
// get any remaining uri elements to pass to the processor // get any remaining uri elements to pass to the processor
String[] args = new String[tokenCount - 4]; String[] args = new String[tokenCount - 3];
for (int i=0; i<tokenCount-4; i++) for (int i=0; i<tokenCount-3; i++)
{ {
args[i] = t.nextToken(); args[i] = t.nextToken();
} }

View File

@@ -114,13 +114,13 @@ public class DownloadContentServlet extends BaseServlet
// TODO: add compression here? // TODO: add compression here?
// see http://servlets.com/jservlet2/examples/ch06/ViewResourceCompress.java for example // see http://servlets.com/jservlet2/examples/ch06/ViewResourceCompress.java for example
// only really needed if we don't use the built in compression of the servlet container // only really needed if we don't use the built in compression of the servlet container
uri = uri.substring(req.getContextPath().length());
StringTokenizer t = new StringTokenizer(uri, "/"); StringTokenizer t = new StringTokenizer(uri, "/");
if (t.countTokens() < 7) if (t.countTokens() < 6)
{ {
throw new IllegalArgumentException("Download URL did not contain all required args: " + uri); throw new IllegalArgumentException("Download URL did not contain all required args: " + uri);
} }
t.nextToken(); // skip web app name
t.nextToken(); // skip servlet name t.nextToken(); // skip servlet name
String attachToken = t.nextToken(); String attachToken = t.nextToken();

View File

@@ -85,20 +85,21 @@ public class ExternalAccessServlet extends BaseServlet
return; return;
} }
uri = uri.substring(req.getContextPath().length());
StringTokenizer t = new StringTokenizer(uri, "/"); StringTokenizer t = new StringTokenizer(uri, "/");
int count = t.countTokens(); int tokenCount = t.countTokens();
if (count < 3) if (tokenCount < 2)
{ {
throw new IllegalArgumentException("Externally addressable URL did not contain all required args: " + uri); throw new IllegalArgumentException("Externally addressable URL did not contain all required args: " + uri);
} }
t.nextToken(); // skip web app name
t.nextToken(); // skip servlet name t.nextToken(); // skip servlet name
String outcome = t.nextToken(); String outcome = t.nextToken();
// get rest of the tokens arguments // get rest of the tokens arguments
String[] args = new String[count - 3]; String[] args = new String[tokenCount - 2];
for (int i=0; i<count - 3; i++) for (int i=0; i<tokenCount - 2; i++)
{ {
args[i] = t.nextToken(); args[i] = t.nextToken();
} }

View File

@@ -25,6 +25,7 @@ import java.util.StringTokenizer;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.transaction.UserTransaction; import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
@@ -100,14 +101,14 @@ public class TemplateContentServlet extends BaseServlet
return; return;
} }
uri = uri.substring(req.getContextPath().length());
StringTokenizer t = new StringTokenizer(uri, "/"); StringTokenizer t = new StringTokenizer(uri, "/");
int tokenCount = t.countTokens(); int tokenCount = t.countTokens();
if (tokenCount < 5) if (tokenCount < 4)
{ {
throw new IllegalArgumentException("Template Servlet URL did not contain all required args: " + uri); throw new IllegalArgumentException("Template Servlet URL did not contain all required args: " + uri);
} }
t.nextToken(); // skip web app name
t.nextToken(); // skip servlet name t.nextToken(); // skip servlet name
// get NodeRef to the content // get NodeRef to the content
@@ -116,7 +117,7 @@ public class TemplateContentServlet extends BaseServlet
// get NodeRef to the template if supplied // get NodeRef to the template if supplied
NodeRef templateRef = null; NodeRef templateRef = null;
if (tokenCount >= 8) if (tokenCount >= 7)
{ {
storeRef = new StoreRef(t.nextToken(), t.nextToken()); storeRef = new StoreRef(t.nextToken(), t.nextToken());
templateRef = new NodeRef(storeRef, t.nextToken()); templateRef = new NodeRef(storeRef, t.nextToken());
@@ -165,7 +166,7 @@ public class TemplateContentServlet extends BaseServlet
} }
// create the model - put the supplied noderef in as space/document as appropriate // create the model - put the supplied noderef in as space/document as appropriate
Object model = getModel(serviceRegistry, req, res, nodeRef); Object model = getModel(serviceRegistry, req.getSession(), req.getParameterMap(), nodeRef);
// process the template against the node content directly to the response output stream // process the template against the node content directly to the response output stream
// assuming the repo is capable of streaming in chunks, this should allow large files // assuming the repo is capable of streaming in chunks, this should allow large files
@@ -215,14 +216,15 @@ public class TemplateContentServlet extends BaseServlet
* *
* @param services ServiceRegistry required for TemplateNode construction * @param services ServiceRegistry required for TemplateNode construction
* @param session HttpSession for accessing current User * @param session HttpSession for accessing current User
* @param paramMap Request parameter map
* @param nodeRef NodeRef of the space/document to process template against * @param nodeRef NodeRef of the space/document to process template against
* *
* @return an object model ready for executing template against * @return an object model ready for executing template against
*/ */
private Object getModel(ServiceRegistry services, HttpServletRequest req, HttpServletResponse res, NodeRef nodeRef) private Object getModel(ServiceRegistry services, HttpSession session, Map paramMap, NodeRef nodeRef)
{ {
// build FreeMarker default model and merge // build FreeMarker default model and merge
Map root = DefaultModelHelper.buildDefaultModel(services, Application.getCurrentUser(req.getSession())); Map root = DefaultModelHelper.buildDefaultModel(services, Application.getCurrentUser(session));
// put the current NodeRef in as "space" and "document" // put the current NodeRef in as "space" and "document"
TemplateNode node = new TemplateNode(nodeRef, services, this.imageResolver); TemplateNode node = new TemplateNode(nodeRef, services, this.imageResolver);

View File

@@ -306,9 +306,10 @@ public class ClipboardBean
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Attempting to copy node ID: " + item.Node.getId() + " into node ID: " + destRef.getId()); logger.debug("Attempting to copy node ID: " + item.Node.getId() + " into node ID: " + destRef.getId());
if (dd.isSubClass(item.Node.getType(), ContentModel.TYPE_CONTENT)) if (dd.isSubClass(item.Node.getType(), ContentModel.TYPE_CONTENT) ||
dd.isSubClass(item.Node.getType(), ContentModel.TYPE_FOLDER))
{ {
// call the node ops service to initiate the copy // copy the file/folder
this.fileFolderService.copy( this.fileFolderService.copy(
item.Node.getNodeRef(), item.Node.getNodeRef(),
destRef, destRef,
@@ -316,6 +317,7 @@ public class ClipboardBean
} }
else else
{ {
// copy the node
this.copyService.copy( this.copyService.copy(
item.Node.getNodeRef(), item.Node.getNodeRef(),
destRef, destRef,
@@ -330,13 +332,14 @@ public class ClipboardBean
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Attempting to move node ID: " + item.Node.getId() + " into node ID: " + destRef.getId()); logger.debug("Attempting to move node ID: " + item.Node.getId() + " into node ID: " + destRef.getId());
if (dd.isSubClass(item.Node.getType(), ContentModel.TYPE_CONTENT)) if (dd.isSubClass(item.Node.getType(), ContentModel.TYPE_CONTENT) ||
dd.isSubClass(item.Node.getType(), ContentModel.TYPE_FOLDER))
{ {
// move the node // move the file/folder
this.fileFolderService.move( this.fileFolderService.move(
item.Node.getNodeRef(), item.Node.getNodeRef(),
destRef, destRef,
name); // TODO: could add "Copy of ..." here if move fails name);
} }
else else
{ {

View File

@@ -155,7 +155,7 @@
<td class="separator" width=1></td> <td class="separator" width=1></td>
<td width=118 valign=middle> <td width=118 valign=middle>
<%-- View mode settings --%> <%-- View mode settings --%>
<a:modeList itemSpacing="4" iconColumnWidth="20" selectedStyleClass="statusListHighlight" disabledStyleClass="statusListDisabled" selectedImage="/images/icons/Details.gif" <a:modeList id="viewMode" itemSpacing="4" iconColumnWidth="20" selectedStyleClass="statusListHighlight" disabledStyleClass="statusListDisabled" selectedImage="/images/icons/Details.gif"
value="#{BrowseBean.browseViewMode}" actionListener="#{BrowseBean.viewModeChanged}" menu="true" menuImage="/images/icons/menu.gif" styleClass="moreActionsMenu"> value="#{BrowseBean.browseViewMode}" actionListener="#{BrowseBean.viewModeChanged}" menu="true" menuImage="/images/icons/menu.gif" styleClass="moreActionsMenu">
<a:listItem value="details" label="#{msg.details_view}" /> <a:listItem value="details" label="#{msg.details_view}" />
<a:listItem value="icons" label="#{msg.view_icon}" /> <a:listItem value="icons" label="#{msg.view_icon}" />

View File

@@ -112,7 +112,7 @@
</td> </td>
<td> <td>
<%-- language selection drop-down --%> <%-- language selection drop-down --%>
<h:selectOneMenu value="#{LoginBean.language}" style="width:150px" onchange="document.forms['loginForm'].submit(); return true;"> <h:selectOneMenu id="language" value="#{LoginBean.language}" style="width:150px" onchange="document.forms['loginForm'].submit(); return true;">
<f:selectItems value="#{LoginBean.languages}" /> <f:selectItems value="#{LoginBean.languages}" />
</h:selectOneMenu> </h:selectOneMenu>
</td> </td>