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