Search in sources :

Example 36 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class ModelScriptService method createSpaceReference.

/**
 * Creates a {@link SpaceReference} from a list of string representing the space name and the name of its parents.
 *
 * @param spaces the list of the spaces name (eg ["A", "B", "C"])
 * @param parent the wiki reference in which the space is located
 * @return the reference to the space
 * @since 7.2M2
 */
public SpaceReference createSpaceReference(List<String> spaces, WikiReference parent) {
    SpaceReference spaceReference = null;
    EntityReference parentReference = parent;
    for (String space : spaces) {
        spaceReference = new SpaceReference(space, parentReference);
        parentReference = spaceReference;
    }
    return spaceReference;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference)

Example 37 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class XWiki method getPreferencesDocumentReference.

/**
 * Return the document reference to the wiki preferences.
 *
 * @param context see {@link XWikiContext}
 * @since 4.3M2
 */
private DocumentReference getPreferencesDocumentReference(XWikiContext context) {
    String database = context.getWikiId();
    EntityReference spaceReference;
    if (database != null) {
        spaceReference = new EntityReference(SYSTEM_SPACE, EntityType.SPACE, new WikiReference(database));
    } else {
        spaceReference = getCurrentMixedEntityReferenceResolver().resolve(SYSTEM_SPACE, EntityType.SPACE);
    }
    return new DocumentReference("XWikiPreferences", new SpaceReference(spaceReference));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference) RegexEntityReference(org.xwiki.model.reference.RegexEntityReference) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference)

Example 38 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class BaseSearchResult method searchSpaces.

/**
 * Search for keyword in the given scopes. Limit the search only to spaces.
 *
 * @param keywords the string that will be used in a "like" XWQL clause
 * @param number number of results to be returned
 * @param start 0-based start offset
 * @return the results.
 */
protected List<SearchResult> searchSpaces(String keywords, String wikiName, int number, int start) throws QueryException, IllegalArgumentException, UriBuilderException, XWikiException {
    List<SearchResult> result = new ArrayList<SearchResult>();
    if (StringUtils.isEmpty(keywords)) {
        return result;
    }
    String escapedKeywords = keywords.replaceAll("([%_!])", "!$1");
    String query = "select space.reference from XWikiSpace as space" + " where lower(space.name) like lower(:keywords) escape '!'" + " or lower(space.reference) like lower(:prefix) escape '!'" + " order by lower(space.reference), space.reference";
    List<Object> queryResult = queryManager.createQuery(query, Query.HQL).bindValue("keywords", String.format("%%%s%%", escapedKeywords)).bindValue("prefix", String.format("%s%%", escapedKeywords)).setWiki(wikiName).setLimit(number).setOffset(start).addFilter(this.hiddenSpaceFilter).execute();
    XWiki xwikiApi = Utils.getXWikiApi(componentManager);
    for (Object object : queryResult) {
        String spaceId = (String) object;
        List<String> spaces = Utils.getSpacesFromSpaceId(spaceId);
        SpaceReference spaceReference = new SpaceReference(wikiName, spaces);
        if (this.authorizationManager.hasAccess(Right.VIEW, spaceReference)) {
            Document spaceDoc = xwikiApi.getDocument(spaceReference);
            SearchResult searchResult = objectFactory.createSearchResult();
            searchResult.setType("space");
            searchResult.setId(spaceId);
            searchResult.setWiki(wikiName);
            searchResult.setSpace(spaceId);
            searchResult.setTitle(spaceDoc != null ? spaceDoc.getPlainTitle() : spaceReference.getName());
            // Add a link to the space information.
            Link spaceLink = new Link();
            spaceLink.setRel(Relations.SPACE);
            spaceLink.setHref(Utils.createURI(uriInfo.getBaseUri(), SpaceResource.class, wikiName, spaces).toString());
            searchResult.getLinks().add(spaceLink);
            // Add a link to the home page if it exists and it is viewable.
            if (spaceDoc != null && !spaceDoc.isNew()) {
                Link pageLink = new Link();
                pageLink.setHref(Utils.createURI(uriInfo.getBaseUri(), PageResource.class, wikiName, spaces, spaceDoc.getName()).toString());
                pageLink.setRel(Relations.HOME);
                searchResult.getLinks().add(pageLink);
            }
            result.add(searchResult);
        }
    }
    return result;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) ArrayList(java.util.ArrayList) XWiki(com.xpn.xwiki.api.XWiki) SearchResult(org.xwiki.rest.model.jaxb.SearchResult) Document(com.xpn.xwiki.api.Document) Link(org.xwiki.rest.model.jaxb.Link)

