Skip to content
Snippets Groups Projects
Commit 5204f119 authored by Marius Dumitru Florea's avatar Marius Dumitru Florea
Browse files

XWIKI-22374: Incorrect saving of annotations when there are special characters...

XWIKI-22374: Incorrect saving of annotations when there are special characters (%, *) in the document name
* Fix the way the space names are decoded when the annotation REST resources are called.
parent 7da4650c
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.Encoded;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
......@@ -45,7 +46,7 @@ public class AnnotationsRESTResource extends AbstractAnnotationsRESTResource
{
/**
* @param wiki the wiki of the document to get annotations for
* @param space the space of the document to get annotations for
* @param spaceNames the space names of the document to get annotations for
* @param page the name of the document to get annotation for
* @return annotations of a given XWiki page. Note that we're returning a response holding the AnnotatedContent
* instead of an AnnotatedContent object because we need to be able to set custom expire fields to prevent
......@@ -53,10 +54,10 @@ public class AnnotationsRESTResource extends AbstractAnnotationsRESTResource
* @throws XWikiRestException when failing to parse space
*/
@GET
public Response doGetAnnotatedContent(@PathParam("spaceName") String space, @PathParam("pageName") String page,
@PathParam("wikiName") String wiki) throws XWikiRestException
public Response doGetAnnotatedContent(@PathParam("spaceName") @Encoded String spaceNames,
@PathParam("pageName") String page, @PathParam("wikiName") String wiki) throws XWikiRestException
{
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(space), page);
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(spaceNames), page);
return getAnnotatedContent(documentReference);
}
......@@ -64,17 +65,18 @@ public Response doGetAnnotatedContent(@PathParam("spaceName") String space, @Pat
* Add annotation to a given page.
*
* @param wiki the wiki of the document to add annotation on
* @param space the space of the document to add annotation on
* @param spaceNames the space names of the document to add annotation on
* @param page the name of the document to add annotation on
* @param request the request object with the annotation to be added
* @return AnnotationRequestResponse, responseCode = 0 if no error
* @throws XWikiRestException when failing to parse space
*/
@POST
public AnnotationResponse doPostAnnotation(@PathParam("wikiName") String wiki, @PathParam("spaceName") String space,
@PathParam("pageName") String page, AnnotationAddRequest request) throws XWikiRestException
public AnnotationResponse doPostAnnotation(@PathParam("wikiName") String wiki,
@PathParam("spaceName") @Encoded String spaceNames, @PathParam("pageName") String page,
AnnotationAddRequest request) throws XWikiRestException
{
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(space), page);
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(spaceNames), page);
return postAnnotation(documentReference, request);
}
}
......@@ -23,6 +23,7 @@
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.Encoded;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
......@@ -49,7 +50,7 @@ public class AnnotationsTranslationRESTResource extends AbstractAnnotationsRESTR
{
/**
* @param wiki the wiki of the document to get annotations for
* @param space the space of the document to get annotations for
* @param spaceNames the space names of the document to get annotations for
* @param page the name of the document to get annotation for
* @param language the language of the translation of the document to get the annotation for
* @return annotations of a given XWiki page. Note that we're returning a response holding the AnnotatedContent
......@@ -58,11 +59,12 @@ public class AnnotationsTranslationRESTResource extends AbstractAnnotationsRESTR
* @throws XWikiRestException when failing to parse space
*/
@GET
public Response doGetAnnotatedContent(@PathParam("spaceName") String space, @PathParam("pageName") String page,
@PathParam("wikiName") String wiki, @PathParam("language") String language) throws XWikiRestException
public Response doGetAnnotatedContent(@PathParam("spaceName") @Encoded String spaceNames,
@PathParam("pageName") String page, @PathParam("wikiName") String wiki, @PathParam("language") String language)
throws XWikiRestException
{
DocumentReference documentReference =
new DocumentReference(wiki, parseSpaceSegments(space), page, LocaleUtils.toLocale(language, Locale.ROOT));
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(spaceNames), page,
LocaleUtils.toLocale(language, Locale.ROOT));
return getAnnotatedContent(documentReference);
}
......@@ -70,7 +72,7 @@ public Response doGetAnnotatedContent(@PathParam("spaceName") String space, @Pat
* Add annotation to a given page.
*
* @param wiki the wiki of the document to add annotation on
* @param space the space of the document to add annotation on
* @param spaceNames the space names of the document to add annotation on
* @param page the name of the document to add annotation on
* @param language he language of the translation of the document to add the annotation on
* @param request the request object with the annotation to be added
......@@ -78,11 +80,11 @@ public Response doGetAnnotatedContent(@PathParam("spaceName") String space, @Pat
* @throws XWikiRestException when failing to parse space
*/
@POST
public AnnotationResponse doPostAnnotation(@PathParam("wikiName") String wiki, @PathParam("spaceName") String space,
@PathParam("pageName") String page, @PathParam("language") String language, AnnotationAddRequest request)
throws XWikiRestException
public AnnotationResponse doPostAnnotation(@PathParam("wikiName") String wiki,
@PathParam("spaceName") @Encoded String spaceNames, @PathParam("pageName") String page,
@PathParam("language") String language, AnnotationAddRequest request) throws XWikiRestException
{
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(space), page);
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(spaceNames), page);
return postAnnotation(documentReference, request);
}
}
......@@ -26,6 +26,7 @@
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.DELETE;
import javax.ws.rs.Encoded;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
......@@ -59,7 +60,7 @@ public class SingleAnnotationRESTResource extends AbstractAnnotationRESTResource
/**
* Deletes the specified annotation.
*
* @param space the space of the document to delete the annotation from
* @param spaceNames the space names of the document to delete the annotation from
* @param page the name of the document to delete the annotation from
* @param wiki the wiki of the document to delete the annotation from
* @param id the id of the annotation to delete
......@@ -69,12 +70,12 @@ public class SingleAnnotationRESTResource extends AbstractAnnotationRESTResource
* @throws XWikiRestException when failing to parse space
*/
@DELETE
public AnnotationResponse doDelete(@PathParam("spaceName") String space, @PathParam("pageName") String page,
@PathParam("wikiName") String wiki, @PathParam("id") String id, AnnotationRequest request)
throws XWikiRestException
public AnnotationResponse doDelete(@PathParam("spaceName") @Encoded String spaceNames,
@PathParam("pageName") String page, @PathParam("wikiName") String wiki, @PathParam("id") String id,
AnnotationRequest request) throws XWikiRestException
{
try {
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(space), page);
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(spaceNames), page);
// Initialize the context with the correct value.
updateContext(documentReference);
......@@ -102,7 +103,7 @@ public AnnotationResponse doDelete(@PathParam("spaceName") String space, @PathPa
/**
* Updates the specified annotation with the values of the fields in received collection.
*
* @param space the space of the document to update the annotation from
* @param spaceNames the space names of the document to update the annotation from
* @param page the name of the document to update the annotation from
* @param wiki the wiki of the document to update the annotation from
* @param id the id of the annotation to update
......@@ -111,12 +112,12 @@ public AnnotationResponse doDelete(@PathParam("spaceName") String space, @PathPa
* @throws XWikiRestException when failing to parse space
*/
@PUT
public AnnotationResponse doUpdate(@PathParam("spaceName") String space, @PathParam("pageName") String page,
@PathParam("wikiName") String wiki, @PathParam("id") String id, AnnotationUpdateRequest updateRequest)
throws XWikiRestException
public AnnotationResponse doUpdate(@PathParam("spaceName") @Encoded String spaceNames,
@PathParam("pageName") String page, @PathParam("wikiName") String wiki, @PathParam("id") String id,
AnnotationUpdateRequest updateRequest) throws XWikiRestException
{
try {
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(space), page);
DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(spaceNames), page);
// Initialize the context with the correct value.
updateContext(documentReference);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment