Merged MNT-17845-5.2.N (5.2.2) to 5.2.N (5.2.2)

137772 anechifor: REPO-2516 - MNT-17845 : Smart Folders - subtitute isReference with fromNodeRef


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@137782 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2017-06-23 11:37:10 +00:00
parent 689c4cac70
commit f84a7bf2f3
9 changed files with 163 additions and 161 deletions

View File

@@ -63,7 +63,7 @@ public class Reference
* NodeRef Reference representations validated by this method should produce
* valid Reference objects based on the given {@link NodeRef} when passed to
* the {@link #fromNodeRef(NodeRef)} method.
*
* @deprecated
* @param nodeRef
* @return <code>true</code> if the given {@link NodeRef} is a valid
* Reference representation<br>
@@ -119,55 +119,50 @@ public class Reference
}
/**
* {@link NodeRef} {@link Reference} representation decoder/converter
* method.<br>
* Creates a {@link Reference} representation based on the ID of the given
* {@link NodeRef}.<br>
* It expects a {@link #VIRTUAL_TOKEN} prefixed encoded string. The encoded
* string must start with a valid {@link Encoding} token. The Reference
* representation structure is (no delimiters between the 3 elements):
* VIRTUAL_TOKEN ENCODING_TOKEN referenceString Given that a valid encoding
* was detected {@link Encoding#urlNative} information is used to obtain a
* reference string. The reference string is parsed using the encoding
* configured parser.
*
* @param nodeRef
* @return the {@link Reference} object corresponding to the given
* {@link NodeRef}
* @throws ReferenceParseException
* if an error occurs during the reference string parsing
* @throws ReferenceEncodingException
* if the {@link NodeRef} ID has an invalid virtual token prefix
* or it uses an invalid encoding token
*/
public static final Reference fromNodeRef(NodeRef nodeRef) throws ReferenceParseException, ReferenceEncodingException
{
String id = nodeRef.getId();
if (id.startsWith("" + VIRTUAL_TOKEN) && (id.length() > 1)) // belts-and-braces
{
char token = id.charAt(1);
Encoding encoding = Encodings.fromToken(token);
if (encoding == null)
{
throw new ReferenceEncodingException("Invalid encoding token " + token + " in " + id);
}
else
{
String referenceString = id.substring(2);
if (!encoding.urlNative)
{
referenceString = new String(org.apache.commons.codec.binary.Base64.decodeBase64(referenceString));
}
Reference reference = encoding.parser.parse(referenceString);
return reference.propagateNodeRefMutations(nodeRef);
}
}
else
{
throw new ReferenceEncodingException("Invalid node ID format " + id);
}
}
*
* {@link NodeRef} {@link Reference} representation decoder/converter
* method.<br>
* Creates a {@link Reference} representation based on the ID of the given
* {@link NodeRef}.<br>
* It expects a {@link #VIRTUAL_TOKEN} prefixed encoded string. The encoded
* string must start with a valid {@link Encoding} token. The Reference
* representation structure is (no delimiters between the 3 elements):
* VIRTUAL_TOKEN ENCODING_TOKEN referenceString Given that a valid encoding
* was detected {@link Encoding#urlNative} information is used to obtain a
* reference string. The reference string is parsed using the encoding
* configured parser.
* @param nodeRef
* @return the {@link Reference} object corresponding to the given
* {@link NodeRef}
*
*/
public static final Reference fromNodeRef(NodeRef nodeRef) {
String id = nodeRef.getId();
if (id.startsWith("" + VIRTUAL_TOKEN) && (id.length() > 1)) // belts-and-braces
{
char token = id.charAt(1);
Encoding encoding = Encodings.fromToken(token);
if (encoding != null) {
try {
String referenceString = id.substring(2);
if (!encoding.urlNative) {
referenceString = new String(
org.apache.commons.codec.binary.Base64.decodeBase64(referenceString));
}
Reference reference = encoding.parser.parse(referenceString);
return reference.propagateNodeRefMutations(nodeRef);
} catch (ReferenceParseException rpe) {
logger.debug("Parse exception:", rpe);
return null;
}catch (ReferenceEncodingException ree) {
logger.debug("encoding exception:", ree) ;
return null;
}
}
}
return null;
}
// Average reference length log trace