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;
}
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));
}
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;
}
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));
}
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();
}
};
}
};
}
Aggregations