1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rest.internal.resources.pages

File ModifiablePageResource.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

4
10
2
1
69
36
5
0.5
5
2
2.5

Classes

Class Line # Actions
ModifiablePageResource 36 10 0% 5 2
0.87587.5%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rest.internal.resources.pages;
21   
22    import javax.inject.Inject;
23    import javax.ws.rs.core.Response;
24    import javax.ws.rs.core.Response.Status;
25   
26    import org.xwiki.rest.XWikiResource;
27    import org.xwiki.rest.internal.ModelFactory;
28    import org.xwiki.rest.model.jaxb.Page;
29   
30    import com.xpn.xwiki.XWikiException;
31    import com.xpn.xwiki.api.Document;
32   
33    /**
34    * @version $Id: ce3aa20572b711613ef4294830a6dee1d65f85f3 $
35    */
 
36    public class ModifiablePageResource extends XWikiResource
37    {
38    @Inject
39    protected ModelFactory factory;
40   
 
41  186 toggle public Response putPage(DocumentInfo documentInfo, Page page) throws XWikiException
42    {
43  186 Document doc = documentInfo.getDocument();
44   
45    // Save the document only if there is actually something to do if if the document does not exist
46  186 if (this.factory.toDocument(doc, page) || doc.isNew()) {
47  186 doc.save(page.getComment());
48   
49  185 page =
50    this.factory.toRestPage(uriInfo.getBaseUri(), uriInfo.getAbsolutePath(), doc, false, false, false, false,
51    false);
52   
53  185 if (documentInfo.isCreated()) {
54  107 return Response.created(uriInfo.getAbsolutePath()).entity(page).build();
55    } else {
56  78 return Response.status(Status.ACCEPTED).entity(page).build();
57    }
58    } else {
59  0 return Response.status(Status.NOT_MODIFIED).build();
60    }
61    }
62   
 
63  49 toggle void deletePage(DocumentInfo documentInfo) throws XWikiException
64    {
65  49 Document doc = documentInfo.getDocument();
66   
67  49 doc.delete();
68    }
69    }