Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
AbstractFormUrlEncodedAnnotationUpdateRequestReader | 34 | 13 | 0% | 4 | 5 |
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.annotation.rest.internal.representations; | |
21 | ||
22 | import org.xwiki.annotation.rest.model.jaxb.AnnotationField; | |
23 | import org.xwiki.annotation.rest.model.jaxb.AnnotationUpdateRequest; | |
24 | import org.xwiki.annotation.rest.model.jaxb.ObjectFactory; | |
25 | ||
26 | /** | |
27 | * Partial implementation of a reader that reads an annotation update request, extending the request reader with the | |
28 | * read of the annotation fields. | |
29 | * | |
30 | * @param <T> the type read from the url encoded form | |
31 | * @version $Id: 10c024fbc3e6ffaae6d6958d3e27890e037a5fbc $ | |
32 | * @since 2.3M1 | |
33 | */ | |
34 | public abstract class AbstractFormUrlEncodedAnnotationUpdateRequestReader<T extends AnnotationUpdateRequest> extends | |
35 | AbstractFormUrlEncodedAnnotationRequestReader<T> | |
36 | { | |
37 | 12 | ![]() |
38 | protected boolean saveField(T readObject, String key, String value, ObjectFactory objectFactory) | |
39 | { | |
40 | // first try to pass this through the super reader, to read the specific request fields | |
41 | 12 | boolean read = super.saveField(readObject, key, value, objectFactory); |
42 | // if the field was not read then it's a custom field, store it as an annotation extra field | |
43 | 12 | if (!read) { |
44 | // use xwiki convention that first value is always the one used and ignore a field if it has already been | |
45 | // read | |
46 | 12 | boolean contains = false; |
47 | 12 | for (AnnotationField readField : readObject.getAnnotation().getFields()) { |
48 | 12 | if (readField.getName().equals(key)) { |
49 | 0 | contains = true; |
50 | 0 | break; |
51 | } | |
52 | } | |
53 | 12 | if (!contains) { |
54 | 12 | AnnotationField extraField = objectFactory.createAnnotationField(); |
55 | 12 | extraField.setName(key); |
56 | 12 | extraField.setValue(value); |
57 | 12 | readObject.getAnnotation().getFields().add(extraField); |
58 | } | |
59 | } | |
60 | // always return true since this will always be able to store the extra fields | |
61 | 12 | return true; |
62 | } | |
63 | } |