org.alfresco.service.namespace.NamespacePrefixResolver Java Examples
The following examples show how to use
org.alfresco.service.namespace.NamespacePrefixResolver.
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: IgnoreConstraint.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private SearchParameters applyFTSDecorations(SearchParameters searchParameters, NamespacePrefixResolver nspResolver) { SearchParameters constrainedParameters = searchParameters.copy(); String theQuery = constrainedParameters.getQuery(); theQuery = "(" + theQuery + ")"; if (ignoreAspectQNames != null) { for (QName ignoredAspect : ignoreAspectQNames) { theQuery = theQuery + " and " + "!ASPECT:'" + ignoredAspect.toPrefixString(nspResolver) + "'"; } } if (ignoreTypeNames != null) { for (QName ignoredType : ignoreTypeNames) { theQuery = theQuery + " and " + "!TYPE:'" + ignoredType.toPrefixString(nspResolver) + "'"; } } constrainedParameters.setQuery(theQuery); return constrainedParameters; }
Example #2
Source File: Path.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
private String createElementString(NamespacePrefixResolver resolver) { StringBuilder sb = new StringBuilder(32); if (ref.getParentRef() == null) { sb.append("/"); } else { // a parent is present sb.append(resolver == null ? ISO9075.getXPathName(ref.getQName()) : ISO9075.getXPathName(ref.getQName(), resolver)); } if (ref.getNthSibling() > -1) { sb.append("[").append(ref.getNthSibling()).append("]"); } return sb.toString(); }
Example #3
Source File: ISO9075.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
public static String getXPathName(QName qName, NamespacePrefixResolver nspr) { Collection<String> prefixes = nspr.getPrefixes(qName.getNamespaceURI()); if (prefixes.size() == 0) { throw new NamespaceException("A namespace prefix is not registered for uri " + qName.getNamespaceURI()); } String prefix = prefixes.iterator().next(); if (prefix.equals(NamespaceService.DEFAULT_PREFIX)) { return ISO9075.encode(qName.getLocalName()); } else { return prefix + ":" + ISO9075.encode(qName.getLocalName()); } }
Example #4
Source File: SolrSearchService.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public List<Serializable> selectProperties(NodeRef contextNodeRef, String xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks, String language) throws InvalidNodeRefException, XPathException { NodeSearcher nodeSearcher = new NodeSearcher(nodeService, dictionaryService, this); return nodeSearcher.selectProperties(contextNodeRef, xpath, parameters, namespacePrefixResolver, followAllParentLinks, language); }
Example #5
Source File: M2ConstraintDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
M2ConstraintDefinition(ModelDefinition modelDefinition, M2PropertyDefinition m2PropertyDef, M2Constraint m2Constraint, NamespacePrefixResolver prefixResolver) { this.model = modelDefinition; this.m2Constraint = m2Constraint; this.prefixResolver = prefixResolver; String constraintName = m2Constraint.getName(); if (constraintName == null) { // the constraint is anonymous, so it has to be defined within the context of a property if (m2PropertyDef == null) { throw new DictionaryException(ERR_ANON_NEEDS_PROPERTY); } // pick the name up from the property and some anonymous value String localName = m2PropertyDef.getName().getLocalName() + "_anon_" + (++anonPropCount); this.name = QName.createQName(m2PropertyDef.getName().getNamespaceURI(), localName); m2Constraint.setName(this.name.getPrefixedQName(prefixResolver).toPrefixString()); } else { this.name = QName.createQName(m2Constraint.getName(), prefixResolver); if (!model.isNamespaceDefined(name.getNamespaceURI())) { throw new DictionaryException(ERR_NAMESPACE_NOT_DEFINED, name.toPrefixString(), name.getNamespaceURI(), model.getName().toPrefixString()); } } }
Example #6
Source File: SolrSearchService.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public List<Serializable> selectProperties(NodeRef contextNodeRef, String xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks) throws InvalidNodeRefException, XPathException { return selectProperties(contextNodeRef, xpath, parameters, namespacePrefixResolver, followAllParentLinks, SearchService.LANGUAGE_XPATH); }
Example #7
Source File: M2PropertyDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
M2PropertyDefinition( ClassDefinition classDef, PropertyDefinition propertyDef, M2PropertyOverride override, NamespacePrefixResolver prefixResolver, Map<QName, ConstraintDefinition> modelConstraints) { this.classDef = classDef; this.name = propertyDef.getName(); this.dataType = propertyDef.getDataType(); this.propertyTypeName = this.dataType.getName(); this.m2Property = createOverriddenProperty(propertyDef, override, prefixResolver, modelConstraints); }
Example #8
Source File: SolrSearchService.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public List<NodeRef> selectNodes(NodeRef contextNodeRef, String xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks, String language) throws InvalidNodeRefException, XPathException { NodeSearcher nodeSearcher = new NodeSearcher(nodeService, dictionaryService, this); return nodeSearcher.selectNodes(contextNodeRef, xpath, parameters, namespacePrefixResolver, followAllParentLinks, language); }
Example #9
Source File: M2DataTypeDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
M2DataTypeDefinition(ModelDefinition model, M2DataType propertyType, NamespacePrefixResolver resolver) { this.model = model; this.name = QName.createQName(propertyType.getName(), resolver); if (!model.isNamespaceDefined(name.getNamespaceURI())) { throw new DictionaryException(ERR_NOT_DEFINED_NAMESPACE, name.toPrefixString(), name.getNamespaceURI(), model.getName().toPrefixString()); } this.dataType = propertyType; this.analyserResourceBundleName = dataType.getAnalyserResourceBundleName(); }
Example #10
Source File: FacetQNameUtils.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * This method converts the supplied qname string into a {@link QName} object. * It accepts both short and long form qname strings. * * @param s a qname string, such as "cm:name" or "{http://www.alfresco.org/model/content/1.0}name" * @param resolver this is needed to convert any qname prefixes into their long form. * @return the QName instance. * @throws NullPointerException if the provided string is {@code null}. * @throws IllegalArgumentException if the provided string could not be recognised as a valid QName. */ public static QName createQName(String s, NamespacePrefixResolver resolver) { final QName result; if (s.length() < 2) { throw new IllegalArgumentException("Cannot convert string '" + s + "'"); } if (s.charAt(0) == QName.NAMESPACE_BEGIN && s.substring(1).contains(Character.toString(QName.NAMESPACE_END))) { // Assume it's a long-form qname. result = QName.createQName(s); } else if ( !s.contains(Character.toString(QName.NAMESPACE_BEGIN)) && s.contains(Character.toString(QName.NAMESPACE_PREFIX))) { // Assume it's a short-form qname. result = QName.createQName(s, resolver); } else if (!s.contains(Character.toString(QName.NAMESPACE_BEGIN)) && !s.contains(Character.toString(QName.NAMESPACE_END)) && !s.contains(Character.toString(QName.NAMESPACE_PREFIX))) { // No '{', '}' or ':' means it's a prefixless QName (SITE or TAG, in our case). result = QName.createQName(null, s); } else { // We're not sure what sort of qname this is supposed to be. throw new IllegalArgumentException("Cannot convert string '" + s + "'"); } return result; }
Example #11
Source File: NodePermission.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel) { Attribute nodeRefAttribute = element.attribute(NODE_REF); if(nodeRefAttribute != null) { nodeRef = new NodeRef(nodeRefAttribute.getStringValue()); } Attribute inheritFromParentAttribute = element.attribute(INHERIT_FROM_PARENT); if(inheritFromParentAttribute != null) { inheritPermissionsFromParent = Boolean.parseBoolean(inheritFromParentAttribute.getStringValue()); } else { inheritPermissionsFromParent = true; } // Node Permissions Entry for (Iterator npit = element.elementIterator(NODE_PERMISSION); npit.hasNext(); /**/) { Element permissionEntryElement = (Element) npit.next(); ModelPermissionEntry permissionEntry = new ModelPermissionEntry(nodeRef); permissionEntry.initialise(permissionEntryElement, nspr, permissionModel); permissionEntries.add(permissionEntry); } }
Example #12
Source File: GlobalPermissionEntry.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel) { Attribute authorityAttribute = element.attribute(AUTHORITY); if(authorityAttribute != null) { authority = authorityAttribute.getStringValue(); } Attribute permissionAttribute = element.attribute(PERMISSION); if(permissionAttribute != null) { permissionReference = permissionModel.getPermissionReference(null, permissionAttribute.getStringValue()); } }
Example #13
Source File: PropertyValueConstraint.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public PropertyValueConstraint(VirtualQueryConstraint decoratedConstraint, QName property, Serializable value, NamespacePrefixResolver nspResolver) { super(decoratedConstraint); this.property = property; this.value = value; this.nspResolver = nspResolver; }
Example #14
Source File: AuthorityDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void setNamespacePrefixResolver(NamespacePrefixResolver namespacePrefixResolver) { this.namespacePrefixResolver = namespacePrefixResolver; qnameAssocSystem = QName.createQName("sys", "system", namespacePrefixResolver); qnameAssocAuthorities = QName.createQName("sys", "authorities", namespacePrefixResolver); qnameAssocZones = QName.createQName("sys", "zones", namespacePrefixResolver); }
Example #15
Source File: M2ModelDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
M2ModelDefinition(M2Model model, NamespacePrefixResolver resolver, DictionaryDAO dictionaryDAO) { this.name = QName.createQName(model.getName(), resolver); this.model = model; this.analyserResourceBundleName = model.getAnalyserResourceBundleName(); this.dictionaryDAO = dictionaryDAO; }
Example #16
Source File: CompiledModel.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
/** * Construct * * @param model model definition * @param dictionaryDAO dictionary DAO * @param namespaceDAO namespace DAO */ /*package*/ CompiledModel(M2Model model, DictionaryDAO dictionaryDAO, NamespaceDAO namespaceDAO, boolean enableConstraintClassLoading) { try { // Phase 1: Construct model definitions from model entries // resolving qualified names this.model = model; constructDefinitions(model, namespaceDAO, dictionaryDAO); // Phase 2: Resolve dependencies between model definitions ModelQuery query = new DelegateModelQuery(this, dictionaryDAO); resolveDependencies(query, namespaceDAO); // Phase 3: Resolve inheritance of values within class hierachy NamespacePrefixResolver localPrefixes = createLocalPrefixResolver(model, namespaceDAO); resolveInheritance(query, localPrefixes, constraints); // Phase 4: Resolve constraint dependencies for (ConstraintDefinition def : constraints.values()) { ((M2ConstraintDefinition)def).resolveDependencies(query, enableConstraintClassLoading); } } catch(Exception e) { if (logger.isDebugEnabled()) { logger.debug("Failed to compile model: " + model.getName(), e); } throw new DictionaryException(ERR_COMPILE_MODEL_FAILURE, e, model.getName()); } }
Example #17
Source File: NamePatternPropertyValueConstraint.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public NamePatternPropertyValueConstraint(VirtualQueryConstraint decoratedConstraint, QName property, Serializable value, NamespacePrefixResolver nspResolver) { super(decoratedConstraint, property, value, nspResolver); this.property = property; this.value = value; this.nspResolver = nspResolver; }
Example #18
Source File: VirtualQueryImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); query = new VirtualQueryImpl(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.toString(), SearchService.LANGUAGE_FTS_ALFRESCO, QUERY_TEST_STRING_QUERY); mockitoActualEnvironment = Mockito.mock(ActualEnvironment.class); Mockito.when(mockitoActualEnvironment.query(Mockito.any(SearchParameters.class))) .thenReturn(new EmptyResultSet()); mockitoPrefixResolver = Mockito.mock(NamespacePrefixResolver.class); Mockito.when(mockitoPrefixResolver.getNamespaceURI(TST_PREFIX)).thenReturn(TEST_URI); Mockito.when(mockitoPrefixResolver.getPrefixes(TEST_URI)).thenReturn(Arrays.asList(TST_PREFIX)); Mockito.when(mockitoActualEnvironment.getNamespacePrefixResolver()).thenReturn(mockitoPrefixResolver); testQName1 = QName.createQName(TST_PREFIX, TEST_LOCAL_NAME_1, mockitoPrefixResolver); testQName2 = QName.createQName(TST_PREFIX, TEST_LOCAL_NAME_2, mockitoPrefixResolver); NodeRef n1 = new NodeRef("workspace://SpacesStore/17c8f11d-0936-4295-88a0-12b85764c76f"); NodeRef n2 = new NodeRef("workspace://SpacesStore/27c8f11d-0936-4295-88a0-12b85764c76f"); nodeOneReference = ((VirtualProtocol) Protocols.VIRTUAL.protocol).newReference(n1, "/1", n2); }
Example #19
Source File: QueryParserUtils.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public static PropertyDefinition matchPropertyDefinition(String defaultNameSpaceUri, NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService, String string) { QName search = QName.createQName(QueryParserUtils.expandQName(defaultNameSpaceUri, namespacePrefixResolver, string)); PropertyDefinition propertyDefinition = dictionaryService.getProperty(QName.createQName(QueryParserUtils.expandQName(defaultNameSpaceUri, namespacePrefixResolver, string))); QName match = null; if (propertyDefinition == null) { for (QName definition : dictionaryService.getAllProperties(null)) { if (definition.getNamespaceURI().equalsIgnoreCase(search.getNamespaceURI())) { if (definition.getLocalName().equalsIgnoreCase(search.getLocalName())) { if (match == null) { match = definition; } else { throw new DictionaryException("Ambiguous data datype " + string); } } } } } else { return propertyDefinition; } if (match == null) { return null; } else { return dictionaryService.getProperty(match); } }
Example #20
Source File: AuthenticationTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private NamespacePrefixResolver getNamespacePrefixReolsver(String defaultURI) { DynamicNamespacePrefixResolver nspr = new DynamicNamespacePrefixResolver(null); nspr.registerNamespace(NamespaceService.SYSTEM_MODEL_PREFIX, NamespaceService.SYSTEM_MODEL_1_0_URI); nspr.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI); nspr.registerNamespace(ContentModel.USER_MODEL_PREFIX, ContentModel.USER_MODEL_URI); nspr.registerNamespace("namespace", "namespace"); nspr.registerNamespace(NamespaceService.DEFAULT_PREFIX, defaultURI); return nspr; }
Example #21
Source File: DBQuery.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public static String matchURI(String prefix, NamespacePrefixResolver namespacePrefixResolver) { HashSet<String> prefixes = new HashSet<String>(namespacePrefixResolver.getPrefixes()); if (prefixes.contains(prefix)) { return namespacePrefixResolver.getNamespaceURI(prefix); } String match = null; for (String candidate : prefixes) { if (candidate.equalsIgnoreCase(prefix)) { if (match == null) { match = candidate; } else { throw new QueryModelException("Ambiguous namespace prefix " + prefix); } } } if (match == null) { return null; } else { return namespacePrefixResolver.getNamespaceURI(match); } }
Example #22
Source File: DBQuery.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public static TypeDefinition matchTypeDefinition(String string, NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService) { QName search = QName.createQName(expandQName(string, namespacePrefixResolver)); TypeDefinition typeDefinition = dictionaryService.getType(search); QName match = null; if (typeDefinition == null) { for (QName definition : dictionaryService.getAllTypes()) { if (definition.getNamespaceURI().equalsIgnoreCase(search.getNamespaceURI())) { if (definition.getLocalName().equalsIgnoreCase(search.getLocalName())) { if (match == null) { match = definition; } else { throw new QueryModelException("Ambiguous data datype " + string); } } } } } else { return typeDefinition; } if (match == null) { return null; } else { return dictionaryService.getType(match); } }
Example #23
Source File: QueryParserUtils.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public static AspectDefinition matchAspectDefinition(String defaultNameSpaceUri, NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService, String string) { QName search = QName.createQName(expandQName(defaultNameSpaceUri, namespacePrefixResolver, string)); AspectDefinition aspectDefinition = dictionaryService.getAspect(QName.createQName(expandQName(defaultNameSpaceUri, namespacePrefixResolver, string))); QName match = null; if (aspectDefinition == null) { for (QName definition : dictionaryService.getAllAspects()) { if (definition.getNamespaceURI().equalsIgnoreCase(search.getNamespaceURI())) { if (definition.getLocalName().equalsIgnoreCase(search.getLocalName())) { if (match == null) { match = definition; } else { throw new DictionaryException("Ambiguous data datype " + string); } } } } } else { return aspectDefinition; } if (match == null) { return null; } else { return dictionaryService.getAspect(match); } }
Example #24
Source File: ConcurrentNodeServiceSearchTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private NamespacePrefixResolver getNamespacePrefixReolsver(String defaultURI) { DynamicNamespacePrefixResolver nspr = new DynamicNamespacePrefixResolver(null); nspr.registerNamespace(NamespaceService.SYSTEM_MODEL_PREFIX, NamespaceService.SYSTEM_MODEL_1_0_URI); nspr.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI); nspr.registerNamespace(NamespaceService.APP_MODEL_PREFIX, NamespaceService.APP_MODEL_1_0_URI); nspr.registerNamespace("namespace", "namespace"); nspr.registerNamespace(NamespaceService.DEFAULT_PREFIX, defaultURI); return nspr; }
Example #25
Source File: AbstractSearcherComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public List<NodeRef> selectNodes(NodeRef contextNodeRef, String xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks) throws InvalidNodeRefException, XPathException { return selectNodes(contextNodeRef, xpath, parameters, namespacePrefixResolver, followAllParentLinks, SearchService.LANGUAGE_XPATH); }
Example #26
Source File: AbstractSearcherComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public List<Serializable> selectProperties(NodeRef contextNodeRef, String xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks) throws InvalidNodeRefException, XPathException { return selectProperties(contextNodeRef, xpath, parameters, namespacePrefixResolver, followAllParentLinks, SearchService.LANGUAGE_XPATH); }
Example #27
Source File: Path.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
/** * @return Returns a string path made up of the component elements of this instance (prefixed where appropriate) */ public String toPrefixString(NamespacePrefixResolver resolver) { StringBuilder sb = new StringBuilder(128); for (Element element : elements) { if((sb.length() > 1) || ((sb.length() == 1) && (sb.charAt(0) != '/'))) { sb.append("/"); } sb.append(element.getPrefixedString(resolver)); } return sb.toString(); }
Example #28
Source File: QueryCollectionImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public QueryCollectionImpl(String name, Map<QName, QueryParameterDefinition> parameters, NamespacePrefixResolver namespacePrefixResolver) { super(); this.name = name; this.parameters = parameters; this.namespacePrefixResolver = namespacePrefixResolver; }
Example #29
Source File: QueryParserUtils.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public static String expandQName(String defaultNameSpaceUri, NamespacePrefixResolver namespacePrefixResolver, String qnameString) { String fieldName = qnameString; // Check for any prefixes and expand to the full uri if (qnameString.charAt(0) != '{') { int colonPosition = qnameString.indexOf(':'); if (colonPosition == -1) { // use the default namespace fieldName = "{" + defaultNameSpaceUri + "}" + qnameString; } else { String prefix = qnameString.substring(0, colonPosition); String uri = matchURI(namespacePrefixResolver, prefix); if (uri == null) { fieldName = "{" + defaultNameSpaceUri + "}" + qnameString; } else { fieldName = "{" + uri + "}" + qnameString.substring(colonPosition + 1); } } } return fieldName; }
Example #30
Source File: SortedResultSet.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private QName expandAttributeFieldName(String field, NamespacePrefixResolver namespacePrefixResolver) { QName qname; // Check for any prefixes and expand to the full uri if (field.charAt(1) != '{') { int colonPosition = field.indexOf(':'); if (colonPosition == -1) { // use the default namespace qname = QName.createQName(NamespaceService.DEFAULT_URI, field.substring(1)); } else { String prefix = field.substring(1, colonPosition); String uri = namespacePrefixResolver.getNamespaceURI(prefix); if (uri == null) { return null; } // find the prefix qname = QName.createQName(prefix, field.substring(colonPosition + 1), namespacePrefixResolver); } } else { qname = QName.createQName(field.substring(1)); } return qname; }