use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class DefaultSignatureStoreTest method testRetrievingExistingSignature.
@Test
public void testRetrievingExistingSignature() throws Exception {
XWikiDocument sourceDocument = mock(XWikiDocument.class);
when(this.xwiki.getDocument(new DocumentReference("wiki", "space", "document"), this.xcontext)).thenReturn(sourceDocument);
BaseObject signatureObject = mock(BaseObject.class);
when(sourceDocument.getXObject(new DocumentReference(DefaultSignatureStore.SIGNATURECLASS, new WikiReference("wiki")), DefaultSignatureStore.SIGNATURECLASS_PROP_REFERENCE, "block")).thenReturn(signatureObject);
when(signatureObject.getLargeStringValue(DefaultSignatureStore.SIGNATURECLASS_PROP_SIGNATURE)).thenReturn(ENCODED_SIGNATURE);
assertThat(this.store.retrieve(new BlockReference("block", new DocumentReference("wiki", "space", "document"))), equalTo(SIGNATURE));
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class DefaultSignatureStoreTest method testUpdatingSignature.
@Test
public void testUpdatingSignature() throws Exception {
XWikiDocument sourceDocument = mock(XWikiDocument.class);
when(this.xwiki.getDocument(new DocumentReference("wiki", "space", "document"), this.xcontext)).thenReturn(sourceDocument);
BaseObject signatureObject = mock(BaseObject.class);
when(sourceDocument.getXObject(new DocumentReference(DefaultSignatureStore.SIGNATURECLASS, new WikiReference("wiki")), DefaultSignatureStore.SIGNATURECLASS_PROP_REFERENCE, "block")).thenReturn(signatureObject);
this.store.store(new BlockReference("block", new DocumentReference("wiki", "space", "document")), SIGNATURE);
verify(signatureObject, never()).setStringValue(eq(DefaultSignatureStore.SIGNATURECLASS_PROP_REFERENCE), any(String.class));
verify(signatureObject).setLargeStringValue(DefaultSignatureStore.SIGNATURECLASS_PROP_SIGNATURE, ENCODED_SIGNATURE);
verify(this.xwiki).saveDocument(sourceDocument, this.xcontext);
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class DefaultModelContext method getCurrentEntityReference.
@Override
public EntityReference getCurrentEntityReference() {
WikiReference result = null;
// TODO: This is bridge to the old XWiki Context since we currently don't store the current entity in the
// new Execution Context yet. Remove when we do so.
ExecutionContext econtext = this.execution.getContext();
if (econtext != null) {
Map<String, Object> xcontext = (Map<String, Object>) econtext.getProperty(XCONTEXT_KEY);
if (xcontext != null) {
String wikiName = (String) xcontext.get(WIKINAME_KEY);
if (wikiName != null) {
result = new WikiReference(wikiName);
}
}
}
return result;
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class XWikiDocument method setDatabase.
/**
* Note that this method cannot be removed for now since it's used by Hibernate for loading a XWikiDocument.
*
* @deprecated since 2.2M1 use {@link #setDocumentReference(DocumentReference)} instead
*/
@Deprecated
public void setDatabase(String database) {
if (database != null) {
DocumentReference reference = getDocumentReference();
WikiReference wiki = reference.getWikiReference();
WikiReference newWiki = new WikiReference(database);
if (!newWiki.equals(wiki)) {
setDocumentReferenceInternal(reference.replaceParent(wiki, newWiki));
}
}
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class XWikiDocument method getChildrenReferences.
/**
* Returns a list of references of all documents which list this document as their parent, in the current wiki.
*
* @param nb The number of results to return.
* @param start The number of results to skip before we begin returning results.
* @param context The {@link com.xpn.xwiki.XWikiContext context}.
* @return the list of document references
* @throws XWikiException If there's an error querying the database.
* @since 2.2M2
*/
public List<DocumentReference> getChildrenReferences(int nb, int start, XWikiContext context) throws XWikiException {
// Use cases:
// - the parent document reference saved in the database matches the reference of this document, in its fully
// serialized form (eg "wiki:space.page"). Note that this is normally not required since the wiki part
// isn't saved in the database when it matches the current wiki.
// - the parent document reference saved in the database matches the reference of this document, in its
// serialized form without the wiki part (eg "space.page"). The reason we don't need to specify the wiki
// part is because document parents saved in the database don't have the wiki part specified when it matches
// the current wiki.
// - the parent document reference saved in the database matches the page name part of this document's
// reference (eg "page") and the parent document's space is the same as this document's space.
List<DocumentReference> children = new ArrayList<DocumentReference>();
try {
Query query = getStore().getQueryManager().createQuery("select distinct doc.fullName from XWikiDocument doc where " + "doc.parent=:prefixedFullName or doc.parent=:fullName or (doc.parent=:name and doc.space=:space)", Query.XWQL);
query.addFilter(Utils.getComponent(QueryFilter.class, "hidden"));
query.bindValue("prefixedFullName", getDefaultEntityReferenceSerializer().serialize(getDocumentReference()));
query.bindValue("fullName", LOCAL_REFERENCE_SERIALIZER.serialize(getDocumentReference()));
query.bindValue("name", getDocumentReference().getName());
query.bindValue("space", LOCAL_REFERENCE_SERIALIZER.serialize(getDocumentReference().getLastSpaceReference()));
query.setLimit(nb).setOffset(start);
List<String> queryResults = query.execute();
WikiReference wikiReference = this.getDocumentReference().getWikiReference();
for (String fullName : queryResults) {
children.add(getCurrentDocumentReferenceResolver().resolve(fullName, wikiReference));
}
} catch (QueryException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, String.format("Failed to retrieve children for document [%s]", this.getDocumentReference()), e);
}
return children;
}
Aggregations