Merged DEV/SWIFT to HEAD

27168: Added generics for cannedQueryRegistry
   27169: Fixed formatting
   27170: SOLR queries
          - ALF-7072 RSOLR 013: Remote API to get ACLs and readers
            - Queries for ACL ChangeSets and ACLs
            - WebScripts for AclChangeSetsGet
          - ALF-7071 and ALF-7072: Fix naming conventions
   27171: Fixed MySQL create script (ALF-8336: RSOLR 013: DB upgrade scripts for ACL changes)
   27337: Initial draft of the publishing API
   27516: Get the basic WCM ML tests working, covering the simpler use cases
   27517: More on the WCM-QS multi lingual support, further on the aspect and the unit tests for it
   27518: Begin the WCM-QS webscript to return the translation details on a node
   27519: Push some WCM-QS ML search logic into SiteHelper, and add a unit test for it
   27542: - Initial skeleton of the channel API.
          - Initial draft of the publishing content model.
   27546: ALF-7481: RSOLR 018: Execute query against SOLR
          - pass authority filter in json body to avoid possible issue over-running the max URL length
   27559: Created a Web Site Generator tool which randomly generates WCM QS websites.
   27561: Created ChannelServiceImpl and implemented the ChannelType registry.
   27577: Start to pull across the WCM-QS ML custom action
   27579: More pulling across the WCM-QS ML custom action
   27580: More WCM-QS ML ui porting
   27588: ALF-8421: RSOLR 037: Encapsulate the CMIS Query Parser
   27589: Created a PublishingModel to hold Web Publishing constants.
   27610: ALF-7874 Add iWorks mimetype entries
   27624: Restructure index tracking
   27630: ALF-8182: SVC 03: Object Picker needs to use new NodeLocatorService to resolve startLocation parameter
          The picker now uses the NodeLocatorService to look up some start locations and most importantly allows
		  custom 'locators' to be used. All the current start location tokens are still supported
		  i.e. {companyhome}, {userhome}, {siteshome}, {doclib}, {self} and {parent}. A new one has been added called {ancestor},
		  this will allow an ancestor node to be located, the node can be selected by type or aspect, see example below.
          Some node locators can take parameters, a "startLocationParams" has therefore been added to allow these to be specified.

		  The example below shows how to configure a picker to start in the root folder of the site the node being edited is located within.

		  <field id="fdk:contentMultiple">
             <control>
                <control-param name="startLocation">{ancestor}</control-param>
                <control-param name="startLocationParams">type=st:site</control-param>
             </control>
          </field>
   27631: ALF-8182: SVC 03: Object Picker needs to use new NodeLocatorService to resolve startLocation parameter
          Centralised node locator classes to repo.nodelocator package
		  (moved out of repo.node package as that area is reserved for low level node processing)
		  and made all naming consistent i.e. nodelocator rather than nodelocation.
   27633: Fixed cmis:objectTypeId property definition (required = true, see CMIS 1.0 errata 1)
   27635: CMIS compliance fixes
   27638: - Initial operational publishing context with model bootstrapped.
          - First implementation of ChannelService.getChannels and ChannelService.createChannel. Test cases to follow imminently...

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28301 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2011-06-09 12:08:12 +00:00
parent efbd951a10
commit ae765f91d9
91 changed files with 2720 additions and 28122 deletions

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import java.util.Collections;
import java.util.List;
import org.alfresco.service.cmr.action.ParameterDefinition;
/**
* Base class for all {@link NodeLocator} implementations.
* <p>Extending this class with automatically register the node locator with the NodeLocatorService.</p>
*
* @author Nick Smith
* @since 4.0
*/
public abstract class AbstractNodeLocator implements NodeLocator
{
public void setNodeLocatorService(NodeLocatorService nodeLocatorService)
{
nodeLocatorService.register(getName(), this);
}
/**
* {@inheritDoc}
*/
public List<ParameterDefinition> getParameterDefinitions()
{
return Collections.emptyList();
}
public abstract String getName();
}

View File

