Search in sources :

Example 21 with EntityReference

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

the class LogoutAction method action.

@Override
public boolean action(XWikiContext context) throws XWikiException {
    XWikiRequest request = context.getRequest();
    XWikiResponse response = context.getResponse();
    // Destroy the current session, if any, so that any private data stored in the session won't be accessible by
    // the next user on the same computer
    HttpSession currentSession = request.getSession(false);
    if (currentSession != null) {
        synchronized (currentSession) {
            currentSession.invalidate();
            // Early registration of a new session, so that the client gets to know the new session identifier early
            // A new session is going to be needed after the redirect anyway
            request.getSession(true);
        }
    }
    // Process redirect
    String redirect;
    redirect = context.getRequest().getParameter("xredirect");
    if (StringUtils.isEmpty(redirect)) {
        DocumentReferenceResolver<EntityReference> resolver = Utils.getComponent(DocumentReferenceResolver.TYPE_REFERENCE);
        // Get default document
        DocumentReference reference = resolver.resolve(null, EntityType.DOCUMENT);
        // Set wiki reference to current wiki
        reference = reference.setWikiReference(new WikiReference(context.getWikiId()));
        // Create URL to the wiki home page
        redirect = context.getWiki().getURL(reference, "view", context);
    }
    sendRedirect(response, redirect);
    return false;
}
Also used : HttpSession(javax.servlet.http.HttpSession) EntityReference(org.xwiki.model.reference.EntityReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 22 with EntityReference

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

the class ObjectAddAction method action.

@Override
public boolean action(XWikiContext context) throws XWikiException {
    // CSRF prevention
    if (!csrfTokenCheck(context)) {
        return false;
    }
    XWiki xwiki = context.getWiki();
    XWikiResponse response = context.getResponse();
    DocumentReference userReference = context.getUserReference();
    XWikiDocument doc = context.getDoc();
    ObjectAddForm oform = (ObjectAddForm) context.getForm();
    String className = oform.getClassName();
    EntityReference classReference = this.relativeResolver.resolve(className, EntityType.DOCUMENT);
    BaseObject object = doc.newXObject(classReference, context);
    BaseClass baseclass = object.getXClass(context);
    // The request parameter names that correspond to object fields must NOT specify the object number because the
    // object number is not known before the object is added. The following is a good parameter name:
    // Space.Class_property. As a consequence we use only the class name to extract the object from the request.
    Map<String, String[]> objmap = oform.getObject(className);
    // We need to have a string in the map for each field for the object to be correctly created.
    // Otherwise, queries using the missing properties will fail to return this object.
    @SuppressWarnings("unchecked") Collection<PropertyClass> fields = baseclass.getFieldList();
    for (PropertyClass property : fields) {
        String name = property.getName();
        if (objmap.get(name) == null) {
            objmap.put(name, EMPTY_PROPERTY);
        }
    }
    // Load the object properties that are defined in the request.
    baseclass.fromMap(objmap, object);
    doc.setAuthorReference(userReference);
    if (doc.isNew()) {
        doc.setCreatorReference(userReference);
    }
    xwiki.saveDocument(doc, localizePlainOrKey("core.comment.addObject"), true, context);
    // If this is an ajax request, no need to redirect.
    if (Utils.isAjaxRequest(context)) {
        context.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
        return false;
    }
    // forward to edit
    String redirect = Utils.getRedirect("edit", "editor=object", "xcontinue", "xredirect");
    // If the redirect URL contains the xobjectNumber parameter then inject the number of the added object as its
    // value so that the target page knows which object was added.
    redirect = XOBJECT_NUMBER_PARAMETER.matcher(redirect).replaceFirst("$1xobjectNumber=" + object.getNumber() + "$2");
    sendRedirect(response, redirect);
    return false;
}
Also used : XWiki(com.xpn.xwiki.XWiki) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 23 with EntityReference

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

the class R72000XWIKI12153DataMigration method addBatch.

private void addBatch(PreparedStatement statement, String spaceName) throws SQLException {
    // Convert the space name into a space reference
    String spaceReference = this.serializer.serialize(new EntityReference(spaceName, EntityType.SPACE));
    statement.setString(1, spaceReference);
    statement.setString(2, spaceName);
    // Add a conversion to the list
    statement.addBatch();
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference)

Example 24 with EntityReference

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

the class R72001XWIKI12228DataMigration method getVisibleSpaces.

private Collection<SpaceReference> getVisibleSpaces(Session session) {
    Query query = session.createQuery(createSpaceQuery(false));
    Collection<SpaceReference> databaseSpaces = new ArrayList<>();
    for (String space : (List<String>) query.list()) {
        databaseSpaces.add(this.spaceResolver.resolve(space, WIKI));
    }
    // Resolve nested spaces
    Set<SpaceReference> spaces = new HashSet<>(databaseSpaces);
    for (SpaceReference space : databaseSpaces) {
        for (EntityReference parent = space.getParent(); parent instanceof SpaceReference; parent = parent.getParent()) {
            spaces.add((SpaceReference) parent);
        }
    }
    return spaces;
}
Also used : Query(org.hibernate.Query) SpaceReference(org.xwiki.model.reference.SpaceReference) ArrayList(java.util.ArrayList) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 25 with EntityReference

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

the class RefactoringScriptServiceTest method configure.

@Before
public void configure() throws Exception {
    this.jobExecutor = this.mocker.getInstance(JobExecutor.class);
    Execution execution = this.mocker.getInstance(Execution.class);
    when(execution.getContext()).thenReturn(executionContext);
    DocumentAccessBridge documentAccessBridge = this.mocker.getInstance(DocumentAccessBridge.class);
    when(documentAccessBridge.getCurrentUserReference()).thenReturn(this.userReference);
    EntityReferenceProvider defaultEntityReferenceProvider = this.mocker.getInstance(EntityReferenceProvider.class);
    when(defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(new EntityReference("WebHome", EntityType.DOCUMENT, null));
}
Also used : EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) Execution(org.xwiki.context.Execution) JobExecutor(org.xwiki.job.JobExecutor) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) EntityReference(org.xwiki.model.reference.EntityReference) Before(org.junit.Before)

Aggregations

EntityReference (org.xwiki.model.reference.EntityReference)338 Test (org.junit.Test)157 DocumentReference (org.xwiki.model.reference.DocumentReference)107 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)39 BaseObject (com.xpn.xwiki.objects.BaseObject)38 ArrayList (java.util.ArrayList)27 XWikiContext (com.xpn.xwiki.XWikiContext)24 WikiReference (org.xwiki.model.reference.WikiReference)24 SpaceReference (org.xwiki.model.reference.SpaceReference)23 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)18 XWikiException (com.xpn.xwiki.XWikiException)17 EntityType (org.xwiki.model.EntityType)11 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)10 EntityReferenceProvider (org.xwiki.model.reference.EntityReferenceProvider)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)8 XDOM (org.xwiki.rendering.block.XDOM)8 URL (java.net.URL)7 AttachmentReference (org.xwiki.model.reference.AttachmentReference)7 HashMap (java.util.HashMap)6 Before (org.junit.Before)6