Merged V2.2 to HEAD

8019: Merged V2.1 to V2.2
     7715: Fix for AWC-1753
     7725: Additional files for AWC-1753 - also fixes unreported issue of OK button not being highlighted when editing post until you press a key
     7726: Additional files for AWC-1753 - also fixes unreported issue of OK button not being highlighted when editing post until you press a key
     7731: Added support for Range and Content-Range headers to support Download managers and Resume features for HTTP downloads
     7967: Workaround for ACT-771: Missing AVM Store system descriptor properties prevents system startup
     7980: AWC-1662: Fixed NPE when searching for users
     7981: Fix for AWC-1661: Can't edit details of user who has had their home space removed
     7988: NodeRef + child path relative URLs support for DownloadContentServlet
     8003: Fix for AWC-1795
     8004: Fix http://issues.alfresco.com/browse/AR-1807

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8461 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2008-03-07 12:28:36 +00:00
parent cb23859b03
commit 51d46140af
10 changed files with 189 additions and 61 deletions

View File

@@ -25,10 +25,13 @@
package org.alfresco.web.app.servlet; package org.alfresco.web.app.servlet;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException; import java.net.SocketException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@@ -39,6 +42,8 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.filestore.FileContentReader; import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.repository.ContentIOException; import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentService;
@@ -125,6 +130,8 @@ public abstract class BaseDownloadContentServlet extends BaseServlet
String attachToken = t.nextToken(); String attachToken = t.nextToken();
boolean attachment = URL_ATTACH.equals(attachToken) || URL_ATTACH_LONG.equals(attachToken); boolean attachment = URL_ATTACH.equals(attachToken) || URL_ATTACH_LONG.equals(attachToken);
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
// get or calculate the noderef and filename to download as // get or calculate the noderef and filename to download as
NodeRef nodeRef; NodeRef nodeRef;
String filename; String filename;
@@ -153,8 +160,34 @@ public abstract class BaseDownloadContentServlet extends BaseServlet
// build noderef from the appropriate URL elements // build noderef from the appropriate URL elements
nodeRef = new NodeRef(storeRef, id); nodeRef = new NodeRef(storeRef, id);
// filename is last remaining token if (tokenCount > 6)
filename = t.nextToken(); {
// found additional relative path elements i.e. noderefid/images/file.txt
// this allows a url to reference siblings nodes via a cm:name based relative path
// solves the issue with opening HTML content containing relative URLs in HREF or IMG tags etc.
List<String> paths = new ArrayList<String>(tokenCount - 5);
while (t.hasMoreTokens())
{
paths.add(URLDecoder.decode(t.nextToken()));
}
filename = paths.get(paths.size() - 1);
try
{
NodeRef parentRef = serviceRegistry.getNodeService().getPrimaryParent(nodeRef).getParentRef();
FileInfo fileInfo = serviceRegistry.getFileFolderService().resolveNamePath(parentRef, paths);
nodeRef = fileInfo.getNodeRef();
}
catch (FileNotFoundException e)
{
throw new AlfrescoRuntimeException("Unable to find node reference by relative path:" + uri);
}
}
else
{
// filename is last remaining token
filename = t.nextToken();
}
} }
// get qualified of the property to get content from - default to ContentModel.PROP_CONTENT // get qualified of the property to get content from - default to ContentModel.PROP_CONTENT
@@ -174,7 +207,6 @@ public abstract class BaseDownloadContentServlet extends BaseServlet
} }
// get the services we need to retrieve the content // get the services we need to retrieve the content
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
NodeService nodeService = serviceRegistry.getNodeService(); NodeService nodeService = serviceRegistry.getNodeService();
ContentService contentService = serviceRegistry.getContentService(); ContentService contentService = serviceRegistry.getContentService();
PermissionService permissionService = serviceRegistry.getPermissionService(); PermissionService permissionService = serviceRegistry.getPermissionService();
@@ -209,13 +241,15 @@ public abstract class BaseDownloadContentServlet extends BaseServlet
long modifiedSince = req.getDateHeader("If-Modified-Since"); long modifiedSince = req.getDateHeader("If-Modified-Since");
if (modifiedSince > 0L) if (modifiedSince > 0L)
{ {
// round the date to the ignore millisecond value which is not supplied by header // round the date to the ignore millisecond value which is not supplied by header
long modDate = (modified.getTime() / 1000L) * 1000L; long modDate = (modified.getTime() / 1000L) * 1000L;
if (modDate <= modifiedSince) if (modDate <= modifiedSince)
{ {
res.setStatus(304); if (logger.isDebugEnabled())
return; logger.debug("Returning 304 Not Modified.");
} res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
} }
res.setDateHeader("Last-Modified", modified.getTime()); res.setDateHeader("Last-Modified", modified.getTime());
@@ -258,9 +292,85 @@ public abstract class BaseDownloadContentServlet extends BaseServlet
// get the content and stream directly to the response output stream // get the content and stream 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
// to be streamed directly to the browser response stream. // to be streamed directly to the browser response stream.
res.setHeader("Accept-Ranges", "bytes");
try try
{ {
reader.getContent( res.getOutputStream() ); boolean processedRange = false;
String range = req.getHeader("Content-Range");
if (range == null)
{
range = req.getHeader("Range");
}
if (range != null)
{
if (logger.isDebugEnabled())
logger.debug("Found content range header: " + range);
// return the specific set of bytes as requested in the content-range header
/* Examples of byte-content-range-spec values, assuming that the entity contains total of 1234 bytes:
The first 500 bytes:
bytes 0-499/1234
The second 500 bytes:
bytes 500-999/1234
All except for the first 500 bytes:
bytes 500-1233/1234 */
/* 'Range' header example:
bytes=10485760-20971519 */
try
{
if (range.length() > 6)
{
StringTokenizer r = new StringTokenizer(range.substring(6), "-/");
if (r.countTokens() >= 2)
{
long start = Long.parseLong(r.nextToken());
long end = Long.parseLong(r.nextToken());
res.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
res.setHeader("Content-Range", range);
res.setHeader("Content-Length", Long.toString(((end-start)+1L)));
InputStream is = null;
try
{
is = reader.getContentInputStream();
if (start != 0) is.skip(start);
long span = (end-start)+1;
long total = 0;
int read = 0;
byte[] buf = new byte[((int)span) < 8192 ? (int)span : 8192];
while ((read = is.read(buf)) != 0 && total < span)
{
total += (long)read;
res.getOutputStream().write(buf, 0, (int)read);
}
res.getOutputStream().close();
processedRange = true;
}
finally
{
if (is != null) is.close();
}
}
}
}
catch (NumberFormatException nerr)
{
// processedRange flag will stay false if this occurs
}
}
if (processedRange == false)
{
// As per the spec:
// If the server ignores a byte-range-spec because it is syntactically
// invalid, the server SHOULD treat the request as if the invalid Range
// header field did not exist.
long size = reader.getSize();
res.setHeader("Content-Range", "bytes 0-" + Long.toString(size-1L) + "/" + Long.toString(size));
res.setHeader("Content-Length", Long.toString(size));
reader.getContent( res.getOutputStream() );
}
} }
catch (SocketException e1) catch (SocketException e1)
{ {

View File

@@ -121,7 +121,7 @@ public class ErrorBean implements Serializable
// format the message for HTML display // format the message for HTML display
message = message.replaceAll("<", "&lt;"); message = message.replaceAll("<", "&lt;");
message = message.replaceAll(">", "&gt;"); message = message.replaceAll(">", "&gt;");
message = message.replaceAll("\n", "<br/>"); message = message.replaceAll("\n", "<br>");
} }
return message; return message;
@@ -144,7 +144,7 @@ public class ErrorBean implements Serializable
trace = stringWriter.toString(); trace = stringWriter.toString();
trace = trace.replaceAll("<", "&lt;"); trace = trace.replaceAll("<", "&lt;");
trace = trace.replaceAll(">", "&gt;"); trace = trace.replaceAll(">", "&gt;");
trace = trace.replaceAll("\n", "<br/>"); trace = trace.replaceAll("\n", "<br>");
} }
return trace; return trace;

