Merged HEAD (5.1) to 5.1.N (5.1.1)

119450 mcozma: Merged BRANCHES/DEV/VF_REP_INT_51 to HEAD
   ACE-4716 Can't rename a document in a virtual context from CMIS
   ACE-4752 Type virtualization method does not work
   ACE-4717 Document name is renamed when making "Check in" for a document edited in Google Docs
   ACE-4700 Can't upload to a virtual folder when filename starts with a number and includes dashes


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@119613 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2015-12-04 09:10:57 +00:00
parent 38ab389189
commit f187db02f3
29 changed files with 1228 additions and 422 deletions

View File

@@ -19,6 +19,7 @@
package org.alfresco.repo.virtual;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -26,6 +27,10 @@ import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.repo.jscript.ScriptNode;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ISO9075;
/**
* JavaScript API {@link VirtualContext} adapter.
@@ -40,6 +45,8 @@ public class AlfrescoScriptVirtualContext extends BaseScopableProcessorExtension
public static final String ACTUAL_PATH_PH = "ACTUAL_PATH";
public static final String ACTUAL_ISO9075_PATH_PH = "ACTUAL_ISO9075_PATH";
private VirtualContext context;
private ServiceRegistry serviceRegistry;
@@ -54,18 +61,70 @@ public class AlfrescoScriptVirtualContext extends BaseScopableProcessorExtension
this.placeholders = createPlaceHolders();
}
/**
* @return an array containing the plain qname path at index 0 and the
* ISO9075 element-encoded qname path at index 1
*/
private String[] createQNamePaths()
{
final NamespaceService ns = serviceRegistry.getNamespaceService();
final Map<String, String> cache = new HashMap<String, String>();
final StringBuilder bufPlain = new StringBuilder(128);
final StringBuilder bufISO9075 = new StringBuilder(128);
final Path path = serviceRegistry.getNodeService().getPath(context.getActualNodeRef());
for (final Path.Element e : path)
{
if (e instanceof Path.ChildAssocElement)
{
final QName qname = ((Path.ChildAssocElement) e).getRef().getQName();
if (qname != null)
{
String prefix = cache.get(qname.getNamespaceURI());
if (prefix == null)
{
// first request for this namespace prefix, get and
// cache result
Collection<String> prefixes = ns.getPrefixes(qname.getNamespaceURI());
prefix = prefixes.size() != 0 ? prefixes.iterator().next() : "";
cache.put(qname.getNamespaceURI(),
prefix);
}
bufISO9075.append('/').append(prefix).append(':').append(ISO9075.encode(qname.getLocalName()));
bufPlain.append('/').append(prefix).append(':').append(qname.getLocalName());
}
}
else
{
bufISO9075.append('/').append(e.toString());
bufPlain.append('/').append(e.toString());
}
}
String[] qnamePaths = new String[] { bufPlain.toString(), bufISO9075.toString() };
return qnamePaths;
}
// TODO: extract placeholder interface. make placeholders configurable.
// TODO: extract open-close-configurable placeholders
private Map<String, String> createPlaceHolders()
{
Map<String, String> newPlaceholders = new HashMap<>();
String user = AuthenticationUtil.getFullyAuthenticatedUser();
// TODO: extract open-close-configurable placeholders
newPlaceholders.put(CURRENT_USER_PH,
user);
// TODO: can we replace getQnamePath usage
String[] paths = createQNamePaths();
// the actual path will contain the ISO9075 encoded qname path
// this was reverted from a dual placeholder implementation (see CM-523)
newPlaceholders.put(ACTUAL_PATH_PH,
getActualNode().getQnamePath());
paths[1]);
// newPlaceholders.put(ACTUAL_ISO9075_PATH_PH,
// paths[1]);
return newPlaceholders;
}