Search in sources :

Example 91 with WikiReference

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

the class PathWikiReferenceExtractorTest method testAndAssert.

private void testAndAssert(String urlToTest, String expectedWikiId) throws Exception {
    ExtendedURL url = new ExtendedURL(new URL(urlToTest), "xwiki");
    // Remove the resource type (i.e. the first segment) since this is what is expected by the extractor
    url.getSegments().remove(0);
    WikiReference wikiReference = this.mocker.getComponentUnderTest().extract(url);
    assertEquals(new WikiReference(expectedWikiId), wikiReference);
}
Also used : ExtendedURL(org.xwiki.url.ExtendedURL) WikiReference(org.xwiki.model.reference.WikiReference) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL)

Example 92 with WikiReference

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

the class BinEntityResourceReferenceResolverTest method buildEntityReference.

private EntityReference buildEntityReference(String wiki, List<String> spaces, String page, String attachment) {
    EntityReference entityReference = new WikiReference(wiki);
    if (spaces != null) {
        EntityReference parent = entityReference;
        for (String space : spaces) {
            entityReference = new EntityReference(space, EntityType.SPACE, parent);
            parent = entityReference;
        }
    }
    if (page != null) {
        entityReference = new EntityReference(page, EntityType.DOCUMENT, entityReference);
    }
    if (attachment != null) {
        entityReference = new EntityReference(attachment, EntityType.ATTACHMENT, entityReference);
    }
    return entityReference;
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) WikiReference(org.xwiki.model.reference.WikiReference)

Example 93 with WikiReference

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

the class Exporter method exportDocuments.

/**
 * Export documents from an existing loaded XWiki database. The database is defined by its passed name and by an
 * Hibernate configuration file.
 *
 * @param exportDirectory the directory where to export the documents
 * @param wikiId the wiki to export
 * @throws Exception if the export failed for any reason
 */
public void exportDocuments(File exportDirectory, String wikiId) throws Exception {
    WikiReference currentWikiReference = this.oldCoreHelper.getXWikiContext().getWikiReference();
    try {
        this.oldCoreHelper.getXWikiContext().setWikiId(wikiId);
        // TODO: Use Filter framework instead
        Package pack = new Package();
        pack.setWithVersions(false);
        pack.addAllWikiDocuments(this.oldCoreHelper.getXWikiContext());
        // See https://jira.xwiki.org/browse/XWIKI-458
        try {
            pack.exportToDir(exportDirectory, this.oldCoreHelper.getXWikiContext());
        } catch (IOException e) {
            throw new PackageException(PackageException.ERROR_PACKAGE_UNKNOWN, "Failed to export documents to [" + exportDirectory + "]", e);
        }
    } finally {
        this.oldCoreHelper.getXWikiContext().setWikiReference(currentWikiReference);
    }
}
Also used : PackageException(com.xpn.xwiki.plugin.packaging.PackageException) Package(com.xpn.xwiki.plugin.packaging.Package) IOException(java.io.IOException) WikiReference(org.xwiki.model.reference.WikiReference)

Example 94 with WikiReference

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

the class AbstractValidationTest method readXarContents.

protected static List<DocumentReference> readXarContents(String fileName, String patternFilter) throws Exception {
    Collection<XarEntry> entries = XarPackage.getEntries(new File(fileName));
    List<DocumentReference> result = new ArrayList<DocumentReference>(entries.size());
    WikiReference wikiReference = new WikiReference("xwiki");
    Pattern pattern = patternFilter == null ? null : Pattern.compile(patternFilter);
    for (XarEntry entry : entries) {
        if (pattern == null || pattern.matcher(SERIALIZER.serialize(entry)).matches()) {
            result.add(new DocumentReference(entry, wikiReference));
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) XarEntry(org.xwiki.xar.XarEntry) ArrayList(java.util.ArrayList) WikiReference(org.xwiki.model.reference.WikiReference) File(java.io.File) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 95 with WikiReference

use of org.xwiki.model.reference.WikiReference in project celements-blog by celements.

the class ArticleLuceneQueryBuilder method build.

@Override
public LuceneQuery build(ArticleLoadParameter param) throws XWikiException {
    LuceneQuery query = null;
    if (param.getBlogDocRef() != null) {
        QueryRestrictionGroup blogOrSubsGrp = searchService.createRestrictionGroup(Type.OR);
        blogOrSubsGrp.add(getBlogRestriction(param));
        blogOrSubsGrp.add(getSubsRestrictions(param));
        if (!blogOrSubsGrp.isEmpty()) {
            WikiReference wikiRef = param.getBlogDocRef().getWikiReference();
            query = searchService.createQuery();
            query.setWiki(wikiRef);
            query.add(getBlogSearchTermRestriction(param));
            DocumentReference articleClassRef = getBlogClasses().getArticleClassRef(wikiRef.getName());
            query.add(searchService.createObjectRestriction(articleClassRef));
            if (StringUtils.isNotBlank(param.getLanguage())) {
                query.add(searchService.createFieldRestriction(articleClassRef, BlogClasses.PROPERTY_ARTICLE_LANG, "\"" + param.getLanguage() + "\""));
            }
            query.add(blogOrSubsGrp);
        }
    }
    LOGGER.info("Built '" + query + "' for '" + param + "'");
    return query;
}
Also used : LuceneQuery(com.celements.search.lucene.query.LuceneQuery) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup)

Aggregations

WikiReference (org.xwiki.model.reference.WikiReference)220 DocumentReference (org.xwiki.model.reference.DocumentReference)127 Test (org.junit.Test)106 SpaceReference (org.xwiki.model.reference.SpaceReference)58 XWikiContext (com.xpn.xwiki.XWikiContext)33 XWikiException (com.xpn.xwiki.XWikiException)24 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 ArrayList (java.util.ArrayList)19 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)18 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)11 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)10 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)10 XWiki (com.xpn.xwiki.XWiki)9 BaseObject (com.xpn.xwiki.objects.BaseObject)9 ComponentManager (org.xwiki.component.manager.ComponentManager)9 Expectations (org.jmock.Expectations)8 Before (org.junit.Before)8 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)8