Merged V2.2 to HEAD

10640: Fixed ETWOTWO-688: Node Path.Element strings are returned with numerical ordering suffix
   10641: Fix for ETWOTWO-640: Cannot login through FTP
   10665: Fix to generate legal Faces component IDs (in turn output as HTML element IDs). Fixes ETWOTWO-687 and ALFCOM-1756.
   10666: Fix for ETWOTWO-539.
   10675: Merged V2.1 to V2.2
     10649: Fix for ETWOONE-98 and extra error/debug logging. ... other linkvalidation enable/disable changes
   10711: Merged V2.1 to V2.2
      10615: Fix to keep org.alfresco.repo.workflow.jbpm.* in the session


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10712 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2008-09-04 01:54:39 +00:00
parent c257497885
commit 78e1f21f14
2 changed files with 94 additions and 33 deletions

View File

@@ -53,7 +53,17 @@ import org.apache.commons.logging.LogFactory;
public final class FacesHelper public final class FacesHelper
{ {
private static Log logger = LogFactory.getLog(FacesHelper.class); private static Log logger = LogFactory.getLog(FacesHelper.class);
private static Pattern FACES_ID_PATTERN = Pattern.compile("[^a-z^A-Z^_]?[^a-z^A-Z^0-9^_^-]");
/**
* Mask for hex encoding
*/
private static final int MASK = (1 << 4) - 1;
/**
* Digits used for hex string encoding
*/
private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
/** /**
* Private constructor * Private constructor
@@ -179,20 +189,16 @@ public final class FacesHelper
} }
/** /**
* Makes the given id a legal JSF component id by replacing illegal * Makes the given id a legal JSF component id by replacing illegal characters
* characters with underscores. * with ISO9075 encoding - which itself a subset of valid HTML ID characters.
* *
* @param id The id to make legal * @param id The id to make legal
* @return The legalised id *
* @return the legalised id
*/ */
public static String makeLegalId(String id) public static String makeLegalId(String id)
{ {
if (id != null) return (id != null ? validFacesId(id) : null);
{
id = FACES_ID_PATTERN.matcher(id).replaceAll("_");
}
return id;
} }
/** /**
@@ -265,4 +271,59 @@ public final class FacesHelper
FacesContext.setCurrentInstance(facesContext); FacesContext.setCurrentInstance(facesContext);
} }
} }
/**
* Helper to ensure only valid and acceptable characters are output as Faces component IDs.
* Based on ISO9075 encoding - which itself a subset of valid HTML ID characters.
*/
private static String validFacesId(String id)
{
int len = id.length();
StringBuilder buf = new StringBuilder(len + (len>>1));
for (int i = 0; i<len; i++)
{
char c = id.charAt(i);
int ci = (int)c;
if (i == 0)
{
if ((ci >= 65 && ci <= 90) || // A-Z
(ci >= 97 && ci <= 122)) // a-z
{
buf.append(c);
}
else
{
encode(c, buf);
}
}
else
{
if ((ci >= 65 && ci <= 90) || // A-Z
(ci >= 97 && ci <= 122) || // a-z
(ci >= 48 && ci <= 57) || // 0-9
ci == 45 || ci == 95) // - and _
{
buf.append(c);
}
else
{
encode(c, buf);
}
}
}
return buf.toString();
}
private static void encode(char c, StringBuilder builder)
{
char[] buf = new char[] { 'x', '0', '0', '0', '0', '_' };
int charPos = 5;
do
{
buf[--charPos] = DIGITS[c & MASK];
c >>>= 4;
}
while (c != 0);
builder.append(buf);
}
} }

View File

@@ -242,7 +242,7 @@ public class UploadContentServlet extends BaseServlet
writer.setEncoding(encoding); writer.setEncoding(encoding);
// Stream the content into the repository // Stream the content into the repository
writer.putContent(req.getInputStream()); writer.putContent(inputStream);
if (logger.isDebugEnabled() == true) if (logger.isDebugEnabled() == true)
{ {