View File

@@ -65,7 +65,7 @@ public class EditPostDialog extends CreatePostDialog
String htmlContent = reader.getContentString(); String htmlContent = reader.getContentString();
if (htmlContent != null) if (htmlContent != null)
{ {
this.content = StringUtils.replace(htmlContent, "<br/>", "\r\n"); this.content = StringUtils.replace(htmlContent, "<br>", "\r\n");
} }
} }
} }

View File

@@ -618,7 +618,7 @@ public class ForumsBean implements IContextListener
StringBuilder replyPosterHTML = new StringBuilder("<td valign='top'>"); StringBuilder replyPosterHTML = new StringBuilder("<td valign='top'>");
replyPosterHTML.append("<img src='"); replyPosterHTML.append("<img src='");
replyPosterHTML.append(contextPath); replyPosterHTML.append(contextPath);
replyPosterHTML.append("/images/icons/user_large.gif' /><br/>"); replyPosterHTML.append("/images/icons/user_large.gif' /><br>");
replyPosterHTML.append((String)replyToNode.getProperties().get("creator")); replyPosterHTML.append((String)replyToNode.getProperties().get("creator"));
replyPosterHTML.append("</td>"); replyPosterHTML.append("</td>");
@@ -1230,7 +1230,7 @@ public class ForumsBean implements IContextListener
out.write("<td><table border='0' cellpadding='0' cellspacing='0' width='100%'><tr>"); out.write("<td><table border='0' cellpadding='0' cellspacing='0' width='100%'><tr>");
out.write("<td valign='top'><img src='"); out.write("<td valign='top'><img src='");
out.write(contextPath); out.write(contextPath);
out.write("/images/icons/user_large.gif'/><br/>"); out.write("/images/icons/user_large.gif'/><br>");
out.write((String)node.getProperties().get("creator")); out.write((String)node.getProperties().get("creator"));
out.write("</td><td width='100%'>"); out.write("</td><td width='100%'>");
@@ -1240,7 +1240,7 @@ public class ForumsBean implements IContextListener
renderBodyContents(context, primaryColumn); renderBodyContents(context, primaryColumn);
renderBubbleBottom(out, contextPath, colour); renderBubbleBottom(out, contextPath, colour);
out.write("</td><td><div style='width:32px;' /></td></table></td>"); out.write("</td><td><div style='width:32px;'></div></td></table></td>");
} }
/** /**
@@ -1260,7 +1260,7 @@ public class ForumsBean implements IContextListener
String colour = "yellow"; String colour = "yellow";
out.write("<td width='100%'><table border='0' cellpadding='0' cellspacing='0' width='100%'><tr>"); out.write("<td width='100%'><table border='0' cellpadding='0' cellspacing='0' width='100%'><tr>");
out.write("<td><div style='width:32px;' /></td><td width='100%'>"); out.write("<td><div style='width:32px;'></div></td><td width='100%'>");
renderBubbleTop(out, contextPath, colour, "#FFF5A3"); renderBubbleTop(out, contextPath, colour, "#FFF5A3");
renderHeaderContents(context, out, primaryColumn, actionsColumn, columns); renderHeaderContents(context, out, primaryColumn, actionsColumn, columns);
@@ -1270,7 +1270,7 @@ public class ForumsBean implements IContextListener
out.write("</td><td valign='top'><img src='"); out.write("</td><td valign='top'><img src='");
out.write(contextPath); out.write(contextPath);
out.write("/images/icons/user_large.gif'/><br/>"); out.write("/images/icons/user_large.gif'/><br>");
out.write((String)node.getProperties().get("creator")); out.write((String)node.getProperties().get("creator"));
out.write("</td></table></td>"); out.write("</td></table></td>");
} }

View File

@@ -35,6 +35,6 @@ public class SeparatorGenerator extends HtmlSeparatorGenerator
{ {
// For the standard separator just show a <hr/> element // For the standard separator just show a <hr/> element
this.html = "<div style='margin-top: 6px; margin-bottom: 6px;'><hr/></div>"; this.html = "<div style='margin-top: 6px; margin-bottom: 6px;'><hr></div>";
} }
} }

View File

@@ -341,6 +341,8 @@ public abstract class BaseInviteUsersWizard extends BaseWizardBean
tx = Repository.getUserTransaction(context, true); tx = Repository.getUserTransaction(context, true);
tx.begin(); tx.begin();
List<SelectItem> results = new ArrayList<SelectItem>();
if (filterIndex == 0) if (filterIndex == 0)
{ {
// Use lucene search to retrieve user details // Use lucene search to retrieve user details
@@ -358,16 +360,18 @@ public abstract class BaseInviteUsersWizard extends BaseWizardBean
SearchService.LANGUAGE_LUCENE, SearchService.LANGUAGE_LUCENE,
query.toString()); query.toString());
List<NodeRef> nodes = resultSet.getNodeRefs(); List<NodeRef> nodes = resultSet.getNodeRefs();
items = new SelectItem[nodes.size()];
for (int index=0; index<nodes.size(); index++) for (int index=0; index<nodes.size(); index++)
{ {
NodeRef personRef = nodes.get(index); NodeRef personRef = nodes.get(index);
String firstName = (String)this.getNodeService().getProperty(personRef, ContentModel.PROP_FIRSTNAME); String firstName = (String)this.getNodeService().getProperty(personRef, ContentModel.PROP_FIRSTNAME);
String lastName = (String)this.getNodeService().getProperty(personRef, ContentModel.PROP_LASTNAME); String lastName = (String)this.getNodeService().getProperty(personRef, ContentModel.PROP_LASTNAME);
String username = (String)this.getNodeService().getProperty(personRef, ContentModel.PROP_USERNAME); String username = (String)this.getNodeService().getProperty(personRef, ContentModel.PROP_USERNAME);
SelectItem item = new SortableSelectItem(username, firstName + " " + lastName + " [" + username + "]", lastName); if (username != null)
items[index] = item; {
SelectItem item = new SortableSelectItem(username, firstName + " " + lastName + " [" + username + "]", lastName);
results.add(item);
}
} }
} }
else else
@@ -375,8 +379,7 @@ public abstract class BaseInviteUsersWizard extends BaseWizardBean
// groups - simple text based match on name // groups - simple text based match on name
Set<String> groups = getAuthorityService().getAllAuthorities(AuthorityType.GROUP); Set<String> groups = getAuthorityService().getAllAuthorities(AuthorityType.GROUP);
groups.addAll(getAuthorityService().getAllAuthorities(AuthorityType.EVERYONE)); groups.addAll(getAuthorityService().getAllAuthorities(AuthorityType.EVERYONE));
List<SelectItem> results = new ArrayList<SelectItem>(groups.size());
String containsLower = contains.trim().toLowerCase(); String containsLower = contains.trim().toLowerCase();
int offset = PermissionService.GROUP_PREFIX.length(); int offset = PermissionService.GROUP_PREFIX.length();
for (String group : groups) for (String group : groups)
@@ -386,10 +389,10 @@ public abstract class BaseInviteUsersWizard extends BaseWizardBean
results.add(new SortableSelectItem(group, group.substring(offset), group)); results.add(new SortableSelectItem(group, group.substring(offset), group));
} }
} }
items = new SelectItem[results.size()];
results.toArray(items);
} }
items = new SelectItem[results.size()];
results.toArray(items);
Arrays.sort(items); Arrays.sort(items);
// commit the transaction // commit the transaction

View File

@@ -257,7 +257,7 @@ public class NewUserWizard extends AbstractWizardBean
this.homeSpaceLocation = null; // default to Company root space this.homeSpaceLocation = null; // default to Company root space
this.homeSpaceName = ""; // default to none set below root this.homeSpaceName = ""; // default to none set below root
NodeRef homeFolderRef = (NodeRef) props.get("homeFolder"); NodeRef homeFolderRef = (NodeRef) props.get("homeFolder");
if (this.getNodeService().exists(homeFolderRef) == true) if (homeFolderRef != null && this.getNodeService().exists(homeFolderRef) == true)
{ {
ChildAssociationRef childAssocRef = this.getNodeService().getPrimaryParent(homeFolderRef); ChildAssociationRef childAssocRef = this.getNodeService().getPrimaryParent(homeFolderRef);
NodeRef parentRef = childAssocRef.getParentRef(); NodeRef parentRef = childAssocRef.getParentRef();

View File

@@ -350,13 +350,13 @@ public final class Utils
if (endTagIndex != -1) if (endTagIndex != -1)
{ {
// found end of the tag to match // found end of the tag to match
String tag = s.substring(i + 1, endTagIndex).toLowerCase(); String tag = s.substring(i + 1, endTagIndex);
String matchTag = tag; String matchTag = tag;
if (endMatchIndex != -1) if (endMatchIndex != -1)
{ {
matchTag = s.substring(i + 1, endMatchIndex).toLowerCase(); matchTag = s.substring(i + 1, endMatchIndex);
} }
if (safeTags.contains(matchTag)) if (safeTags.contains(matchTag.toLowerCase()))
{ {
// safe tag - append to buffer // safe tag - append to buffer
buf.append('<').append(tag).append('>'); buf.append('<').append(tag).append('>');

View File

@@ -27,20 +27,15 @@
<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> <%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> <%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>
<h:panelGrid cellpadding="2" cellspacing="2" border="0" width="100%" <f:verbatim>
rowClasses="wizardSectionHeading, paddingRow">
<h:outputText value="#{msg.message}" />
<h:panelGrid cellpadding="2" cellspacing="6" border="0" columns="3"
columnClasses="alignTop, alignTop, alignTop">
<h:graphicImage value="/images/icons/required_field.gif" alt="#{msg.required_field}" />
<h:outputText value="#{msg.message}:" />
<h:inputTextarea id="message" value="#{DialogManager.bean.content}" rows="6" cols="70"
onkeyup="checkButtonState();" onchange="checkButtonState();" />
</h:panelGrid>
</h:panelGrid>
<script type="text/javascript"> <script type="text/javascript">
document.getElementById("dialog:dialog-body:message").focus(); window.onload = pageLoaded;
function pageLoaded()
{
document.getElementById("dialog:dialog-body:message").focus();
checkButtonState();
}
function checkButtonState() function checkButtonState()
{ {
@@ -53,4 +48,17 @@
document.getElementById("dialog:finish-button").disabled = false; document.getElementById("dialog:finish-button").disabled = false;
} }
} }
</script> </script>
</f:verbatim>
<h:panelGrid cellpadding="2" cellspacing="2" border="0" width="100%"
rowClasses="wizardSectionHeading, paddingRow">
<h:outputText value="#{msg.message}" />
<h:panelGrid cellpadding="2" cellspacing="6" border="0" columns="3"
columnClasses="alignTop, alignTop, alignTop">
<h:graphicImage value="/images/icons/required_field.gif" alt="#{msg.required_field}" />
<h:outputText value="#{msg.message}:" />
<h:inputTextarea id="message" value="#{DialogManager.bean.content}" rows="6" cols="70"
onkeyup="checkButtonState();" onchange="checkButtonState();" />
</h:panelGrid>
</h:panelGrid>

View File

@@ -27,22 +27,15 @@
<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> <%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> <%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>
<h:panelGrid cellpadding="2" cellspacing="2" border="0" width="100%" <f:verbatim>
rowClasses="wizardSectionHeading, paddingRow">
<h:outputText value="#{msg.message}" />
<h:panelGrid cellpadding="2" cellspacing="2" border="0" columns="3"
columnClasses="alignTop, alignTop, alignTop">
<h:graphicImage value="/images/icons/required_field.gif" alt="#{msg.required_field}" />
<h:outputText value="#{msg.message}:" />
<h:inputTextarea id="message" value="#{DialogManager.bean.content}" rows="6" cols="70"
onkeyup="checkButtonState();" onchange="checkButtonState();" />
</h:panelGrid>
</h:panelGrid>
<h:outputText value="#{ForumsBean.replyBubbleHTML}" escape="false" />
<script type="text/javascript"> <script type="text/javascript">
document.getElementById("dialog:dialog-body:message").focus(); window.onload = pageLoaded;
function pageLoaded()
{
document.getElementById("dialog:dialog-body:message").focus();
checkButtonState();
}
function checkButtonState() function checkButtonState()
{ {
@@ -56,4 +49,18 @@
} }
} }
</script> </script>
</f:verbatim>
<h:panelGrid cellpadding="2" cellspacing="2" border="0" width="100%"
rowClasses="wizardSectionHeading, paddingRow">
<h:outputText value="#{msg.message}" />
<h:panelGrid cellpadding="2" cellspacing="2" border="0" columns="3"
columnClasses="alignTop, alignTop, alignTop">
<h:graphicImage value="/images/icons/required_field.gif" alt="#{msg.required_field}" />
<h:outputText value="#{msg.message}:" />
<h:inputTextarea id="message" value="#{DialogManager.bean.content}" rows="6" cols="70"
onkeyup="checkButtonState();" onchange="checkButtonState();" />
</h:panelGrid>
</h:panelGrid>
<h:outputText value="#{ForumsBean.replyBubbleHTML}" escape="false" />