Clover Coverage Report - ARESTC 0.1.7-SNAPSHOT
Coverage timestamp: Fri Aug 27 2010 19:12:04 CEST
../../../../img/srcFileCovDistChart8.png 54% of files have more coverage
8   86   6   2
4   28   0.75   4
4     1.5  
1    
 
  TransformResponse       Line # 34 8 0% 6 4 75% 0.75
 
  (16)
 
1    /*
2    *
3    * (C)opyright 2010, Nikolaos Georgosopoulos
4    *
5    * This file is part of ARESTC.
6   
7    ARESTC is free software: you can redistribute it and/or modify
8    it under the terms of the Lesser General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11   
12    ARESTC is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    GNU General Public License for more details.
16   
17    You should have received a copy of the Lesser General Public License
18    along with ARESTC. If not, see <http://www.gnu.org/licenses/>.
19   
20    */
21    package net.sf.arestc.core;
22   
23    import java.io.InputStream;
24   
25   
26    import org.apache.commons.io.IOUtils;
27   
28    // TODO: Auto-generated Javadoc
29    /**
30    * The Class TransformResponse.
31    *
32    * @author georgosn
33    */
 
34    public class TransformResponse extends BaseCommand {
35   
36    /**
37    * Instantiates a new transform response.
38    */
 
39  0 toggle public TransformResponse() {
40  0 super();
41    }
42   
43    /**
44    * Instantiates a new transform response.
45    *
46    * @param next the next
47    */
 
48  18 toggle public TransformResponse(final ConnectorCommand next) {
49  18 super(next);
50    }
51   
52    /*
53    * (non-Javadoc)
54    *
55    * @see
56    * net.sf.arestc.core.BaseCommand#process(net.sf.arestc.core.ConnectorRequest
57    * , net.sf.arestc.core.ConnectorContext)
58    */
 
59  11 toggle @Override
60    public ConnectorContext process(final ConnectorRequest request,
61    final ConnectorContext context) throws CommandException {
62  11 context.setReturnedBody(request.getReturnTransformer().transform(
63    context.getReturnedBody()));
64  11 if (context.isReturnStream()) {
65  1 transformStream(context);
66    }
67   
68  11 return super.process(request, context);
69    }
70   
71    /**
72    * Transform stream.
73    *
74    * @param context
75    * the context
76    */
 
77  1 toggle private void transformStream(final ConnectorContext context) {
78   
79  1 if (!InputStream.class.isAssignableFrom(context.getReturnedBody()
80    .getClass())) {
81  0 context.setReturnedBody(IOUtils.toInputStream(context
82    .getReturnedBody().toString()));
83    }
84   
85    }
86    }