Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 158   Methods: 14
NCLOC: 86   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
PartialResponse.java 92.9% 80% 71.4% 80.9%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: PartialResponse.java 636946 2008-03-14 01:25:12Z natalia $
 18    */
 19   
 20    package org.apache.xindice.webadmin;
 21   
 22    import org.apache.xindice.util.XMLUtilities;
 23   
 24    import java.util.ArrayList;
 25   
 26    /**
 27    * PartialResponse represents response part of the multi-status response
 28    * document. Every partial response has its correspondent URL information
 29    * (href element) and one or more elements with additional request-specific
 30    * information.
 31    *
 32    * @version $Revision: 636946 $, $Date: 2008-03-14 01:25:12 +0000 (Fri, 14 Mar 2008) $
 33    */
 34    public class PartialResponse {
 35    private final String href;
 36    private ArrayList children;
 37   
 38  12 public PartialResponse(String href) {
 39  12 this.href = href;
 40    }
 41   
 42  0 public String getHref() {
 43  0 return href;
 44    }
 45   
 46    /**
 47    * Adds another element to the list of children of this partial response.
 48    *
 49    * @param name Element name
 50    * @param value Element value
 51    */
 52  0 public void addContent(String name, String value) {
 53  0 Content child = new Content(name);
 54  0 child.setValue(value);
 55  0 addContent(child);
 56    }
 57   
 58    /**
 59    * Adds another element to the list of children of this partial response.
 60    *
 61    * @param child Existing element
 62    */
 63  16 public void addContent(Content child) {
 64  16 if (children == null) {
 65  12 children = new ArrayList();
 66    }
 67  16 children.add(child);
 68    }
 69   
 70    /**
 71    * Builds XML out of partial response object.
 72    *
 73    * @return XML string
 74    */
 75  12 public String toString() {
 76  12 StringBuffer buf = new StringBuffer(1024);
 77  12 buf.append("<response>");
 78  12 buf.append("<href>").append(XMLUtilities.escape(href)).append("</href>");
 79   
 80  12 if (children != null && children.size() != 0) {
 81  12 for (int i = 0; i < children.size(); i++) {
 82  16 buf.append(((Content) children.get(i)).getContent());
 83    }
 84    }
 85   
 86  12 buf.append("</response>");
 87   
 88  12 return buf.toString();
 89    }
 90   
 91    /**
 92    * Content class holds request-specific information in a tree-like
 93    * structure. Every element of this tree can either be empty, have a
 94    * text value or hold children elements.
 95    */
 96    public static class Content {
 97    private ArrayList children;
 98    private String name;
 99    private String value;
 100   
 101  86 public Content(String name) {
 102  86 this.name = name;
 103    }
 104   
 105  43 public Content(String name, String value) {
 106  43 this.name = name;
 107  43 this.value = value;
 108    }
 109   
 110  16 public void setValue(String value) {
 111  16 this.value = value;
 112    }
 113   
 114  7 public Content addChild(String name) {
 115  7 Content child = new Content(name);
 116  7 addChild(child);
 117  7 return child;
 118    }
 119   
 120  0 public Content addChild(String name, String value) {
 121  0 Content child = addChild(name);
 122  0 child.setValue(value);
 123  0 return child;
 124    }
 125   
 126  90 public void addChild(Content child) {
 127  90 if (children == null) {
 128  39 children = new ArrayList();
 129    }
 130  90 children.add(child);
 131    }
 132   
 133  10 public String getValue() {
 134  10 return value;
 135    }
 136   
 137  104 private StringBuffer getContent() {
 138  104 StringBuffer buf = new StringBuffer(1024);
 139   
 140  104 buf.append("<").append(name).append(">");
 141  104 if (value != null) {
 142  39 buf.append(XMLUtilities.escape(value));
 143  65 } else if (children != null && children.size() != 0) {
 144  37 for (int i = 0; i < children.size(); i++) {
 145  88 buf.append(((Content) children.get(i)).getContent());
 146    }
 147    }
 148   
 149  104 buf.append("</").append(name).append(">");
 150   
 151  104 return buf;
 152    }
 153   
 154  0 public String toString() {
 155  0 return getContent().toString();
 156    }
 157    }
 158    }