Fix ALF-4363 - follow-on to r22190,

- do not re-encode (else "_x0020_" becomes escaped as "_x005f_x0020_")
- allow ".." and add option to auto-encode "@" as "_x0040_" (for MT bootstrap)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22279 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2010-09-06 15:59:52 +00:00
parent d64830f5ec
commit 6f42e152e7

View File

@@ -66,7 +66,6 @@ import org.alfresco.service.cmr.view.Location;
import org.alfresco.service.cmr.view.ImporterBinding.UUID_BINDING; import org.alfresco.service.cmr.view.ImporterBinding.UUID_BINDING;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.ISO9075;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.DefaultResourceLoader;
@@ -306,7 +305,18 @@ public class ImporterComponent
} }
/** /**
* Create a valid path * Create a valid qname-based xpath
*
* Note:
* - the localname will be truncated to 100 chars
* - the localname should already be encoded for ISO 9075 (in case of MT bootstrap, the @ sign will be auto-encoded, see below)
*
* Some examples:
* /
* sys:people/cm:admin
* /app:company_home/app:dictionary
* ../../cm:people_x0020_folder
* sys:people/cm:admin_x0040_test
* *
* @param path * @param path
* @return * @return
@@ -318,10 +328,25 @@ public class ImporterComponent
for (int i = 0; i < segments.length; i++) for (int i = 0; i < segments.length; i++)
{ {
if (segments[i] != null && segments[i].length() > 0) if (segments[i] != null && segments[i].length() > 0)
{
int colonIndex = segments[i].indexOf(QName.NAMESPACE_PREFIX);
if (colonIndex == -1)
{
// eg. ".."
validPath.append(segments[i]);
}
else
{ {
String[] qnameComponents = QName.splitPrefixedQName(segments[i]); String[] qnameComponents = QName.splitPrefixedQName(segments[i]);
QName segmentQName = QName.createQName(qnameComponents[0], QName.createValidLocalName(qnameComponents[1]), namespaceService);
validPath.append(ISO9075.getXPathName(segmentQName, namespaceService)); String localName = QName.createValidLocalName(qnameComponents[1]);
// MT: bootstrap of "alfrescoUserStore.xml" requires 'sys:people/cm:admin@tenant' to be encoded as 'sys:people/cm:admin_x0040_tenant' (for XPath)
localName = localName.replace("@", "_x0040_");
QName segmentQName = QName.createQName(qnameComponents[0], localName, namespaceService);
validPath.append(segmentQName.toPrefixString());
}
} }
if (i < (segments.length -1)) if (i < (segments.length -1))
{ {
@@ -1053,8 +1078,8 @@ public class ImporterComponent
} }
else if (importedRef.startsWith("/")) else if (importedRef.startsWith("/"))
{ {
importedRef = createValidPath(importedRef); String path = createValidPath(importedRef);
List<NodeRef> nodeRefs = searchService.selectNodes(sourceNodeRef, importedRef, null, namespaceService, false); List<NodeRef> nodeRefs = searchService.selectNodes(sourceNodeRef, path, null, namespaceService, false);
if (nodeRefs.size() > 0) if (nodeRefs.size() > 0)
{ {
nodeRef = nodeRefs.get(0); nodeRef = nodeRefs.get(0);
@@ -1072,8 +1097,8 @@ public class ImporterComponent
// resolve relative path // resolve relative path
try try
{ {
importedRef = createValidPath(importedRef); String path = createValidPath(importedRef);
List<NodeRef> nodeRefs = searchService.selectNodes(sourceNodeRef, importedRef, null, namespaceService, false); List<NodeRef> nodeRefs = searchService.selectNodes(sourceNodeRef, path, null, namespaceService, false);
if (nodeRefs.size() > 0) if (nodeRefs.size() > 0)
{ {
nodeRef = nodeRefs.get(0); nodeRef = nodeRefs.get(0);