|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| InternalEntityDecl.java | 83,3% | 70% | 62,5% | 70,4% |
|
||||||||||||||
| 1 | /* | |
| 2 | * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. | |
| 3 | * | |
| 4 | * This software is open source. | |
| 5 | * See the bottom of this file for the licence. | |
| 6 | * | |
| 7 | * $Id: InternalEntityDecl.java,v 1.7 2004/06/25 08:03:36 maartenc Exp $ | |
| 8 | */ | |
| 9 | ||
| 10 | package org.dom4j.dtd; | |
| 11 | ||
| 12 | /** <p><code>InternalEntityDecl</code> represents an internal entity declaration in a DTD.</p> | |
| 13 | * | |
| 14 | * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> | |
| 15 | * @version $Revision: 1.7 $ | |
| 16 | */ | |
| 17 | public class InternalEntityDecl { | |
| 18 | ||
| 19 | /** Holds value of property name. */ | |
| 20 | private String name; | |
| 21 | ||
| 22 | /** Holds value of property value. */ | |
| 23 | private String value; | |
| 24 | ||
| 25 | ||
| 26 | 0 | public InternalEntityDecl() { |
| 27 | } | |
| 28 | ||
| 29 | 38 | public InternalEntityDecl(String name, String value) { |
| 30 | 38 | this.name = name; |
| 31 | 38 | this.value = value; |
| 32 | } | |
| 33 | ||
| 34 | /** Getter for property name. | |
| 35 | * @return Value of property name. | |
| 36 | */ | |
| 37 | 12 | public String getName() { |
| 38 | 12 | return name; |
| 39 | } | |
| 40 | ||
| 41 | /** Setter for property name. | |
| 42 | * @param name New value of property name. | |
| 43 | */ | |
| 44 | 0 | public void setName(String name) { |
| 45 | 0 | this.name = name; |
| 46 | } | |
| 47 | ||
| 48 | /** Getter for property value. | |
| 49 | * @return Value of property value. | |
| 50 | */ | |
| 51 | 12 | public String getValue() { |
| 52 | 12 | return value; |
| 53 | } | |
| 54 | ||
| 55 | /** Setter for property value. | |
| 56 | * @param value New value of property value. | |
| 57 | */ | |
| 58 | 0 | public void setValue(String value) { |
| 59 | 0 | this.value = value; |
| 60 | } | |
| 61 | ||
| 62 | 44 | public String toString() { |
| 63 | 44 | StringBuffer buffer = new StringBuffer( "<!ENTITY " ); |
| 64 | ||
| 65 | 44 | if (name.startsWith("%")) { |
| 66 | 20 | buffer.append("% "); |
| 67 | 20 | buffer.append(name.substring(1)); |
| 68 | } | |
| 69 | else { | |
| 70 | 24 | buffer.append(name); |
| 71 | } | |
| 72 | ||
| 73 | 44 | buffer.append(" \""); |
| 74 | 44 | buffer.append(escapeEntityValue(value)); |
| 75 | 44 | buffer.append("\">"); |
| 76 | ||
| 77 | 44 | return buffer.toString(); |
| 78 | } | |
| 79 | ||
| 80 | 44 | private String escapeEntityValue(String text) { |
| 81 | 44 | StringBuffer result = new StringBuffer(); |
| 82 | 44 | for (int i = 0; i < text.length(); i++) { |
| 83 | 334 | char c = text.charAt(i); |
| 84 | 334 | switch (c) { |
| 85 | 0 | case '<': |
| 86 | 0 | result.append("&#60;"); |
| 87 | 0 | break; |
| 88 | 2 | case '>': |
| 89 | 2 | result.append(">"); |
| 90 | 2 | break; |
| 91 | 0 | case '&': |
| 92 | 0 | result.append("&#38;"); |
| 93 | 0 | break; |
| 94 | 0 | case '\'': |
| 95 | 0 | result.append("'"); |
| 96 | 0 | break; |
| 97 | 2 | case '\"': |
| 98 | 2 | result.append("""); |
| 99 | 2 | break; |
| 100 | 330 | default: |
| 101 | 330 | if (c < 32) { |
| 102 | 0 | result.append("&#" + (int) c + ";"); |
| 103 | } else { | |
| 104 | 330 | result.append(c); |
| 105 | } | |
| 106 | 330 | break; |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 | 44 | return result.toString(); |
| 111 | } | |
| 112 | ||
| 113 | } | |
| 114 | ||
| 115 | ||
| 116 | ||
| 117 | ||
| 118 | /* | |
| 119 | * Redistribution and use of this software and associated documentation | |
| 120 | * ("Software"), with or without modification, are permitted provided | |
| 121 | * that the following conditions are met: | |
| 122 | * | |
| 123 | * 1. Redistributions of source code must retain copyright | |
| 124 | * statements and notices. Redistributions must also contain a | |
| 125 | * copy of this document. | |
| 126 | * | |
| 127 | * 2. Redistributions in binary form must reproduce the | |
| 128 | * above copyright notice, this list of conditions and the | |
| 129 | * following disclaimer in the documentation and/or other | |
| 130 | * materials provided with the distribution. | |
| 131 | * | |
| 132 | * 3. The name "DOM4J" must not be used to endorse or promote | |
| 133 | * products derived from this Software without prior written | |
| 134 | * permission of MetaStuff, Ltd. For written permission, | |
| 135 | * please contact dom4j-info@metastuff.com. | |
| 136 | * | |
| 137 | * 4. Products derived from this Software may not be called "DOM4J" | |
| 138 | * nor may "DOM4J" appear in their names without prior written | |
| 139 | * permission of MetaStuff, Ltd. DOM4J is a registered | |
| 140 | * trademark of MetaStuff, Ltd. | |
| 141 | * | |
| 142 | * 5. Due credit should be given to the DOM4J Project - | |
| 143 | * http://www.dom4j.org | |
| 144 | * | |
| 145 | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS | |
| 146 | * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT | |
| 147 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 148 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
| 149 | * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 150 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 151 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 152 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 153 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
| 154 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 155 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
| 156 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 157 | * | |
| 158 | * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. | |
| 159 | * | |
| 160 | * $Id: InternalEntityDecl.java,v 1.7 2004/06/25 08:03:36 maartenc Exp $ | |
| 161 | */ |
|
||||||||||