1212package com .maxprograms .xml ;
1313
1414import java .io .Serializable ;
15+ import java .text .MessageFormat ;
1516import java .util .List ;
1617import java .util .Stack ;
1718import java .util .StringTokenizer ;
@@ -65,7 +66,8 @@ public static ContentModel parse(String modelString) {
6566 if (string .startsWith ("(#PCDATA" )) {
6667 type = MIXED ;
6768 if (!string .endsWith (")*" )) {
68- throw new IllegalArgumentException ("Invalid mixed content model: " + string );
69+ MessageFormat mf = new MessageFormat (Messages .getString ("ContentModel.0" ));
70+ throw new IllegalArgumentException (mf .format (new Object [] { modelString }));
6971 }
7072 }
7173
@@ -87,13 +89,13 @@ public static ContentModel parse(String modelString) {
8789 current .add (groupParticle );
8890 } else if ("*" .equals (token ) || "+" .equals (token ) || "?" .equals (token )) {
8991 if (current .isEmpty ()) {
90- throw new IllegalArgumentException (
91- "Cardinality operator '" + token + "' must follow a valid particle." );
92+ MessageFormat mf = new MessageFormat ( Messages . getString ( "ContentModel.1" ));
93+ throw new IllegalArgumentException ( mf . format ( new Object [] { token }) );
9294 }
9395 Object lastObject = current .get (current .size () - 1 );
9496 if (!(lastObject instanceof ContentParticle )) {
95- throw new IllegalArgumentException (
96- "Cardinality operator '" + token + "' must follow a valid particle." );
97+ MessageFormat mf = new MessageFormat ( Messages . getString ( "ContentModel.1" ));
98+ throw new IllegalArgumentException ( mf . format ( new Object [] { token }) );
9799 }
98100 int cardinality = "?" .equals (token ) ? OPTIONAL : ("*" .equals (token ) ? ZEROMANY : ONEMANY );
99101 ((ContentParticle ) lastObject ).setCardinality (cardinality );
@@ -108,7 +110,8 @@ public static ContentModel parse(String modelString) {
108110
109111 for (Object obj : current ) {
110112 if (!(obj instanceof ContentParticle )) {
111- throw new IllegalArgumentException ("Invalid content model: " + string );
113+ MessageFormat mf = new MessageFormat (Messages .getString ("ContentModel.2" ));
114+ throw new IllegalArgumentException (mf .format (new Object [] { modelString }));
112115 }
113116 particles .add ((ContentParticle ) obj );
114117 }
@@ -118,7 +121,7 @@ public static ContentModel parse(String modelString) {
118121
119122 private static ContentParticle processGroup (List <Object > group ) {
120123 if (group .isEmpty ()) {
121- throw new IllegalArgumentException ("Empty group found in content model." );
124+ throw new IllegalArgumentException (Messages . getString ( "ContentModel.3" ) );
122125 }
123126 if (group .size () == 1 ) {
124127 Object obj = group .get (0 );
@@ -139,7 +142,8 @@ private static ContentParticle processGroup(List<Object> group) {
139142 }
140143 }
141144 if (sep == null ) {
142- throw new IllegalArgumentException ("No separator found in group: " + group );
145+ MessageFormat mf = new MessageFormat (Messages .getString ("ContentModel.4" ));
146+ throw new IllegalArgumentException (mf .format (new Object [] { group }));
143147 }
144148 ContentParticle result = "|" .equals (sep ) ? new DTDChoice () : new DTDSecuence ();
145149 for (Object obj : group ) {
@@ -163,17 +167,20 @@ private static void validateParentheses(String string) {
163167 else if (c == ')' )
164168 balance --;
165169 if (balance < 0 ) {
166- throw new IllegalArgumentException ("Unbalanced parentheses in content model: " + string );
170+ MessageFormat mf = new MessageFormat (Messages .getString ("ContentModel.5" ));
171+ throw new IllegalArgumentException (mf .format (new Object [] { string }));
167172 }
168173 }
169174 if (balance != 0 ) {
170- throw new IllegalArgumentException ("Unbalanced parentheses in content model: " + string );
175+ MessageFormat mf = new MessageFormat (Messages .getString ("ContentModel.5" ));
176+ throw new IllegalArgumentException (mf .format (new Object [] { string }));
171177 }
172178 }
173179
174180 private static void validateToken (String token ) {
175181 if (!token .matches ("[a-zA-Z0-9#|,?*+()]+" )) {
176- throw new IllegalArgumentException ("Invalid token in content model: " + token );
182+ MessageFormat mf = new MessageFormat (Messages .getString ("ContentModel.6" ));
183+ throw new IllegalArgumentException (mf .format (new Object [] { token }));
177184 }
178185 }
179186
0 commit comments