Search in sources :

Example 1 with ObjectFactory

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

the class XWikiResource method initialize.

/**
 * Resource initialization.
 */
@Override
public void initialize() throws InitializationException {
    logger = java.util.logging.Logger.getLogger(this.getClass().getName());
    objectFactory = new ObjectFactory();
    this.slf4Jlogger.trace("Resource {} initialized. Serving user: '{}'\n", getClass().getName(), Utils.getXWikiUser(componentManager));
}
Also used : ObjectFactory(org.xwiki.rest.model.jaxb.ObjectFactory)

Example 2 with ObjectFactory

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

the class TextPlainPageReader method readFrom.

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

Example 3 with ObjectFactory

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

the class FormUrlEncodedTagsReader 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();
    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());
        String text = httpServletRequest.getParameter(TAGS_FIELD_NAME);
        if (text != null) {
            String[] tagNames = text.split(" |,|\\|");
            for (String tagName : tagNames) {
                Tag tag = objectFactory.createTag();
                tag.setName(tagName);
                tags.getTags().add(tag);
            }
        }
        String[] tagNames = httpServletRequest.getParameterValues(TAG_FIELD_NAME);
        if (tagNames != null) {
            for (String tagName : tagNames) {
                Tag tag = objectFactory.createTag();
                tag.setName(tagName);
                tags.getTags().add(tag);
            }
        }
    } else {
        String text = form.getFirstValue(TAGS_FIELD_NAME);
        if (text != null) {
            String[] tagNames = text.split(" |,|\\|");
            for (String tagName : tagNames) {
                Tag tag = objectFactory.createTag();
                tag.setName(tagName);
                tags.getTags().add(tag);
            }
        }
        for (String tagName : form.getValuesArray(TAG_FIELD_NAME)) {
            Tag tag = objectFactory.createTag();
            tag.setName(tagName);
            tags.getTags().add(tag);
        }
    }
    return tags;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) 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) Tag(org.xwiki.rest.model.jaxb.Tag) Tags(org.xwiki.rest.model.jaxb.Tags)

Example 4 with ObjectFactory

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

the class FormUrlEncodedObjectReader method readFrom.

@Override
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    ObjectFactory objectFactory = new ObjectFactory();
    Object object = objectFactory.createObject();
    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());
        object.setClassName(httpServletRequest.getParameter(CLASSNAME_FIELD_NAME));
        Enumeration<String> enumeration = httpServletRequest.getParameterNames();
        while (enumeration.hasMoreElements()) {
            String name = enumeration.nextElement();
            if (name.startsWith(PROPERTY_PREFIX)) {
                Property property = objectFactory.createProperty();
                property.setName(name.replace(PROPERTY_PREFIX, ""));
                property.setValue(httpServletRequest.getParameter(name));
                object.getProperties().add(property);
            }
        }
    } else {
        object.setClassName(form.getFirstValue(CLASSNAME_FIELD_NAME));
        for (String name : form.getNames()) {
            if (name.startsWith(PROPERTY_PREFIX)) {
                Property property = objectFactory.createProperty();
                property.setName(name.replace(PROPERTY_PREFIX, ""));
                property.setValue(form.getFirstValue(name));
                object.getProperties().add(property);
            }
        }
    }
    return object;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ObjectFactory(org.xwiki.rest.model.jaxb.ObjectFactory) InputRepresentation(org.restlet.representation.InputRepresentation) Form(org.restlet.data.Form) Object(org.xwiki.rest.model.jaxb.Object) InputRepresentation(org.restlet.representation.InputRepresentation) Representation(org.restlet.representation.Representation) Property(org.xwiki.rest.model.jaxb.Property)

Example 5 with ObjectFactory

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

the class TextPlainPropertyReader method readFrom.

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

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