use of org.alfresco.repo.virtual.ref.GetTemplatePathMethod in project alfresco-repository by Alfresco.
the class ApplyTemplateMethod method execute.
public VirtualFolderDefinition execute(VirtualProtocol virtualProtocol, Reference reference, VirtualContext context) throws ProtocolMethodException {
Resource resource = reference.getResource();
try {
VirtualFolderDefinition theStructure = resource.processWith(new TemplateResourceProcessor(context));
String path = reference.execute(new GetTemplatePathMethod());
if (!path.isEmpty()) {
String[] pathElements = path.split(PATH_SEPARATOR);
int startIndex = path.startsWith(PATH_SEPARATOR) ? 1 : 0;
for (int i = startIndex; i < pathElements.length; i++) {
theStructure = theStructure.findChildById(pathElements[i]);
if (theStructure == null) {
throw new ProtocolMethodException("Invalid template path in " + reference.toString());
}
}
}
return theStructure;
} catch (ResourceProcessingError e) {
throw new ProtocolMethodException(e);
}
}
use of org.alfresco.repo.virtual.ref.GetTemplatePathMethod in project alfresco-repository by Alfresco.
the class VirtualStoreImpl method getPath.
@Override
public Path getPath(Reference reference) throws VirtualizationException {
Reference virtualPathElement = reference;
Reference virtualPathParent = reference.execute(new GetParentReferenceMethod());
Path virtualPath = new Path();
while (virtualPathElement != null && virtualPathParent != null) {
NodeRef parentNodeRef;
parentNodeRef = virtualPathParent.toNodeRef();
NodeRef parent = parentNodeRef;
NodeRef virtualPathNodeRef = virtualPathElement.toNodeRef();
// TODO: extract node reference name into protocol method in order
// to enforce path processing code reuse and consistency
String templatePath = virtualPathElement.execute(new GetTemplatePathMethod()).trim();
final String pathSeparator = "/";
if (pathSeparator.equals(templatePath)) {
// found root
break;
} else if (templatePath.endsWith(pathSeparator)) {
templatePath = templatePath.substring(0, templatePath.length() - 1);
}
int lastSeparator = templatePath.lastIndexOf(pathSeparator);
String childId = templatePath.substring(lastSeparator + 1);
VirtualFolderDefinition structure = resolveVirtualFolderDefinition(virtualPathParent);
VirtualFolderDefinition child = structure.findChildById(childId);
if (child == null) {
throw new VirtualizationException("Invalid reference: " + reference.encode());
}
String childName = child.getName();
QName childQName = QName.createQName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName);
ChildAssociationRef assocRef = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, parent, childQName, virtualPathNodeRef, true, -1);
ChildAssocElement assocRefElement = new ChildAssocElement(assocRef);
virtualPath.prepend(assocRefElement);
virtualPathElement = virtualPathParent;
virtualPathParent = virtualPathParent.execute(new GetParentReferenceMethod());
}
return virtualPath;
}
Aggregations