Search in sources :

Example 6 with ObjectFactory

use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.

the class AbstractHttpTest method setUp.

@Before
public void setUp() throws Exception {
    random = new Random();
    JAXBContext context = JAXBContext.newInstance("org.xwiki.rest.model.jaxb");
    marshaller = context.createMarshaller();
    unmarshaller = context.createUnmarshaller();
    objectFactory = new ObjectFactory();
    // Make sure guest does not have edit right
    Page page = this.testUtils.rest().page(new DocumentReference("xwiki", "XWiki", "XWikiPreferences"));
    org.xwiki.rest.model.jaxb.Object rightObject = this.testUtils.rest().object("XWiki.XWikiGlobalRights");
    rightObject.withProperties(this.testUtils.rest().property("users", "XWiki.XWikiGuest"), this.testUtils.rest().property("levels", "edit"), this.testUtils.rest().property("allow", "0"));
    Objects objects = new Objects();
    objects.withObjectSummaries(rightObject);
    page.setObjects(objects);
    this.testUtils.rest().save(page);
    // Init solr utils
    this.solrUtils = new SolrTestUtils(this.testUtils);
}
Also used : SolrTestUtils(org.xwiki.repository.test.SolrTestUtils) Random(java.util.Random) ObjectFactory(org.xwiki.rest.model.jaxb.ObjectFactory) Objects(org.xwiki.rest.model.jaxb.Objects) JAXBContext(javax.xml.bind.JAXBContext) Page(org.xwiki.rest.model.jaxb.Page) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 7 with ObjectFactory

use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.

the class WikiManagerRestTest method setUp.

@Before
public void setUp() throws Exception {
    random = new Random();
    JAXBContext context = JAXBContext.newInstance("org.xwiki.rest.model.jaxb");
    marshaller = context.createMarshaller();
    unmarshaller = context.createUnmarshaller();
    objectFactory = new ObjectFactory();
    // Access once the wiki to make sure the DW is run on main wiki before messing with it
    HttpClient httpClient = new HttpClient();
    GetMethod getMethod = new GetMethod("http://localhost:" + port + "/xwiki/");
    getMethod.setFollowRedirects(true);
    httpClient.executeMethod(getMethod);
}
Also used : Random(java.util.Random) ObjectFactory(org.xwiki.rest.model.jaxb.ObjectFactory) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JAXBContext(javax.xml.bind.JAXBContext) Before(org.junit.Before)

Example 8 with ObjectFactory

use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.

the class TextPlainTagsReader method readFrom.

@Override
public Tags readFrom(Class<Tags> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    ObjectFactory objectFactory = new ObjectFactory();
    Tags tags = objectFactory.createTags();
    String text = getEntityAsString(entityStream);
    String[] tagNames = text.split(" |,|\\||\\r?\\n");
    for (String tagName : tagNames) {
        Tag tag = objectFactory.createTag();
        tag.setName(tagName);
        tags.getTags().add(tag);
    }
    return tags;
}
Also used : ObjectFactory(org.xwiki.rest.model.jaxb.ObjectFactory) Tag(org.xwiki.rest.model.jaxb.Tag) Tags(org.xwiki.rest.model.jaxb.Tags)

Example 9 with ObjectFactory

use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.

the class FormUrlEncodedCommentReader method readFrom.

@Override
public Comment readFrom(Class<Comment> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    ObjectFactory objectFactory = new ObjectFactory();
    Comment comment = objectFactory.createComment();
    Representation representation = new InputRepresentation(entityStream, org.restlet.data.MediaType.APPLICATION_WWW_FORM);
    Form form = new Form(representation);
    /*
         * If the form is empty then it might have happened that some filter has invalidated the entity stream. Try to
         * read data using getParameter()
         */
    if (form.getNames().isEmpty()) {
        HttpServletRequest httpServletRequest = ServletUtils.getRequest(Request.getCurrent());
        try {
            comment.setReplyTo(Integer.parseInt(httpServletRequest.getParameter(COMMENT_REPLYTO_FIELD_NAME)));
        } catch (NumberFormatException e) {
        // Just ignore, there won't be a reply to.
        }
        comment.setText(httpServletRequest.getParameter(COMMENT_TEXT_FIELD_NAME));
    } else {
        try {
            comment.setReplyTo(Integer.parseInt(form.getFirstValue(COMMENT_REPLYTO_FIELD_NAME)));
        } catch (NumberFormatException e) {
        // Just ignore, there won't be a reply to.
        }
        comment.setText(form.getFirstValue(COMMENT_TEXT_FIELD_NAME));
    }
    return comment;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Comment(org.xwiki.rest.model.jaxb.Comment) ObjectFactory(org.xwiki.rest.model.jaxb.ObjectFactory) InputRepresentation(org.restlet.representation.InputRepresentation) Form(org.restlet.data.Form) InputRepresentation(org.restlet.representation.InputRepresentation) Representation(org.restlet.representation.Representation)

Example 10 with ObjectFactory

use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.

the class TextPlainCommentReader method readFrom.

@Override
public Comment readFrom(Class<Comment> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    ObjectFactory objectFactory = new ObjectFactory();
    Comment comment = objectFactory.createComment();
    String text = getEntityAsString(entityStream);
    comment.setText(text);
    return comment;
}
Also used : Comment(org.xwiki.rest.model.jaxb.Comment) ObjectFactory(org.xwiki.rest.model.jaxb.ObjectFactory)

Aggregations

ObjectFactory (org.xwiki.rest.model.jaxb.ObjectFactory)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Form (org.restlet.data.Form)5 InputRepresentation (org.restlet.representation.InputRepresentation)5 Representation (org.restlet.representation.Representation)5 Page (org.xwiki.rest.model.jaxb.Page)3 Property (org.xwiki.rest.model.jaxb.Property)3 Random (java.util.Random)2 JAXBContext (javax.xml.bind.JAXBContext)2 Before (org.junit.Before)2 Comment (org.xwiki.rest.model.jaxb.Comment)2 Tag (org.xwiki.rest.model.jaxb.Tag)2 Tags (org.xwiki.rest.model.jaxb.Tags)2 HttpClient (org.apache.commons.httpclient.HttpClient)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 SolrTestUtils (org.xwiki.repository.test.SolrTestUtils)1 Object (org.xwiki.rest.model.jaxb.Object)1 Objects (org.xwiki.rest.model.jaxb.Objects)1