Example 39 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class DefaultSecurityEntryReader method read.

/**
 * Load the rules from wiki documents.
 *
 * @param entity Any entity reference that is either a WIKI or a SPACE, or an entity containing a DOCUMENT entity.
 * @return the access rules that could be loaded into the cache.
 * @throws org.xwiki.security.authorization.AuthorizationException if an issue arise while reading these rules
 *         from the wiki.
 */
@Override
public SecurityRuleEntry read(SecurityReference entity) throws AuthorizationException {
    if (entity == null) {
        return null;
    }
    if (entity.getOriginalReference() == null) {
        // More generally, any reference without a valid original reference should not be considered.
        return new InternalSecurityRuleEntry(entity, Collections.<SecurityRule>emptyList());
    }
    DocumentReference documentReference;
    DocumentReference classReference;
    WikiReference wikiReference;
    switch(entity.getType()) {
        case WIKI:
            wikiReference = new WikiReference(entity);
            SpaceReference wikiSpace = new SpaceReference(XWikiConstants.XWIKI_SPACE, wikiReference);
            documentReference = new DocumentReference(XWikiConstants.WIKI_DOC, wikiSpace);
            classReference = new DocumentReference(XWikiConstants.GLOBAL_CLASSNAME, wikiSpace);
            break;
        case SPACE:
            wikiReference = new WikiReference(entity.extractReference(EntityType.WIKI));
            documentReference = new DocumentReference(XWikiConstants.SPACE_DOC, new SpaceReference(entity));
            classReference = new DocumentReference(XWikiConstants.GLOBAL_CLASSNAME, new SpaceReference(XWikiConstants.XWIKI_SPACE, wikiReference));
            break;
        case DOCUMENT:
            wikiReference = new WikiReference(entity.extractReference(EntityType.WIKI));
            documentReference = new DocumentReference(entity);
            classReference = new DocumentReference(XWikiConstants.LOCAL_CLASSNAME, new SpaceReference(XWikiConstants.XWIKI_SPACE, wikiReference));
            break;
        default:
            throw new EntityTypeNotSupportedException(entity.getType(), this);
    }
    return new InternalSecurityRuleEntry(entity, getSecurityRules(documentReference, classReference, wikiReference));
}
Also used : EntityTypeNotSupportedException(org.xwiki.security.authorization.EntityTypeNotSupportedException) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 40 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class LegacyTestWiki method getAllGroupReferences.

private Collection<DocumentReference> getAllGroupReferences(final DocumentReference userReference) {
    final TestWiki wiki = wikis.get(context.getWikiId());
    if (wiki == null) {
        return Collections.<DocumentReference>emptySet();
    }
    final Collection<String> groupNames = wiki.getGroupsForUser(userReference);
    final SpaceReference userSpaceReference = new SpaceReference("XWiki", new WikiReference(wiki.getName()));
    return new AbstractCollection<DocumentReference>() {

        @Override
        public int size() {
            return groupNames.size();
        }

        @Override
        public Iterator<DocumentReference> iterator() {
            return new Iterator<DocumentReference>() {

                private final Iterator<String> groupNamesIterator = groupNames.iterator();

                @Override
                public boolean hasNext() {
                    return groupNamesIterator.hasNext();
                }

                @Override
                public DocumentReference next() {
                    String groupName = groupNamesIterator.next();
                    return documentReferenceResolver.resolve(groupName, userSpaceReference);
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) AbstractCollection(java.util.AbstractCollection) Iterator(java.util.Iterator) WikiReference(org.xwiki.model.reference.WikiReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

SpaceReference (org.xwiki.model.reference.SpaceReference)142 DocumentReference (org.xwiki.model.reference.DocumentReference)96 Test (org.junit.Test)83 WikiReference (org.xwiki.model.reference.WikiReference)58 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)21 ArrayList (java.util.ArrayList)11 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)11 XWikiException (com.xpn.xwiki.XWikiException)9 QueryRestrictionGroup (com.celements.search.lucene.query.QueryRestrictionGroup)8 Expectations (org.jmock.Expectations)8 XWikiContext (com.xpn.xwiki.XWikiContext)7 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)7 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)7 ComponentManager (org.xwiki.component.manager.ComponentManager)7 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)7 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)7 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)7 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)7 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)7