use of org.alfresco.service.namespace.NamespaceService in project alfresco-remote-api by Alfresco.
the class PutMethodTest method setUp.
@Before
public void setUp() throws Exception {
searchService = ctx.getBean("SearchService", SearchService.class);
fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
nodeService = ctx.getBean("NodeService", NodeService.class);
transactionService = ctx.getBean("transactionService", TransactionService.class);
webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
authenticationService = ctx.getBean("authenticationService", MutableAuthenticationService.class);
personService = ctx.getBean("PersonService", PersonService.class);
lockService = ctx.getBean("LockService", LockService.class);
contentService = ctx.getBean("contentService", ContentService.class);
checkOutCheckInService = ctx.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
permissionService = ctx.getBean("PermissionService", PermissionService.class);
namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
actionService = ctx.getBean("ActionService", ActionService.class);
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
companyHomeNodeRef = repositoryHelper.getCompanyHome();
txn = transactionService.getUserTransaction();
txn.begin();
createUser(USER1_NAME);
createUser(USER2_NAME);
InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
InputStream davLockInfoAdminIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_ADMIN);
InputStream davLockInfoUser2IS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_USER2);
testDataFile = IOUtils.toByteArray(testDataIS);
davLockInfoAdminFile = IOUtils.toByteArray(davLockInfoAdminIS);
davLockInfoUser2File = IOUtils.toByteArray(davLockInfoUser2IS);
testDataIS.close();
davLockInfoAdminIS.close();
davLockInfoUser2IS.close();
// Create a test file with versionable aspect and content
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
versionableDocName = "doc-" + GUID.generate();
properties.put(ContentModel.PROP_NAME, versionableDocName);
versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef();
contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null);
txn.commit();
txn = transactionService.getUserTransaction();
txn.begin();
}
use of org.alfresco.service.namespace.NamespaceService in project acs-community-packaging by Alfresco.
the class TemplateSupportBean method selectDictionaryNodes.
/**
* @param fc FacesContext
* @param xpath XPath to the nodes to select
* @param noSelectionLabel Label to add to the list if no items are found in the search
* @param mimetype Optional mimetype of items to add, will not add to list if mimetype does not match
*
* @return List of SelectItem wrapper objects for the nodes found at the XPath
*/
private List<SelectItem> selectDictionaryNodes(FacesContext fc, String xpath, String noSelectionLabel, String mimetype) {
List<SelectItem> wrappers = null;
try {
NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
NamespaceService resolver = Repository.getServiceRegistry(fc).getNamespaceService();
List<NodeRef> results = this.getSearchService().selectNodes(rootNodeRef, xpath, null, resolver, false);
wrappers = new ArrayList<SelectItem>(results.size() + 1);
if (results.size() != 0) {
DictionaryService dd = Repository.getServiceRegistry(fc).getDictionaryService();
for (NodeRef ref : results) {
if (this.getNodeService().exists(ref) == true) {
Node childNode = new Node(ref);
ContentData content = (ContentData) childNode.getProperties().get(ContentModel.PROP_CONTENT);
if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT) && (mimetype == null || mimetype.equals(content.getMimetype()))) {
wrappers.add(new SelectItem(childNode.getId(), childNode.getName()));
}
}
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(wrappers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
} catch (AccessDeniedException accessErr) {
// ignore the result if we cannot access the root
}
// add an entry (at the start) to instruct the user to select an item
if (wrappers == null) {
wrappers = new ArrayList<SelectItem>(1);
}
wrappers.add(0, new SelectItem(NO_SELECTION, Application.getMessage(FacesContext.getCurrentInstance(), noSelectionLabel)));
return wrappers;
}
use of org.alfresco.service.namespace.NamespaceService in project acs-community-packaging by Alfresco.
the class SearchContext method fromXML.
/**
* Restore a SearchContext from an XML definition
*
* @param xml XML format SearchContext @see #toXML()
*/
public SearchContext fromXML(String xml) {
try {
NamespaceService ns = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNamespaceService();
// get the root element
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(xml));
Element rootElement = document.getRootElement();
Element textElement = rootElement.element(ELEMENT_TEXT);
if (textElement != null) {
this.text = textElement.getText();
}
Element modeElement = rootElement.element(ELEMENT_MODE);
if (modeElement != null) {
this.mode = Integer.parseInt(modeElement.getText());
}
Element locationElement = rootElement.element(ELEMENT_LOCATION);
if (locationElement != null) {
this.location = locationElement.getText();
}
Element categoriesElement = rootElement.element(ELEMENT_CATEGORIES);
if (categoriesElement != null) {
List<String> categories = new ArrayList<String>(4);
for (Iterator i = categoriesElement.elementIterator(ELEMENT_CATEGORY); i.hasNext(); ) /**/
{
Element categoryElement = (Element) i.next();
categories.add(categoryElement.getText());
}
this.categories = categories.toArray(this.categories);
}
Element contentTypeElement = rootElement.element(ELEMENT_CONTENT_TYPE);
if (contentTypeElement != null) {
this.contentType = contentTypeElement.getText();
}
Element folderTypeElement = rootElement.element(ELEMENT_FOLDER_TYPE);
if (folderTypeElement != null) {
this.folderType = folderTypeElement.getText();
}
Element mimetypeElement = rootElement.element(ELEMENT_MIMETYPE);
if (mimetypeElement != null) {
this.mimeType = mimetypeElement.getText();
}
Element attributesElement = rootElement.element(ELEMENT_ATTRIBUTES);
if (attributesElement != null) {
for (Iterator i = attributesElement.elementIterator(ELEMENT_ATTRIBUTE); i.hasNext(); ) /**/
{
Element attrElement = (Element) i.next();
QName qname = QName.createQName(attrElement.attributeValue(ELEMENT_NAME), ns);
addAttributeQuery(qname, attrElement.getText());
}
}
Element rangesElement = rootElement.element(ELEMENT_RANGES);
if (rangesElement != null) {
for (Iterator i = rangesElement.elementIterator(ELEMENT_RANGE); i.hasNext(); ) /**/
{
Element rangeElement = (Element) i.next();
Element lowerElement = rangeElement.element(ELEMENT_LOWER);
Element upperElement = rangeElement.element(ELEMENT_UPPER);
Element incElement = rangeElement.element(ELEMENT_INCLUSIVE);
if (lowerElement != null && upperElement != null && incElement != null) {
QName qname = QName.createQName(rangeElement.attributeValue(ELEMENT_NAME), ns);
addRangeQuery(qname, lowerElement.getText(), upperElement.getText(), Boolean.parseBoolean(incElement.getText()));
}
}
}
Element valuesElement = rootElement.element(ELEMENT_FIXED_VALUES);
if (valuesElement != null) {
for (Iterator i = valuesElement.elementIterator(ELEMENT_VALUE); i.hasNext(); ) /**/
{
Element valueElement = (Element) i.next();
QName qname = QName.createQName(valueElement.attributeValue(ELEMENT_NAME), ns);
addFixedValueQuery(qname, valueElement.getText());
}
}
} catch (Throwable err) {
throw new AlfrescoRuntimeException("Failed to import SearchContext from XML.", err);
}
return this;
}
use of org.alfresco.service.namespace.NamespaceService in project acs-community-packaging by Alfresco.
the class SearchContext method getPathFromSpaceRef.
/**
* Generate a search XPATH pointing to the specified node, optionally return an XPATH
* that includes the child nodes.
*
* @param ref Of the node to generate path too
* @param children Whether to include children of the node
*
* @return the path
*/
public static String getPathFromSpaceRef(NodeRef ref, boolean children) {
FacesContext context = FacesContext.getCurrentInstance();
Path path = Repository.getServiceRegistry(context).getNodeService().getPath(ref);
NamespaceService ns = Repository.getServiceRegistry(context).getNamespaceService();
StringBuilder buf = new StringBuilder(64);
for (int i = 0; i < path.size(); i++) {
String elementString = "";
Path.Element element = path.get(i);
if (element instanceof Path.ChildAssocElement) {
ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
if (elementRef.getParentRef() != null) {
Collection<String> prefixes = ns.getPrefixes(elementRef.getQName().getNamespaceURI());
if (prefixes.size() > 0) {
elementString = '/' + (String) prefixes.iterator().next() + ':' + ISO9075.encode(elementRef.getQName().getLocalName());
}
}
}
buf.append(elementString);
}
if (children == true) {
// append syntax to get all children of the path
buf.append("//*");
} else {
// append syntax to just represent the path, not the children
buf.append("/*");
}
return buf.toString();
}
use of org.alfresco.service.namespace.NamespaceService in project acs-community-packaging by Alfresco.
the class ContextListener method contextInitialized.
/**
* @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
*/
public void contextInitialized(ServletContextEvent event) {
// make sure that the spaces store in the repository exists
this.servletContext = event.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
// If no context has been initialised, exit silently so config changes can be made
if (ctx == null) {
return;
}
ServiceRegistry registry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
TransactionService transactionService = registry.getTransactionService();
NodeService nodeService = registry.getNodeService();
SearchService searchService = registry.getSearchService();
NamespaceService namespaceService = registry.getNamespaceService();
AuthenticationContext authenticationContext = (AuthenticationContext) ctx.getBean("authenticationContext");
// repo bootstrap code for our client
UserTransaction tx = null;
NodeRef companySpaceNodeRef = null;
try {
tx = transactionService.getUserTransaction();
tx.begin();
authenticationContext.setSystemUserAsCurrentUser();
// get and setup the initial store ref and root path from config
StoreRef storeRef = Repository.getStoreRef(servletContext);
// get root path
String rootPath = Application.getRootPath(servletContext);
// Extract company space id and store it in the Application object
companySpaceNodeRef = Repository.getCompanyRoot(nodeService, searchService, namespaceService, storeRef, rootPath);
Application.setCompanyRootId(companySpaceNodeRef.getId());
// commit the transaction
tx.commit();
} catch (Throwable e) {
// rollback the transaction
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception ex) {
}
logger.error("Failed to initialise ", e);
throw new AlfrescoRuntimeException("Failed to initialise ", e);
} finally {
try {
authenticationContext.clearCurrentSecurityContext();
} catch (Exception ex) {
}
}
}
Aggregations