Files
alfresco-community-repo/source/java/org/alfresco/repo/virtual/ref/VirtualHashReferenceParser.java
Raluca Munteanu 86dc6f3402 Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@125603 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2016-04-20 10:21:07 +00:00

97 lines
3.5 KiB
Java

package org.alfresco.repo.virtual.ref;
import java.util.Collections;
import java.util.List;
import org.alfresco.repo.virtual.ref.ReferenceParser.Cursor;
import org.alfresco.util.Pair;
/**
* Custom parser for hash encoded strings of {@link Reference}s having the
* protocol set to {@link VirtualProtocol}.
*/
public class VirtualHashReferenceParser extends ProtocolHashParser
{
private String protocolCode;
private NumericPathHasher numericPathHasher = new NumericPathHasher();
public VirtualHashReferenceParser(HashStore classpathHashStore)
{
this(classpathHashStore,
VIRTUAL_PROTOCOL_CODE);
}
public VirtualHashReferenceParser(HashStore classpathHashStore, String protocolCode)
{
super(classpathHashStore);
this.protocolCode = protocolCode;
}
@Override
public Reference parse(Cursor cursor) throws ReferenceParseException
{
if (!protocolCode.equals(cursor.currentToken()))
{
throw new ReferenceParseException("Node token \"" + protocolCode + "\" expected instead of \""
+ cursor.currentToken() + "\"");
}
cursor.i++;
Resource templateResource = parseResource(cursor);
Resource actualNodeResource = parseResource(cursor);
String pathToken = cursor.nextToken();
String pathCode = pathToken.substring(0,
1);
String templatePath;
if (HASHED_NUMERIC_PATH_CODE.equals(pathCode))
{
String pathHash = pathToken.substring(1);
templatePath = numericPathHasher.lookup(new Pair<String, String>(pathHash,
null));
}
else if (NUMERIC_ROOT_PATH_CODE.equals(pathCode))
{
templatePath = "/";
}
else if (NUMERIC_PATH_CODE.equals(pathCode))
{
String pathNonHashed = pathToken.substring(1);
templatePath = numericPathHasher.lookup(new Pair<String, String>(null,
pathNonHashed));
}
else if (MIXED_NUMERIC_PATH_CODE.equals(pathCode))
{
String pathHash = pathToken.substring(1);
String pathNonHashed = cursor.nextToken();
templatePath = numericPathHasher.lookup(new Pair<String, String>(pathHash,
pathNonHashed));
}
else
{
throw new ReferenceParseException("Pnvalid path token code " + pathCode);
}
return parseVirtualExtension(cursor,
templateResource,
templatePath,
actualNodeResource);
}
protected Reference parseVirtualExtension(Cursor c, Resource templateResource, String templatePath,
Resource actualNodeResource)
{
List<Parameter> extraParameters = Collections.<Parameter> emptyList();
return ((VirtualProtocol) Protocols.VIRTUAL.protocol).newReference(Encodings.HASH.encoding,
templateResource,
templatePath,
actualNodeResource,
extraParameters);
}
}