@@ -0,0 +1,140 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
* This {@link NodeLocator} identifies an ancestor of the source node.
* <p>The node returned can be of a specific <code>type</code> and/or have a specific <code>aspect</code> applied.
*
* <p>If no parameters are passed the immediate primary parent is returned.</p>
*
* @author Nick Smith
* @since 4.0
*/
public class AncestorNodeLocator extends AbstractNodeLocator
{
public static final String NAME = "ancestor";
public static final String TYPE_KEY = "type";
public static final String ASPECT_KEY = "aspect";
private NamespaceService namespaceService;
private NodeService nodeService;
/**
* {@inheritDoc}
*/
@Override
public NodeRef getNode(NodeRef source, Map<String, Serializable> params)
{
QName type = getQNameParam(TYPE_KEY, params);
QName aspect = getQNameParam(ASPECT_KEY, params);
NodeRef child = source;
while (true)
{
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(child);
if (parentAssoc == null)
{
break; // No matching ancestor found.
}
NodeRef parent = parentAssoc.getParentRef();
if (parent == null)
{
break; // No matching ancestor found.
}
if (typeMatches(type, parent) && aspectMatches(aspect, parent))
{
return parent; // Matching ancestor was found.
}
child = parent;
}
return null;
}
/**
* {@inheritDoc}
*/
@Override
public List<ParameterDefinition> getParameterDefinitions()
{
List<ParameterDefinition> paramDefs = new ArrayList<ParameterDefinition>(2);
paramDefs.add(new ParameterDefinitionImpl(TYPE_KEY, DataTypeDefinition.QNAME, false, "Type"));
paramDefs.add(new ParameterDefinitionImpl(ASPECT_KEY, DataTypeDefinition.QNAME, false, "Aspect"));
return paramDefs;
}
private boolean typeMatches(QName type, NodeRef parent)
{
return type == null || type.equals(nodeService.getType(parent));
}
private boolean aspectMatches(QName aspect, NodeRef parent)
{
return aspect == null || nodeService.getAspects(parent).contains(aspect);
}
private QName getQNameParam(String key, Map<String, Serializable> params)
{
String value = (String) params.get(key);
if (value != null)
{
return QName.createQName(value, namespaceService);
}
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getName()
{
return NAME;
}
/**
* @param nodeService the nodeService to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param namespaceService the namespaceService to set
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.repo.model.Repository;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Locates the Company Home {@link NodeRef}.
*
* @author Nick Smith
* @since 4.0
*/
public class CompanyHomeNodeLocator extends AbstractNodeLocator
{
public static final String NAME = "companyhome";
private Repository repoHelper;
/**
* {@inheritDoc}
*/
public NodeRef getNode(NodeRef source, Map<String, Serializable> params)
{
return repoHelper.getCompanyHome();
}
/**
* {@inheritDoc}
*/
@Override
public String getName()
{
return NAME;
}
/**
* @param repoHelper the repoHelper to set
*/
public void setRepositoryHelper(Repository repoHelper)
{
this.repoHelper = repoHelper;
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* A strategy for locating a {@link NodeRef} in the repository, given a source node and an arbitrary set of parameters.
*
* @author Nick Smith
* @since 4.0
*
*/
public interface NodeLocator
{
/**
* Finds a {@link NodeRef} given a starting {@link NodeRef} and a
* {@link Map} of parameters.
* Returns <code>null</code> if the specified node could not be found.
*
* @param sourceNode the starting point for locating a new node. The source node. Can be <code>null</code>.
* @param params an arbitrary {@link Map} of parameters.Can be <code>null</code>.
* @return the node to be found or <code>null</code>.
*/
NodeRef getNode(NodeRef source, Map<String, Serializable> params);
/**
* A list containing the parmameter defintions for this {@link NodeLocator}.
*
* @return a list of parameter definitions
*/
public List<ParameterDefinition> getParameterDefinitions();
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* This service is responsible for locating {@link NodeRef}s in the repository using {@link NodeLocator} strategies.
*
* @author Nick Smith
* @since 4.0
*
*/
public interface NodeLocatorService
{
/**
* Locates and returns a {@link NodeRef} using the specified {@link NodeLocator}.
*
* @param locatorName the name of the {@link NodeLocator} to use.
* @param source the source node. Can be <code>null</code>.
* @param params An arbitrary set of parameters. Can be <code>null</code>.
* @return the node to be found or <code>null</code>.
*/
NodeRef getNode(String locatorName, NodeRef source, Map<String, Serializable> params);
void register(String locatorName, NodeLocator locator);
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.ParameterCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Implementation of the {@link NodeLocatorService} which is responsible for locating a
* {@link NodeRef} using a named lookup strategy.
*
* @author Nick Smith
* @since 4.0
*/
public class NodeLocatorServiceImpl implements NodeLocatorService
{
/** Logger */
private static Log logger = LogFactory.getLog(NodeLocatorServiceImpl.class);
private final Map<String, NodeLocator> locators = new HashMap<String, NodeLocator>();
/**
* {@inheritDoc}
*/
@Override
public NodeRef getNode(String locatorName, NodeRef source, Map<String, Serializable> params)
{
NodeLocator locator = locators.get(locatorName);
if (locator == null)
{
String msg = "No NodeLocator is registered with name: " + locatorName;
throw new IllegalArgumentException(msg);
}
NodeRef node = locator.getNode(source, params);
if (logger.isDebugEnabled())
{
logger.debug("Node locator named '" + locatorName + "' found node: " + node);
}
return node;
}
/**
* {@inheritDoc}
*/
@Override
public void register(String locatorName, NodeLocator locator)
{
ParameterCheck.mandatory("locatorName", locatorName);
ParameterCheck.mandatory("locator", locator);
if (locators.containsKey(locatorName))
{
String msg = "Locator with name '" + locatorName + "' is already registered!";
throw new IllegalArgumentException(msg);
}
if (logger.isDebugEnabled())
{
logger.debug("Registered node locator: " + locatorName);
}
locators.put(locatorName, locator);
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import static org.mockito.Mockito.when;
import javax.annotation.Resource;
import org.alfresco.repo.model.Repository;
import org.alfresco.repo.site.SiteServiceInternal;
import org.alfresco.service.cmr.repository.NodeRef;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Nick Smith
* @since 4.0
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:alfresco/node-locator-context.xml", "classpath:test-nodeLocatorServiceImpl-context.xml"})
public class NodeLocatorServiceImplTest
{
private static final NodeRef companyHome = new NodeRef("alfresco://company/home");
private static final NodeRef sitesHome = new NodeRef("alfresco://sites/home");
@Resource
private NodeLocatorService nodeLocatorService;
@Autowired
private Repository repositoryHelper;
@Autowired
private SiteServiceInternal siteService;
@Test
public void testUnknownNodeLocator() throws Exception
{
try
{
nodeLocatorService.getNode(null, null, null);
fail("An exception should have been thrown!");
}
catch(IllegalArgumentException e)
{
//NOOP
}
try
{
nodeLocatorService.getNode("some unknown name", null, null);
fail("An exception should have been thrown!");
}
catch(IllegalArgumentException e)
{
//NOOP
}
}
@Test
public void testCompanyHomeNodeLocator() throws Exception
{
NodeRef result = nodeLocatorService.getNode(CompanyHomeNodeLocator.NAME, null, null);
assertEquals(companyHome, result);
}
@Test
public void testSitesHomeNodeLocator() throws Exception
{
NodeRef result = nodeLocatorService.getNode(SitesHomeNodeLocator.NAME, null, null);
assertEquals(sitesHome, result);
}
@Before
public void setUpClass()
{
when(repositoryHelper.getCompanyHome()).thenReturn(companyHome);
when(siteService.getSiteRoot()).thenReturn(sitesHome);
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* This {@link NodeLocator} returns the source node.
*
* @author Nick Smith
* @since 4.0
*/
public class SelfNodeLocator extends AbstractNodeLocator
{
public static final String NAME = "self";
/**
* {@inheritDoc}
*/
@Override
public NodeRef getNode(NodeRef source, Map<String, Serializable> params)
{
return source;
}
/**
* {@inheritDoc}
*/
@Override
public String getName()
{
return NAME;
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.repo.site.SiteServiceInternal;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Locates the Sites Home {@link NodeRef}.
*
* @author Nick Smith
* @since 4.0
*/
public class SitesHomeNodeLocator extends AbstractNodeLocator
{
public static final String NAME = "siteshome";
SiteServiceInternal siteService;
/**
* {@inheritDoc}
*/
@Override
public NodeRef getNode(NodeRef source, Map<String, Serializable> params)
{
return siteService.getSiteRoot();
}
/**
* {@inheritDoc}
*/
@Override
public String getName()
{
return NAME;
}
/**
* @param siteService the siteService to set
*/
public void setSiteService(SiteServiceInternal siteService)
{
this.siteService = siteService;
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.repo.model.Repository;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* This {@link NodeLocator} identifies and returns the node representing the current users home folder.
*
* @author Nick Smith
* @since 4.0
*/
public class UserHomeNodeLocator extends AbstractNodeLocator
{
public static final String NAME = "userhome";
private Repository repositoryHelper;
/**
* {@inheritDoc}
*/
@Override
public NodeRef getNode(NodeRef source, Map<String, Serializable> params)
{
NodeRef person = repositoryHelper.getPerson();
if (person != null)
{
return repositoryHelper.getUserHome(person);
}
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getName()
{
return NAME;
}
/**
* @param repositoryHelper the repositoryHelper to set
*/
public void setRepositoryHelper(Repository repositoryHelper)
{
this.repositoryHelper = repositoryHelper;
}
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.nodelocator;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.util.ParameterCheck;
/**
* This {@link NodeLocator} identifies a node from an XPath provided via the <code>xpath</code> parameter.
*
* @author Nick Smith
* @since 4.0
*/
public class XPathNodeLocator extends AbstractNodeLocator
{
public static final String NAME = "xpath";
public static final String QUERY_KEY = "query";
public static final String STORE_TYPE_KEY = "store_type";
public static final String STORE_ID_KEY = "store_id";
private SearchService searchService;
private StoreRef defaultStore;
/**
* {@inheritDoc}
*/
@Override
public NodeRef getNode(NodeRef source, Map<String, Serializable> params)
{
String query = (String) params.get(QUERY_KEY);
ParameterCheck.mandatoryString("query", query);
StoreRef store = null;
if (source!=null)
{
store = source.getStoreRef();
}
else
{
String storeType = (String) params.get(STORE_TYPE_KEY);
String storeId = (String) params.get(STORE_ID_KEY);
if (storeType != null && storeId != null)
{
store = new StoreRef(storeType, storeId);
}
else store = defaultStore;
}
try
{
ResultSet results = searchService.query(store, SearchService.LANGUAGE_XPATH, query);
List<NodeRef> nodes = results.getNodeRefs();
if (nodes.size() > 0)
{
return nodes.get(0);
}
}
catch (Exception e)
{
String msg = "Error while searching XPath. StoreRef: " + store + " Query: " + query;
throw new AlfrescoRuntimeException(msg, e);
}
return null;
}
/**
* {@inheritDoc}
*/
@Override
public List<ParameterDefinition> getParameterDefinitions()
{
List<ParameterDefinition> paramDefs = new ArrayList<ParameterDefinition>(2);
paramDefs.add(new ParameterDefinitionImpl(QUERY_KEY, DataTypeDefinition.TEXT, true, "Query"));
paramDefs.add(new ParameterDefinitionImpl(STORE_TYPE_KEY, DataTypeDefinition.TEXT, false, "Store Type"));
paramDefs.add(new ParameterDefinitionImpl(STORE_ID_KEY, DataTypeDefinition.TEXT, false, "Store Id"));
return paramDefs;
}
/**
* {@inheritDoc}
*/
@Override
public String getName()
{
return NAME;
}
/**
* @param searchService the searchService to set
*/
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
/**
* @param defaultStore the defaultStore to set
*/
public void setDefaultStore(String defaultStoreStr)
{
this.defaultStore = new StoreRef(defaultStoreStr);
}
}