Java Code Examples for org.alfresco.service.namespace.QName#createValidLocalName()
The following examples show how to use
org.alfresco.service.namespace.QName#createValidLocalName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageManager.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private void addPackageItems(final NodeRef packageRef) { for (NodeRef item : addItems) { String name = (String) nodeService.getProperty(item, ContentModel.PROP_NAME); if (name == null) { name = GUID.generate(); } String localName = QName.createValidLocalName(name); QName qName = QName.createQName(CM_URL, localName); behaviourFilter.disableBehaviour(item, ContentModel.ASPECT_AUDITABLE); try { nodeService.addChild(packageRef, item, PCKG_CONTAINS, qName); } finally { behaviourFilter.enableBehaviour(item, ContentModel.ASPECT_AUDITABLE); } } }
Example 2
Source File: TransitionSimpleWorkflowActionExecuterTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** Test for MNT-14730*/ public void testExecutionApproveWhenDestinationSameAsSource() { addWorkflowAspect(node, sourceFolder, Boolean.FALSE, Boolean.FALSE); assertTrue(nodeService.hasAspect(node, ApplicationModel.ASPECT_SIMPLE_WORKFLOW)); NodeRef pParent = nodeService.getPrimaryParent(node).getParentRef(); assertEquals(sourceFolder, pParent); ActionImpl action = new ActionImpl(null, ID, "accept-simpleworkflow", null); acceptExecuter.execute(action, node); String copyName = QName.createValidLocalName("Copy of my node.txt"); NodeRef nodeRef = nodeService.getChildByName(sourceFolder, ContentModel.ASSOC_CONTAINS, copyName); assertNotNull(nodeRef); }
Example 3
Source File: TransitionSimpleWorkflowActionExecuterTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** Test for MNT-14730*/ public void testExecutionRejectWhenDestinationSameAsSource() { addWorkflowAspect(node, sourceFolder, Boolean.FALSE, Boolean.FALSE); assertTrue(nodeService.hasAspect(node, ApplicationModel.ASPECT_SIMPLE_WORKFLOW)); NodeRef pParent = nodeService.getPrimaryParent(node).getParentRef(); assertEquals(sourceFolder, pParent); assertEquals(0, nodeService.getChildAssocs(destinationFolder).size()); ActionImpl action = new ActionImpl(null, ID, "reject-simpleworkflow", null); rejectExecuter.execute(action, node); assertFalse(nodeService.hasAspect(node, ApplicationModel.ASPECT_SIMPLE_WORKFLOW)); pParent = nodeService.getPrimaryParent(node).getParentRef(); assertEquals(sourceFolder, pParent); assertEquals(0, nodeService.getChildAssocs(destinationFolder).size()); String copyName = QName.createValidLocalName("Copy of my node.txt"); NodeRef nodeRef = nodeService.getChildByName(sourceFolder, ContentModel.ASSOC_CONTAINS, copyName); assertNotNull(nodeRef); }
Example 4
Source File: LuceneCategoryServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public ChildAssociationRef getCategory(NodeRef parent, QName aspectName, String name) { String uri = nodeService.getPrimaryParent(parent).getQName().getNamespaceURI(); String validLocalName = QName.createValidLocalName(name); Collection<ChildAssociationRef> assocs = nodeService.getChildAssocs(parent, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(uri, validLocalName), false); if (assocs.isEmpty()) { return null; } return assocs.iterator().next(); }
Example 5
Source File: LuceneCategoryServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private ChildAssociationRef createCategoryInternal(NodeRef parent, String name) { if (!nodeService.exists(parent)) { throw new AlfrescoRuntimeException("Missing category?"); } String uri = nodeService.getPrimaryParent(parent).getQName().getNamespaceURI(); String validLocalName = QName.createValidLocalName(name); ChildAssociationRef newCategory = publicNodeService.createNode(parent, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(uri, validLocalName), ContentModel.TYPE_CATEGORY); publicNodeService.setProperty(newCategory.getChildRef(), ContentModel.PROP_NAME, name); return newCategory; }
Example 6
Source File: ImporterComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 String * @return String */ private String createValidPath(String path) { StringBuffer validPath = new StringBuffer(path.length()); String[] segments = StringUtils.delimitedListToStringArray(path, "/"); for (int i = 0; i < segments.length; i++) { 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 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)) { validPath.append("/"); } } return validPath.toString(); }
Example 7
Source File: FileImporterImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private NodeRef createDirectory(NodeRef parentNodeRef, String name, String path) { // check the parent node's type to determine which association to use QName assocTypeQName = getAssocTypeQName(parentNodeRef); if (assocTypeQName == null) { throw new IllegalArgumentException( "Unable to create directory. " + "Parent type is inappropriate: " + nodeService.getType(parentNodeRef)); } String qname = QName.createValidLocalName(name); ChildAssociationRef assocRef = this.nodeService.createNode( parentNodeRef, assocTypeQName, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname), ContentModel.TYPE_FOLDER); NodeRef nodeRef = assocRef.getChildRef(); // set the name property on the node this.nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, name); if (logger.isDebugEnabled()) logger.debug("Created folder node with name: " + name); // apply the uifacets aspect - icon, title and description props Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(5); uiFacetsProps.put(ApplicationModel.PROP_ICON, "space-icon-default"); uiFacetsProps.put(ContentModel.PROP_TITLE, name); uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, path); this.nodeService.addAspect(nodeRef, ApplicationModel.ASPECT_UIFACETS, uiFacetsProps); if (logger.isDebugEnabled()) logger.debug("Added uifacets aspect with properties: " + uiFacetsProps); return nodeRef; }
Example 8
Source File: ImporterComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Link an existing Node * * @param context node to link in * @return node reference of child linked in */ private NodeRef linkNode(ImportNode context) { ImportParent parentContext = context.getParentContext(); NodeRef parentRef = parentContext.getParentRef(); // determine the node reference to link to String uuid = context.getUUID(); if (uuid == null || uuid.length() == 0) { throw new ImporterException("Node reference does not specify a reference to follow."); } NodeRef referencedRef = new NodeRef(rootRef.getStoreRef(), uuid); // Note: do not link references that are defined in the root of the import if (!parentRef.equals(getRootRef())) { // determine child assoc type QName assocType = getAssocType(context); AssociationDefinition assocDef = dictionaryService.getAssociation(assocType); if (assocDef.isChild()) { // determine child name QName childQName = getChildName(context); if (childQName == null) { String name = (String)nodeService.getProperty(referencedRef, ContentModel.PROP_NAME); if (name == null || name.length() == 0) { throw new ImporterException("Cannot determine node reference child name"); } String localName = QName.createValidLocalName(name); childQName = QName.createQName(assocType.getNamespaceURI(), localName); } // create the secondary link nodeService.addChild(parentRef, referencedRef, assocType, childQName); reportNodeLinked(referencedRef, parentRef, assocType, childQName); } else { nodeService.createAssociation(parentRef, referencedRef, assocType); reportNodeLinked(parentRef, referencedRef, assocType, null); } } // second, perform any specified udpates to the node updateStrategy.importNode(context); return referencedRef; }
Example 9
Source File: ImporterComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Get the child name to import node under * * @param context the node * @return the child name */ private QName getChildName(ImportNode context) { QName assocType = getAssocType(context); QName childQName = null; // Determine child name String childName = context.getChildName(); if (childName != null) { childName = bindPlaceHolder(childName, binding); // <Fix for ETHREEOH-2299> if (ContentModel.TYPE_PERSON.equals(context.getTypeDefinition().getName()) && assocType.equals(ContentModel.ASSOC_CHILDREN)) { childName = childName.toLowerCase(); } // </Fix for ETHREEOH-2299> String[] qnameComponents = QName.splitPrefixedQName(childName); childQName = QName.createQName(qnameComponents[0], QName.createValidLocalName(qnameComponents[1]), namespaceService); } else { Map<QName, Serializable> typeProperties = context.getProperties(); Serializable nameValue = typeProperties.get(ContentModel.PROP_NAME); if(nameValue != null && !String.class.isAssignableFrom(nameValue.getClass())) { throw new ImporterException("Unable to use childName property: "+ ContentModel.PROP_NAME + " is not a string"); } String name = (String)nameValue; if (name != null && name.length() > 0) { name = bindPlaceHolder(name, binding); String localName = QName.createValidLocalName(name); childQName = QName.createQName(assocType.getNamespaceURI(), localName); } } return childQName; }
Example 10
Source File: ExporterActionExecuter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Creates the ZIP file node in the repository for the export * * @param ruleAction The rule being executed * @return The NodeRef of the newly created ZIP file */ private NodeRef createExportZip(Action ruleAction, NodeRef actionedUponNodeRef) { // create a node in the repository to represent the export package NodeRef exportDest = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER); String packageName = (String)ruleAction.getParameterValue(PARAM_PACKAGE_NAME); // add the default Alfresco content package extension if an extension hasn't been given if (!packageName.endsWith("." + ACPExportPackageHandler.ACP_EXTENSION)) { packageName += (packageName.charAt(packageName.length() -1) == '.') ? ACPExportPackageHandler.ACP_EXTENSION : "." + ACPExportPackageHandler.ACP_EXTENSION; } // set the name for the new node Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(1); contentProps.put(ContentModel.PROP_NAME, packageName); // create the node to represent the zip file String assocName = QName.createValidLocalName(packageName); ChildAssociationRef assocRef = this.nodeService.createNode( exportDest, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, assocName), ContentModel.TYPE_CONTENT, contentProps); NodeRef zipNodeRef = assocRef.getChildRef(); // build a description string to be set on the node representing the content package String desc = ""; String storeRef = (String)ruleAction.getParameterValue(PARAM_STORE); NodeRef rootNode = this.nodeService.getRootNode(new StoreRef(storeRef)); if (rootNode.equals(actionedUponNodeRef)) { desc = I18NUtil.getMessage("export.root.package.description"); } else { String spaceName = (String)this.nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_NAME); String pattern = I18NUtil.getMessage("export.package.description"); if (pattern != null && spaceName != null) { desc = MessageFormat.format(pattern, spaceName); } } // apply the titled aspect to behave in the web client Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f); titledProps.put(ContentModel.PROP_TITLE, packageName); titledProps.put(ContentModel.PROP_DESCRIPTION, desc); this.nodeService.addAspect(zipNodeRef, ContentModel.ASPECT_TITLED, titledProps); return zipNodeRef; }