Coverage Report - net.sf.tacos.util.JSONMarkupWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
JSONMarkupWriter
35% 
100% 
1,088
 
 1  
 // Copyright May 16, 2006 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package net.sf.tacos.util;
 16  
 
 17  
 import org.apache.tapestry.IMarkupWriter;
 18  
 import org.apache.tapestry.NestedMarkupWriter;
 19  
 import org.apache.tapestry.json.JSONObject;
 20  
 import org.apache.tapestry.markup.Attribute;
 21  
 
 22  
 /**
 23  
  * A {@link IMarkupWriter} that only gathers attributes and
 24  
  * attribute values into a JSON structure.
 25  
  */
 26  
 public class JSONMarkupWriter implements IMarkupWriter
 27  
 {
 28  
     private JSONObject json;
 29  
     
 30  
     public JSONMarkupWriter()
 31  7
     {
 32  7
         json = new JSONObject();
 33  7
     }
 34  
     
 35  
     public JSONObject getAttributes()
 36  
     {
 37  7
         return json;
 38  
     }
 39  
 
 40  
     public void attribute(String name, int value)
 41  
     {
 42  4
         json.put(name, value);
 43  4
     }
 44  
 
 45  
     public void attribute(String name, boolean value)
 46  
     {
 47  3
         json.put(name, value);
 48  3
     }
 49  
 
 50  
     public void attribute(String name, String value)
 51  
     {
 52  
         // look for hints
 53  7
         if (name.endsWith("AsInt"))
 54  1
             attribute(name.substring(0, name.length() - 5), Integer.parseInt(value));
 55  6
         else if (name.endsWith("AsBoolean"))
 56  2
             attribute(name.substring(0, name.length() - 9), Boolean.valueOf(value).booleanValue());
 57  
         
 58  
         // look for known names
 59  4
         else if (name.endsWith("Duration"))
 60  2
             attribute(name, Integer.parseInt(value));
 61  
         else
 62  2
             json.put(name, value);
 63  7
     }
 64  
 
 65  
     public void attributeRaw(String name, String value)
 66  
     {
 67  0
         json.put(name, value);
 68  0
     }
 69  
     
 70  
     public void appendAttribute(String name, int value)
 71  
     {        
 72  0
     }
 73  
 
 74  
     public void appendAttribute(String name, boolean value)
 75  
     {        
 76  0
     }
 77  
 
 78  
     public void appendAttribute(String name, String value)
 79  
     {        
 80  0
     }
 81  
 
 82  
     public void appendAttributeRaw(String name, String value)
 83  
     {        
 84  0
     }
 85  
     
 86  
     public boolean hasAttribute(String name)
 87  
     {
 88  0
         return false;
 89  
     }
 90  
     
 91  
     public Attribute getAttribute(String name)
 92  
     {
 93  0
         return null;
 94  
     }
 95  
     
 96  
     public Attribute removeAttribute(String name)
 97  
     {
 98  0
         return null;
 99  
     }
 100  
     
 101  
     public void clearAttributes()
 102  
     {        
 103  0
     }
 104  
 
 105  
     public void begin(String name)
 106  
     {
 107  0
     }
 108  
 
 109  
     public void beginEmpty(String name)
 110  
     {
 111  0
     }
 112  
 
 113  
     public boolean checkError()
 114  
     {
 115  0
         return false;
 116  
     }
 117  
 
 118  
     public void close()
 119  
     {
 120  0
     }
 121  
 
 122  
     public void closeTag()
 123  
     {
 124  0
     }
 125  
 
 126  
     public void comment(String value)
 127  
     {
 128  0
     }
 129  
 
 130  
     public void end()
 131  
     {
 132  0
     }
 133  
 
 134  
     public void end(String name)
 135  
     {
 136  0
     }
 137  
 
 138  
     public void flush()
 139  
     {
 140  0
     }
 141  
 
 142  
     public NestedMarkupWriter getNestedWriter()
 143  
     {
 144  0
         return null;
 145  
     }
 146  
 
 147  
     public void print(char[] data, int offset, int length)
 148  
     {
 149  0
     }
 150  
 
 151  
     public void print(char[] data, int offset, int length, boolean raw)
 152  
     {
 153  0
     }
 154  
 
 155  
     public void print(char value)
 156  
     {
 157  0
     }
 158  
 
 159  
     public void print(int value)
 160  
     {
 161  0
     }
 162  
 
 163  
     public void print(String value)
 164  
     {
 165  0
     }
 166  
 
 167  
     public void print(String value, boolean raw)
 168  
     {
 169  0
     }
 170  
 
 171  
     public void println()
 172  
     {
 173  0
     }
 174  
 
 175  
     public void printRaw(char[] buffer, int offset, int length)
 176  
     {
 177  0
     }
 178  
 
 179  
     public void printRaw(String value)
 180  
     {
 181  0
     }
 182  
 
 183  
     public String getContentType()
 184  
     {
 185  0
         return "";
 186  
     }
 187  
     
 188  
 }