Files
alfresco-community-repo/source/java/org/alfresco/repo/dictionary/RepositoryLocation.java
Alan Davis 91eb2644ad Merged 5.2.N (5.2.1) to HEAD (5.2)
125781 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
      125603 rmunteanu: 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/HEAD/root@127808 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2016-06-03 16:40:56 +00:00

188 lines
5.0 KiB
Java

package org.alfresco.repo.dictionary;
import org.alfresco.repo.search.SearcherException;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.QName;
/**
* Repository location object - defines a location in the repository (can also be used for classpath location)
*/
public class RepositoryLocation
{
/** Store protocol */
private String storeProtocol = StoreRef.PROTOCOL_WORKSPACE; // default
/** Store identifier */
private String storeId = "SpacesStore"; // default
/** Path */
private String path = ""; // default
/** Search Language */
private String queryLanguage = "xpath"; // default
public static final String LANGUAGE_PATH = "path"; // lookup directly using node (prefix qname) path
public static final String LANGUAGE_CLASSPATH = "classpath";
/**
*/
public RepositoryLocation()
{
}
/**
* Constructor
*
* @param storeRef the store reference (e.g. 'workspace://SpacesStore' )
* @param path the path (e.g. '/app:company_home/app:dictionary/app:models' )
* @param queryLanguage the query language (e.g. 'xpath' or 'lucence')
*/
public RepositoryLocation(StoreRef storeRef, String path, String queryLanguage)
{
this.storeProtocol = storeRef.getProtocol();
this.storeId = storeRef.getIdentifier();
this.path = path;
setQueryLanguage(queryLanguage);
}
/**
* Set the store protocol
*
* @param storeProtocol the store protocol
*/
public void setStoreProtocol(String storeProtocol)
{
this.storeProtocol = storeProtocol;
}
/**
* Set the store identifier
*
* @param storeId the store identifier
*/
public void setStoreId(String storeId)
{
this.storeId = storeId;
}
/**
* Set the path
*
* Example path: /app:company_home/app:dictionary/app:models
*
* @param path the path
*/
public void setPath(String path)
{
this.path = path;
}
/**
* Set the query language
*
* @param queryLanguage the search language
*/
public void setQueryLanguage(String queryLanguage)
{
if (queryLanguage.equals(SearchService.LANGUAGE_LUCENE) ||
queryLanguage.equals(SearchService.LANGUAGE_XPATH) ||
queryLanguage.equals(LANGUAGE_PATH) ||
queryLanguage.equals(LANGUAGE_CLASSPATH))
{
this.queryLanguage = queryLanguage;
}
else
{
throw new SearcherException("Unknown query language: " + queryLanguage);
}
}
/**
* Get the store reference (note: should be ignored for classpath location)
*
* @return the store reference
*/
public StoreRef getStoreRef()
{
return new StoreRef(this.storeProtocol, this.storeId);
}
/**
* Get the path
*
* @return the path
*/
public String getPath()
{
return this.path;
}
/**
* Get the query language
*
* @return the query language
*/
public String getQueryLanguage()
{
return this.queryLanguage;
}
/**
* Get the Lucene query statement for models, based on the path
*
* @return the Lucene query statement
*/
public String getLuceneQueryStatement(QName contentModelType)
{
String result = "+TYPE:\"" + contentModelType.toString() + "\"";
if ((this.path != null) && (! this.path.equals("")))
{
result += " +PATH:\"" + this.path + "\"";
}
return result;
}
/**
* Get the XPath query statement for models, based on the path
*
* @return the XPath query statement
*/
public String getXPathQueryStatement(QName prefixResolvedContentModelType)
{
String result = "/*[subtypeOf('" + prefixResolvedContentModelType.toPrefixString() + "')]"; // immediate children only
if ((this.path != null) && (! this.path.equals("")))
{
result = this.path + result;
}
return result;
}
public String[] getPathElements()
{
if ((this.path != null) && (! this.path.equals("")))
{
String pathToSplit = this.path;
while (pathToSplit.startsWith("/"))
{
pathToSplit = pathToSplit.substring(1);
}
while (pathToSplit.endsWith("/"))
{
pathToSplit = pathToSplit.substring(0, pathToSplit.length() - 1);
}
String[] pathElements = pathToSplit.split("/");
return pathElements;
}
else
{
return new String[0];
}
}
}