1 16 package org.apache.cocoon.components.serializers.util; 17 18 import org.apache.commons.lang.builder.EqualsBuilder; 19 import org.apache.commons.lang.builder.HashCodeBuilder; 20 21 28 public class DocType { 29 30 private static final char S_DOCTYPE_1[] = "<!DOCTYPE ".toCharArray(); 31 private static final char S_DOCTYPE_2[] = " PUBLIC \"".toCharArray(); 32 private static final char S_DOCTYPE_3[] = "\" \"".toCharArray(); 33 private static final char S_DOCTYPE_4[] = " SYSTEM \"".toCharArray(); 34 private static final char S_DOCTYPE_5[] = "\">".toCharArray(); 35 private static final char S_DOCTYPE_6[] = ">".toCharArray(); 36 37 38 protected String root_name = null; 39 40 protected String public_id = null; 41 42 protected String system_id = null; 43 44 49 public DocType(String root_name) { 50 this(root_name, null, null); 51 } 52 53 59 public DocType(String root_name, String system_id) { 60 this(root_name, null, system_id); 61 } 62 63 70 public DocType(String root_name, String public_id, String system_id) { 71 super(); 72 if (root_name == null) 73 throw new NullPointerException ("Invalid root document name"); 74 75 if ((public_id != null) && (system_id == null)) 76 throw new NullPointerException ("Required System ID is NULL"); 77 78 this.root_name = root_name; 79 this.public_id = public_id; 80 this.system_id = system_id; 81 } 82 83 86 public String getName() { 87 return(this.root_name); 88 } 89 90 94 public String getPublicId() { 95 return(this.public_id); 96 } 97 98 102 public String getSystemId() { 103 return(this.system_id); 104 } 105 106 109 public String toString() { 110 StringBuffer buf = new StringBuffer (); 111 112 buf.append(S_DOCTYPE_1); buf.append(this.root_name); 114 if (this.public_id != null) { 115 buf.append(S_DOCTYPE_2); buf.append(this.public_id); 117 118 if (this.system_id != null) { 119 buf.append(S_DOCTYPE_3); buf.append(this.system_id); 121 } 122 buf.append(S_DOCTYPE_5); } else if (this.system_id != null) { 124 buf.append(S_DOCTYPE_4); buf.append(this.system_id); 126 buf.append(S_DOCTYPE_5); } else { 128 buf.append(S_DOCTYPE_6); } 130 return(buf.toString()); 131 } 132 133 137 public boolean equals(Object object) { 138 if (!(object instanceof DocType)) { 139 return false; 140 } 141 DocType rhs = (DocType)object; 142 return new EqualsBuilder() 143 .appendSuper(super.equals(object)) 144 .append(public_id, rhs.public_id) 145 .append(system_id, rhs.system_id) 146 .append(root_name, rhs.root_name) 147 .isEquals(); 148 } 149 150 153 public int hashCode() { 154 return new HashCodeBuilder() 155 .appendSuper(super.hashCode()) 156 .append(public_id) 157 .append(system_id) 158 .append(root_name) 159 .toHashCode(); 160 } 161 } 162 | Popular Tags |