1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.filter.xar.internal.input

File AttachmentReader.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

10
15
2
2
87
51
7
0.47
7.5
1
3.5

Classes

Class Line # Actions
AttachmentReader 42 14 0% 6 1
0.9696%
AttachmentReader.WikiAttachment 44 1 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 26 tests. .

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.filter.xar.internal.input;
21   
22    import java.io.ByteArrayInputStream;
23   
24    import javax.inject.Singleton;
25    import javax.xml.stream.XMLStreamException;
26    import javax.xml.stream.XMLStreamReader;
27   
28    import org.apache.commons.codec.binary.Base64;
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.filter.FilterEventParameters;
31    import org.xwiki.filter.xar.input.XARInputProperties;
32    import org.xwiki.filter.xar.internal.XARAttachmentModel;
33    import org.xwiki.filter.xar.internal.XARFilterUtils.EventParameter;
34    import org.xwiki.filter.FilterException;
35   
36    /**
37    * @version $Id: 9267c589d264276a3fe4a7db97662fa2b32344e4 $
38    * @since 6.2M1
39    */
40    @Component
41    @Singleton
 
42    public class AttachmentReader extends AbstractReader implements XARXMLReader<AttachmentReader.WikiAttachment>
43    {
 
44    public static class WikiAttachment
45    {
46    public String name;
47   
48    public byte[] content;
49   
50    public FilterEventParameters parameters = new FilterEventParameters();
51   
 
52  452 toggle public void send(XARInputFilter proxyFilter) throws FilterException
53    {
54  452 proxyFilter.onWikiAttachment(this.name, new ByteArrayInputStream(this.content),
55    Long.valueOf(this.content.length), this.parameters);
56    }
57    }
58   
 
59  452 toggle @Override
60    public WikiAttachment read(XMLStreamReader xmlReader, XARInputProperties properties) throws XMLStreamException, FilterException
61    {
62  452 WikiAttachment wikiAttachment = new WikiAttachment();
63   
64  3641 for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
65  3189 String elementName = xmlReader.getLocalName();
66   
67  3189 String value = xmlReader.getElementText();
68   
69  3189 EventParameter parameter = XARAttachmentModel.ATTACHMENT_PARAMETERS.get(elementName);
70   
71  3189 if (parameter != null) {
72  1833 Object wsValue = convert(parameter.type, value);
73  1833 if (wsValue != null) {
74  1833 wikiAttachment.parameters.put(parameter.name, wsValue);
75    }
76    } else {
77  1356 if (XARAttachmentModel.ELEMENT_NAME.equals(elementName)) {
78  452 wikiAttachment.name = value;
79  904 } else if (XARAttachmentModel.ELEMENT_CONTENT.equals(elementName)) {
80  452 wikiAttachment.content = Base64.decodeBase64(value.getBytes());
81    }
82    }
83    }
84   
85  452 return wikiAttachment;
86    }
87    }