/** * Call-backs for start of Namespace scope */ private void walkStartNamespaces(ExporterCrawlerParameters parameters, Exporter exporter) { Collection<String> prefixes = namespaceService.getPrefixes(); for (String prefix : prefixes) { if (!prefix.equals("xml")) { String uri = namespaceService.getNamespaceURI(prefix); exporter.startNamespace(prefix, uri); } } }
/** * Helper to create Qualified name from current xml element * * @param xpp XmlPullParser * @return QName */ private QName getName(XmlPullParser xpp) { // Ensure namespace is valid String uri = xpp.getNamespace(); if (namespaceService.getURIs().contains(uri) == false) { throw new ImporterException("Namespace URI " + uri + " has not been defined in the Repository dictionary"); } // Construct name String name = xpp.getName(); return QName.createQName(uri, name); }
private void mockNamespaceService() { namespaceService.registerNamespace(NamespaceService.BPM_MODEL_PREFIX, NamespaceService.BPM_MODEL_1_0_URI); namespaceService.registerNamespace(NamespaceService.DEFAULT_PREFIX, NamespaceService.DEFAULT_URI); namespaceService.registerNamespace(NamespaceService.WORKFLOW_MODEL_PREFIX, NamespaceService.WORKFLOW_MODEL_1_0_URI); namespaceService.registerNamespace("test", "http://test"); }
/** * Call-backs for end of Namespace scope */ private void walkEndNamespaces(ExporterCrawlerParameters parameters, Exporter exporter) { Collection<String> prefixes = namespaceService.getPrefixes(); for (String prefix : prefixes) { if (!prefix.equals("xml")) { exporter.endNamespace(prefix); } } }
public NodeRef execute() throws Exception { // Check that the namespace is in the namespace service String uri = namespaceService.getNamespaceURI("test2"); assertNotNull(uri); Collection<ConstraintDefinition> constraints = dictionaryService.getConstraints(TEST_MODEL_TWO, true); assertEquals(1, constraints.size()); assertEquals("test2:con1", constraints.iterator().next().getName().getPrefixString()); // Update model NodeRef workingCopy = DictionaryModelTypeTest.this.cociService.checkout(modelNode); ContentWriter contentWriter2 = DictionaryModelTypeTest.this.contentService.getWriter(workingCopy, ContentModel.PROP_CONTENT, true); contentWriter2.putContent(MODEL_TWO_INVALID_XML); return workingCopy; } });
/** * Call-backs for end of Namespace scope */ private void walkEndNamespaces(ExporterCrawlerParameters parameters, Exporter exporter) { Collection<String> prefixes = namespaceService.getPrefixes(); for (String prefix : prefixes) { if (!prefix.equals("xml")) { exporter.endNamespace(prefix); } } }
public NodeRef execute() throws Exception { // Check that the namespace is in the namespace service String uri = namespaceService.getNamespaceURI("test1"); assertNotNull(uri); // Create a model node PropertyMap properties = new PropertyMap(1); properties.put(QName.createQName("http://www.alfresco.org/test/testmodel1/1.0", "prop2"), "false"); // boolean NodeRef node = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.ALFRESCO_URI, "node1"), QName.createQName("http://www.alfresco.org/test/testmodel1/1.0", "base"), properties).getChildRef(); assertNotNull(node); return node; } }, false, true);
/** * Call-backs for start of Namespace scope */ private void walkStartNamespaces(ExporterCrawlerParameters parameters, Exporter exporter) { Collection<String> prefixes = namespaceService.getPrefixes(); for (String prefix : prefixes) { if (!prefix.equals("xml")) { String uri = namespaceService.getNamespaceURI(prefix); exporter.startNamespace(prefix, uri); } } }
/** * Convert a qname to a string - either full or short prefixed named. * * @param qname QName * @param isShortName boolean * @return qname string. */ private String nameToString(final QName qname, final boolean isShortName) { String result; if (isShortName) { final Map<String, String> cache = namespacePrefixCache.get(); String prefix = cache.get(qname.getNamespaceURI()); if (prefix == null) { // first request for this namespace prefix, get and cache result Collection<String> prefixes = this.namespaceService.getPrefixes(qname.getNamespaceURI()); prefix = prefixes.size() != 0 ? prefixes.iterator().next() : ""; cache.put(qname.getNamespaceURI(), prefix); } result = prefix + QName.NAMESPACE_PREFIX + qname.getLocalName(); } else { result = qname.toString(); } return result; }
public NodeRef execute() throws Exception String uri = namespaceService.getNamespaceURI("test1"); assertNotNull(uri); String uri2 = DictionaryModelTypeTest.this.namespaceService.getNamespaceURI("test1"); assertEquals(uri2, "http://www.alfresco.org/test/testmodel1/1.0");
/** * Helper to create Qualified name from current xml element * * @param xpp XmlPullParser * @return QName */ private QName getName(XmlPullParser xpp) { // Ensure namespace is valid String uri = xpp.getNamespace(); if (namespaceService.getURIs().contains(uri) == false) { throw new ImporterException("Namespace URI " + uri + " has not been defined in the Repository dictionary"); } // Construct name String name = xpp.getName(); return QName.createQName(uri, name); }
@Before public void setUp() throws Exception { namespaceService = mock(NamespaceService.class); Collection<String> cmAlways = new ArrayList<String>(); cmAlways.add("cm"); when(namespaceService.getPrefixes(anyString())).thenReturn(cmAlways); when(namespaceService.getNamespaceURI(anyString())).thenReturn("cm"); nodeService = mock(NodeService.class); Path rootPath = newPath(null, "/"); Path homeFolderPath = newPath(rootPath, "cm:homeFolder"); folderPath1 = newPath(homeFolderPath, "cm:folder1"); folderPath2 = newPath(homeFolderPath, "cm:folder2"); folder1 = newFolder(folderPath1); folder2 = newFolder(folderPath2); content1 = newContent(folderPath1, "cm:content1"); nodeInfoFactory = new NodeInfoFactory(nodeService, namespaceService); nodeChange = new NodeChange(nodeInfoFactory, namespaceService, content1); }
/** * Convert a qname to a string - either full or short prefixed named. * * @param qname QName * @param isShortName boolean * @return qname string. */ private String nameToString(final QName qname, final boolean isShortName) { String result; if (isShortName) { final Map<String, String> cache = namespacePrefixCache.get(); String prefix = cache.get(qname.getNamespaceURI()); if (prefix == null) { // first request for this namespace prefix, get and cache result Collection<String> prefixes = this.namespaceService.getPrefixes(qname.getNamespaceURI()); prefix = prefixes.size() != 0 ? prefixes.iterator().next() : ""; cache.put(qname.getNamespaceURI(), prefix); } result = prefix + QName.NAMESPACE_PREFIX + qname.getLocalName(); } else { result = qname.toString(); } return result; }
String uri = this.namespaceService.getNamespaceURI("test2"); assertNull(uri);
/** * {@inheritDoc} */ public void addProperty(RegistryKey key, Serializable value) { if (key.getProperty() == null) { throw new IllegalArgumentException("Registry values must be added using paths that contain property names: " + key); } // Check the namespace being used in the key String namespaceUri = key.getNamespaceUri(); if (!namespaceService.getURIs().contains(namespaceUri)) { throw new NamespaceException("Unable to add a registry value with an unregistered namespace: " + namespaceUri); } // Get the path, with creation support Pair<NodeRef, QName> keyPair = getPath(key, true); // We know that the node exists, so just set the value nodeService.setProperty(keyPair.getFirst(), keyPair.getSecond(), value); // Done if (logger.isDebugEnabled()) { logger.debug("Added value to registry: \n" + " Key: " + key + "\n" + " Value: " + value); } }
prefixes.add(NamespaceService.CONTENT_MODEL_PREFIX); when(namespaceService.getPrefixes(NamespaceService.CONTENT_MODEL_1_0_URI)) .thenReturn(prefixes); when(namespaceService.getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX)) .thenReturn(NamespaceService.CONTENT_MODEL_1_0_URI); when(contextFactory.getDefaultIntialDirContext()).thenReturn(initialDirContext);
/** * @return The array of aspects applied to this node as short prefix qname strings */ public Scriptable getAspectsShort() { final NamespaceService ns = this.services.getNamespaceService(); final Map<String, String> cache = new HashMap<String, String>(); final Set<QName> aspects = getAspectsSet(); final Object[] result = new Object[aspects.size()]; int count = 0; for (final QName qname : aspects) { 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); } result[count++] = prefix + QName.NAMESPACE_PREFIX + qname.getLocalName(); } return Context.getCurrentContext().newArray(this.scope, result); }
String uri = this.namespaceService.getNamespaceURI("test3"); assertNull(uri);
/** * {@inheritDoc} */ public void addProperty(RegistryKey key, Serializable value) { if (key.getProperty() == null) { throw new IllegalArgumentException("Registry values must be added using paths that contain property names: " + key); } // Check the namespace being used in the key String namespaceUri = key.getNamespaceUri(); if (!namespaceService.getURIs().contains(namespaceUri)) { throw new NamespaceException("Unable to add a registry value with an unregistered namespace: " + namespaceUri); } // Get the path, with creation support Pair<NodeRef, QName> keyPair = getPath(key, true); // We know that the node exists, so just set the value nodeService.setProperty(keyPair.getFirst(), keyPair.getSecond(), value); // Done if (logger.isDebugEnabled()) { logger.debug("Added value to registry: \n" + " Key: " + key + "\n" + " Value: " + value); } }
/** * @return The array of aspects applied to this node as short prefix qname strings */ public Scriptable getAspectsShort() { final NamespaceService ns = this.services.getNamespaceService(); final Map<String, String> cache = new HashMap<String, String>(); final Set<QName> aspects = getAspectsSet(); final Object[] result = new Object[aspects.size()]; int count = 0; for (final QName qname : aspects) { 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); } result[count++] = prefix + QName.NAMESPACE_PREFIX + qname.getLocalName(); } return Context.getCurrentContext().newArray(this.scope, result); }