KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tax > TreeUtilities


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.tax;
20
21 import java.util.Map JavaDoc;
22 import java.util.TreeMap JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.io.ByteArrayInputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.InputStreamReader JavaDoc;
27
28 import org.netbeans.tax.spec.AttlistDecl;
29 import org.netbeans.tax.spec.Attribute;
30 import org.netbeans.tax.spec.CDATASection;
31 import org.netbeans.tax.spec.CharacterReference;
32 import org.netbeans.tax.spec.Comment;
33 import org.netbeans.tax.spec.ConditionalSection;
34 import org.netbeans.tax.spec.DocumentFragment;
35 import org.netbeans.tax.spec.Document;
36 import org.netbeans.tax.spec.DocumentType;
37 import org.netbeans.tax.spec.DTD;
38 import org.netbeans.tax.spec.ElementDecl;
39 import org.netbeans.tax.spec.Element;
40 import org.netbeans.tax.spec.EntityDecl;
41 import org.netbeans.tax.spec.GeneralEntityReference;
42 import org.netbeans.tax.spec.NotationDecl;
43 import org.netbeans.tax.spec.ParameterEntityReference;
44 import org.netbeans.tax.spec.ProcessingInstruction;
45 import org.netbeans.tax.spec.Text;
46
47 /**
48  *
49  * @author Libor Kramolis
50  * @version 0.1
51  */

52 public final class TreeUtilities {
53     
54     /** */
55     private static Constraints constraints = new Constraints ();
56     
57     
58     //
59
// Node.Constraints
60
//
61

62     /**
63      */

64     public static final void checkAttributeName (TreeName treeName) throws InvalidArgumentException {
65         constraints.checkAttributeName (treeName);
66     }
67     
68     /**
69      */

70     public static final boolean isValidAttributeName (TreeName treeName) {
71         return constraints.isValidAttributeName (treeName);
72     }
73     
74     /**
75      */

76     public static final void checkElementTagName (TreeName elementTreeName) throws InvalidArgumentException {
77         constraints.checkElementTagName (elementTreeName);
78     }
79     
80     /**
81      */

82     public static final boolean isValidElementTagName (TreeName elementTreeName) {
83         return constraints.isValidElementTagName (elementTreeName);
84     }
85     
86     /**
87      */

88     public static final void checkNotationDeclSystemId (String JavaDoc systemId) throws InvalidArgumentException {
89         constraints.checkNotationDeclSystemId (systemId);
90     }
91     
92     /**
93      */

94     public static final boolean isValidNotationDeclSystemId (String JavaDoc systemId) {
95         return constraints.isValidNotationDeclSystemId (systemId);
96     }
97     
98     /**
99      */

100     public static final void checkDocumentEncoding (String JavaDoc encoding) throws InvalidArgumentException {
101         constraints.checkDocumentEncoding (encoding);
102     }
103     
104     /**
105      */

106     public static final boolean isValidDocumentEncoding (String JavaDoc encoding) {
107         return constraints.isValidDocumentEncoding (encoding);
108     }
109     
110     /**
111      */

112     public static final void checkDTDEncoding (String JavaDoc encoding) throws InvalidArgumentException {
113         constraints.checkDTDEncoding (encoding);
114     }
115     
116     /**
117      */

118     public static final boolean isValidDTDEncoding (String JavaDoc encoding) {
119         return constraints.isValidDTDEncoding (encoding);
120     }
121     
122     /**
123      */

124     public static final void checkCharacterReferenceName (String JavaDoc name) throws InvalidArgumentException {
125         constraints.checkCharacterReferenceName (name);
126     }
127     
128     /**
129      */

130     public static final boolean isValidCharacterReferenceName (String JavaDoc name) {
131         return constraints.isValidCharacterReferenceName (name);
132     }
133     
134     /**
135      */

136     public static final void checkEntityDeclInternalText (String JavaDoc internalText) throws InvalidArgumentException {
137         constraints.checkEntityDeclInternalText (internalText);
138     }
139     
140     /**
141      */

142     public static final boolean isValidEntityDeclInternalText (String JavaDoc internalText) {
143         return constraints.isValidEntityDeclInternalText (internalText);
144     }
145     
146     /**
147      */

148     public static final void checkAttlistDeclElementName (String JavaDoc elementName) throws InvalidArgumentException {
149         constraints.checkAttlistDeclElementName (elementName);
150     }
151     
152     /**
153      */

154     public static final boolean isValidAttlistDeclElementName (String JavaDoc elementName) {
155         return constraints.isValidAttlistDeclElementName (elementName);
156     }
157     
158     /**
159      */

160     public static final void checkDTDVersion (String JavaDoc version) throws InvalidArgumentException {
161         constraints.checkDTDVersion (version);
162     }
163     
164     /**
165      */

166     public static final boolean isValidDTDVersion (String JavaDoc version) {
167         return constraints.isValidDTDVersion (version);
168     }
169     
170     /**
171      */

172     public static final void checkDocumentTypeSystemId (String JavaDoc systemId) throws InvalidArgumentException {
173         constraints.checkDocumentTypeSystemId (systemId);
174     }
175     
176     /**
177      */

178     public static final boolean isValidDocumentTypeSystemId (String JavaDoc systemId) {
179         return constraints.isValidDocumentTypeSystemId (systemId);
180     }
181     
182     /**
183      */

184     public static final void checkDocumentTypeElementName (String JavaDoc elementName) throws InvalidArgumentException {
185         constraints.checkDocumentTypeElementName (elementName);
186     }
187     
188     /**
189      */

190     public static final boolean isValidDocumentTypeElementName (String JavaDoc elementName) {
191         return constraints.isValidDocumentTypeElementName (elementName);
192     }
193     
194     /**
195      */

196     public static final void checkDocumentStandalone (String JavaDoc standalone) throws InvalidArgumentException {
197         constraints.checkDocumentStandalone (standalone);
198     }
199     
200     /**
201      */

202     public static final boolean isValidDocumentStandalone (String JavaDoc standalone) {
203         return constraints.isValidDocumentStandalone (standalone);
204     }
205     
206     /**
207      */

208     public static final void checkEntityDeclName (String JavaDoc name) throws InvalidArgumentException {
209         constraints.checkEntityDeclName (name);
210     }
211     
212     /**
213      */

214     public static final boolean isValidEntityDeclName (String JavaDoc name) {
215         return constraints.isValidEntityDeclName (name);
216     }
217     
218     /**
219      */

220     public static final void checkAttlistDeclAttributeEnumeratedType (String JavaDoc[] enumeratedType) throws InvalidArgumentException {
221         constraints.checkAttlistDeclAttributeEnumeratedType (enumeratedType);
222     }
223     
224     /**
225      */

226     public static final boolean isValidAttlistDeclAttributeEnumeratedType (String JavaDoc[] enumeratedType) {
227         return constraints.isValidAttlistDeclAttributeEnumeratedType (enumeratedType);
228     }
229     
230     /**
231      */

232     public static final void checkProcessingInstructionData (String JavaDoc data) throws InvalidArgumentException {
233         constraints.checkProcessingInstructionData (data);
234     }
235     
236     /**
237      */

238     public static final boolean isValidProcessingInstructionData (String JavaDoc data) {
239         return constraints.isValidProcessingInstructionData (data);
240     }
241     
242     /**
243      */

244     public static final void checkEntityDeclNotationName (String JavaDoc notationName) throws InvalidArgumentException {
245         constraints.checkEntityDeclNotationName (notationName);
246     }
247     
248     /**
249      */

250     public static final boolean isValidEntityDeclNotationName (String JavaDoc notationName) {
251         return constraints.isValidEntityDeclNotationName (notationName);
252     }
253     
254     /**
255      */

256     public static final void checkElementDeclName (String JavaDoc name) throws InvalidArgumentException {
257         constraints.checkElementDeclName (name);
258     }
259     
260     /**
261      */

262     public static final boolean isValidElementDeclName (String JavaDoc name) {
263         return constraints.isValidElementDeclName (name);
264     }
265     
266     /**
267      */

268     public static final void checkGeneralEntityReferenceName (String JavaDoc name) throws InvalidArgumentException {
269         constraints.checkGeneralEntityReferenceName (name);
270     }
271     
272     /**
273      */

274     public static final boolean isValidGeneralEntityReferenceName (String JavaDoc name) {
275         return constraints.isValidGeneralEntityReferenceName (name);
276     }
277     
278     /**
279      */

280     public static final void checkEntityDeclSystemId (String JavaDoc systemId) throws InvalidArgumentException {
281         constraints.checkEntityDeclSystemId (systemId);
282     }
283     
284     /**
285      */

286     public static final boolean isValidEntityDeclSystemId (String JavaDoc systemId) {
287         return constraints.isValidEntityDeclSystemId (systemId);
288     }
289     
290     /**
291      */

292     public static final void checkProcessingInstructionTarget (String JavaDoc target) throws InvalidArgumentException {
293         constraints.checkProcessingInstructionTarget (target);
294     }
295     
296     /**
297      */

298     public static final boolean isValidProcessingInstructionTarget (String JavaDoc target) {
299         return constraints.isValidProcessingInstructionTarget (target);
300     }
301     
302     /**
303      */

304     public static final void checkEntityDeclPublicId (String JavaDoc publicId) throws InvalidArgumentException {
305         constraints.checkEntityDeclPublicId (publicId);
306     }
307     
308     /**
309      */

310     public static final boolean isValidEntityDeclPublicId (String JavaDoc publicId) {
311         return constraints.isValidEntityDeclPublicId (publicId);
312     }
313     
314     /**
315      */

316     public static final void checkAttlistDeclAttributeDefaultValue (String JavaDoc defaultValue) throws InvalidArgumentException {
317         constraints.checkAttlistDeclAttributeDefaultValue (defaultValue);
318     }
319     
320     /**
321      */

322     public static final boolean isValidAttlistDeclAttributeDefaultValue (String JavaDoc defaultValue) {
323         return constraints.isValidAttlistDeclAttributeDefaultValue (defaultValue);
324     }
325     
326     /**
327      */

328     public static final void checkDocumentFragmentVersion (String JavaDoc version) throws InvalidArgumentException {
329         constraints.checkDocumentFragmentVersion (version);
330     }
331     
332     /**
333      */

334     public static final boolean isValidDocumentFragmentVersion (String JavaDoc version) {
335         return constraints.isValidDocumentFragmentVersion (version);
336     }
337     
338     /**
339      */

340     public static final void checkNotationDeclName (String JavaDoc name) throws InvalidArgumentException {
341         constraints.checkNotationDeclName (name);
342     }
343     
344     /**
345      */

346     public static final boolean isValidNotationDeclName (String JavaDoc name) {
347         return constraints.isValidNotationDeclName (name);
348     }
349     
350     /**
351      */

352     public static final void checkAttributeValue (String JavaDoc value) throws InvalidArgumentException {
353         constraints.checkAttributeValue (value);
354     }
355     
356     /**
357      */

358     public static final boolean isValidAttributeValue (String JavaDoc value) {
359         return constraints.isValidAttributeValue (value);
360     }
361     
362     /**
363      */

364     public static final void checkParameterEntityReferenceName (String JavaDoc name) throws InvalidArgumentException {
365         constraints.checkParameterEntityReferenceName (name);
366     }
367     
368     /**
369      */

370     public static final boolean isValidParameterEntityReferenceName (String JavaDoc name) {
371         return constraints.isValidParameterEntityReferenceName (name);
372     }
373     
374     /**
375      */

376     public static final void checkDocumentFragmentEncoding (String JavaDoc encoding) throws InvalidArgumentException {
377         constraints.checkDocumentFragmentEncoding (encoding);
378     }
379     
380     /**
381      */

382     public static final boolean isValidDocumentFragmentEncoding (String JavaDoc encoding) {
383         return constraints.isValidDocumentFragmentEncoding (encoding);
384     }
385     
386     /**
387      */

388     public static final void checkTextData (String JavaDoc data) throws InvalidArgumentException {
389         constraints.checkTextData (data);
390     }
391     
392     /**
393      */

394     public static final boolean isValidTextData (String JavaDoc data) {
395         return constraints.isValidTextData (data);
396     }
397     
398     /**
399      */

400     public static final void checkDocumentTypePublicId (String JavaDoc publicId) throws InvalidArgumentException {
401         constraints.checkDocumentTypePublicId (publicId);
402     }
403     
404     /**
405      */

406     public static final boolean isValidDocumentTypePublicId (String JavaDoc publicId) {
407         return constraints.isValidDocumentTypePublicId (publicId);
408     }
409     
410     /**
411      */

412     public static final void checkElementDeclContentType (TreeElementDecl.ContentType contentType) throws InvalidArgumentException {
413         constraints.checkElementDeclContentType (contentType);
414     }
415     
416     /**
417      */

418     public static final boolean isValidElementDeclContentType (TreeElementDecl.ContentType contentType) {
419         return constraints.isValidElementDeclContentType (contentType);
420     }
421     
422     /**
423      */

424     public static final void checkDocumentVersion (String JavaDoc version) throws InvalidArgumentException {
425         constraints.checkDocumentVersion (version);
426     }
427     
428     /**
429      */

430     public static final boolean isValidDocumentVersion (String JavaDoc version) {
431         return constraints.isValidDocumentVersion (version);
432     }
433     
434     /**
435      */

436     public static final void checkCDATASectionData (String JavaDoc data) throws InvalidArgumentException {
437         constraints.checkCDATASectionData (data);
438     }
439     
440     /**
441      */

442     public static final boolean isValidCDATASectionData (String JavaDoc data) {
443         return constraints.isValidCDATASectionData (data);
444     }
445     
446     /**
447      */

448     public static final void checkNotationDeclPublicId (String JavaDoc publicId) throws InvalidArgumentException {
449         constraints.checkNotationDeclPublicId (publicId);
450     }
451     
452     /**
453      */

454     public static final boolean isValidNotationDeclPublicId (String JavaDoc publicId) {
455         return constraints.isValidNotationDeclPublicId (publicId);
456     }
457     
458     /**
459      */

460     public static final void checkAttlistDeclAttributeName (String JavaDoc attributeName) throws InvalidArgumentException {
461         constraints.checkAttlistDeclAttributeName (attributeName);
462     }
463     
464     /**
465      */

466     public static final boolean isValidAttlistDeclAttributeName (String JavaDoc attributeName) {
467         return constraints.isValidAttlistDeclAttributeName (attributeName);
468     }
469     
470     /**
471      */

472     public static final void checkCommentData (String JavaDoc data) throws InvalidArgumentException {
473         constraints.checkCommentData (data);
474     }
475     
476     /**
477      */

478     public static final boolean isValidCommentData (String JavaDoc data) {
479         return constraints.isValidCommentData (data);
480     }
481     
482     /**
483      */

484     public static final void checkAttlistDeclAttributeType (short type) throws InvalidArgumentException {
485         constraints.checkAttlistDeclAttributeType (type);
486     }
487     
488     /**
489      */

490     public static final boolean isValidAttlistDeclAttributeType (short type) {
491         return constraints.isValidAttlistDeclAttributeType (type);
492     }
493     
494     /**
495      */

496     public static final void checkAttlistDeclAttributeDefaultType (short defaultType) throws InvalidArgumentException {
497         constraints.checkAttlistDeclAttributeDefaultType (defaultType);
498     }
499     
500     /**
501      */

502     public static final boolean isValidAttlistDeclAttributeDefaultType (short defaultType) {
503         return constraints.isValidAttlistDeclAttributeDefaultType (defaultType);
504     }
505     
506     
507     
508     //
509
// Constraints
510
//
511

512     /**
513      *
514      */

515     private static final class Constraints extends UnicodeClasses
516     implements AttlistDecl.Constraints,
517     Attribute.Constraints,
518     CDATASection.Constraints,
519     CharacterReference.Constraints,
520     Comment.Constraints,
521     ConditionalSection.Constraints,
522     DocumentFragment.Constraints,
523     Document.Constraints,
524     DocumentType.Constraints,
525     DTD.Constraints,
526     ElementDecl.Constraints,
527     Element.Constraints,
528     EntityDecl.Constraints,
529     GeneralEntityReference.Constraints,
530     NotationDecl.Constraints,
531     ParameterEntityReference.Constraints,
532     ProcessingInstruction.Constraints,
533     Text.Constraints {
534         
535         
536         //
537
// itself
538
//
539

540         /**
541          */

542         private static void checkNullArgument (String JavaDoc argName, Object JavaDoc argValue) throws InvalidArgumentException {
543             if ( argValue == null ) {
544                 throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_null_value"));
545             }
546         }
547         
548         /**
549          */

550         private static void checkEmptyString (String JavaDoc argName, String JavaDoc string, boolean trim) throws InvalidArgumentException {
551             if ( (string.length () == 0) || (trim && (string.trim ().equals (""))) ) { // NOI18N
552
throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_empty_value"));
553             }
554         }
555         
556         
557         
558         //
559
// global constraints
560
//
561

562         /**
563          * @see http://www.w3.org/TR/REC-xml#NT-Name
564          */

565         private static void checkXMLName (String JavaDoc argName, String JavaDoc name) throws InvalidArgumentException {
566             checkNullArgument (argName, name);
567             checkEmptyString (argName, name, true);
568             
569             char first = name.charAt (0);
570             if (!!! isXMLNameStartChar (first)) {
571                 throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_first_char", String.valueOf (first)));
572             }
573             
574             for (int i = 0, len = name.length (); i < len; i++) {
575                 char c = name.charAt (i);
576                 if (!!! isXMLNameChar (c)) {
577                     throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_content_char", String.valueOf (c)));
578                 }
579             }
580         }
581         
582         /**
583          * @see http://www.w3.org/TR/REC-xml#NT-Nmtoken
584          */

585         private static void checkNmToken (String JavaDoc argName, String JavaDoc token) throws InvalidArgumentException {
586             
587             checkNullArgument (argName, token);
588             checkEmptyString (argName, token, true);
589             
590             for (int i = 0, len = token.length (); i < len; i++) {
591                 char c = token.charAt (i);
592                 if (!!! isXMLNameChar (c)) {
593                     throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_content_char", String.valueOf (c)));
594                 }
595             }
596             
597         }
598         
599         /**
600          * @see http://www.w3.org/TR/REC-xml-names/#NT-NCName
601          */

602         private static void checkXMLNCName (String JavaDoc argName, String JavaDoc name) throws InvalidArgumentException {
603             checkNullArgument (argName, name);
604             checkEmptyString (argName, name, true);
605             
606             char first = name.charAt (0);
607             if (!!! isXMLNCNameStartChar (first)) {
608                 throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_first_char", String.valueOf (first)));
609             }
610             
611             for (int i = 0, len = name.length (); i < len; i++) {
612                 char c = name.charAt (i);
613                 if (!!! isXMLNCNameChar (c)) {
614                     throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_content_char", String.valueOf (c)));
615                 }
616             }
617         }
618         
619         /**
620          */

621         private static void checkNamespacePrefix (String JavaDoc prefix) throws InvalidArgumentException {
622             String JavaDoc argName = Util.THIS.getString ("PROP_NamespacePrefix");
623             checkXMLNCName (argName, prefix);
624         }
625         
626         /**
627          */

628         private static void checkNamespaceURI (String JavaDoc uri) throws InvalidArgumentException {
629             String JavaDoc argName = Util.THIS.getString ("PROP_NamespaceURI");
630             checkAttributeValue (argName, uri);
631         }
632         
633         
634         
635         /**
636          */

637         private static void checkElementName (String JavaDoc argName, String JavaDoc name) throws InvalidArgumentException {
638             checkNullArgument (argName, name);
639             checkXMLName (argName, name);
640         }
641         
642         /**
643          */

644         private static void checkAttributeName (String JavaDoc argName, String JavaDoc name) throws InvalidArgumentException {
645             checkNullArgument (argName, name);
646             checkXMLName (argName, name);
647         }
648         
649         /**
650          */

651         private static void checkAttributeValue (String JavaDoc argName, String JavaDoc value) throws InvalidArgumentException {
652             checkNullArgument (argName, value);
653             checkCharacterData (argName, value);
654             
655             int index = value.indexOf ('<');
656             if ( index != -1 ) {
657                 throw new InvalidArgumentException (argName, Util.THIS.getString ("EXC_invalid_attribute_value", value));
658             }
659             index = value.indexOf ('&');
660             if ( index != -1 ) {
661                 throw new InvalidArgumentException (argName, Util.THIS.getString ("EXC_invalid_attribute_value", value));
662             }
663             
664             boolean apostrofFound = false;
665             boolean quoteFound = false;
666             for (int i = 0, len = value.length (); i < len; i++) {
667                 char c = value.charAt (i);
668                 if (c == '\'')
669                     if (quoteFound)
670                         throw new InvalidArgumentException (argName, Util.THIS.getString ("EXC_invalid_attribute_value", value));
671                     else
672                         apostrofFound = true;
673                 if (c == '"')
674                     if (apostrofFound)
675                         throw new InvalidArgumentException (argName, Util.THIS.getString ("EXC_invalid_attribute_value", value));
676                     else
677                         quoteFound = true;
678             }
679         }
680         
681         /**
682          */

683         private static void checkCharacterData (String JavaDoc argName, String JavaDoc text) throws InvalidArgumentException {
684             checkNullArgument (argName, text);
685             
686             // do check
687
for (int i = 0, len = text.length (); i < len; i++) {
688                 char c = text.charAt (i);
689                 if (!!! isXMLChar (c)) {
690                     throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_content_char", "0x" + Integer.toHexString (c))); // NOI18N
691
}
692             }
693         }
694         
695         /**
696          */

697         private static void checkSystemId (String JavaDoc argName, String JavaDoc systemId) throws InvalidArgumentException {
698             boolean apostrofFound = false;
699             boolean quoteFound = false;
700             for (int i = 0, len = systemId.length (); i < len; i++) {
701                 char c = systemId.charAt (i);
702                 if (c == '\'')
703                     if (quoteFound)
704                         throw new InvalidArgumentException (argName, Util.THIS.getString ("EXC_Invalid_system_id", systemId));
705                     else
706                         apostrofFound = true;
707                 if (c == '"')
708                     if (apostrofFound)
709                         throw new InvalidArgumentException (argName, Util.THIS.getString ("EXC_Invalid_system_id", systemId));
710                     else
711                         quoteFound = true;
712             }
713         }
714         
715         /**
716          */

717         private static void checkPublicId (String JavaDoc argName, String JavaDoc publicId) throws InvalidArgumentException {
718             boolean apostrofFound = false;
719             boolean quoteFound = false;
720             for (int i = 0, len = publicId.length (); i < len; i++) {
721                 char c = publicId.charAt (i);
722                 if (c == '\'') {
723                     if (quoteFound) {
724                         throw new InvalidArgumentException (argName, Util.THIS.getString ("EXC_Invalid_public_id", publicId));
725                     } else {
726                         apostrofFound = true;
727                     }
728                 } else if (c == '"') {
729                     if (apostrofFound) {
730                         throw new InvalidArgumentException (argName, Util.THIS.getString ("EXC_Invalid_public_id", publicId));
731                     } else {
732                         quoteFound = true;
733                     }
734                 } else if ( isXMLPubidLiteral (c) == false ) {
735                     throw new InvalidArgumentException (argName, Util.THIS.getString ("EXC_Invalid_public_id", publicId));
736                 }
737             }
738         }
739         
740         /**
741          */

742         private static void checkNotationName (String JavaDoc argName, String JavaDoc name) throws InvalidArgumentException {
743             checkNullArgument (argName, name);
744             checkXMLName (argName, name);
745         }
746         
747         
748         /**
749          */

750         private static void checkEncoding (String JavaDoc argName, String JavaDoc encoding) throws InvalidArgumentException {
751             if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TreeUtilities::checkEncoding: encoding = " + encoding); // NOI18N
752

753             ByteArrayInputStream JavaDoc stream = new ByteArrayInputStream JavaDoc (new byte[0]);
754             
755             if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" ::checkEncoding: stream = " + stream); // NOI18N
756

757             try {
758                 InputStreamReader JavaDoc reader = new InputStreamReader JavaDoc (stream, iana2java (encoding));
759                 
760                 if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" ::checkEncoding: reader = " + reader); // NOI18N
761
} catch (IOException JavaDoc exc) {
762                 if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" ::checkEncoding: IOException !!!", exc); // NOI18N
763

764                 throw new InvalidArgumentException (argName, Util.THIS.getString ("EXC_Invalid_encoding", encoding));
765             }
766         }
767         
768         
769         /**
770          */

771         public void checkAttributeName (TreeName treeName) throws InvalidArgumentException {
772             String JavaDoc argName = Util.THIS.getString ("PROP_AttributeName");
773             checkAttributeName (argName, treeName.getQualifiedName ());
774         }
775         
776         /**
777          */

778         public boolean isValidAttributeName (TreeName treeName) {
779             try {
780                 checkAttributeName (treeName);
781             } catch (InvalidArgumentException exc) {
782                 return false;
783             }
784             return true;
785         }
786         
787         
788         /**
789          */

790         public void checkElementTagName (TreeName elementTreeName) throws InvalidArgumentException {
791             checkElementName (Util.THIS.getString ("PROP_ElementTagName"), elementTreeName.getQualifiedName ());
792         }
793         
794         /**
795          */

796         public boolean isValidElementTagName (TreeName elementTreeName) {
797             try {
798                 checkElementTagName (elementTreeName);
799             } catch (InvalidArgumentException exc) {
800                 return false;
801             }
802             return true;
803         }
804         
805         
806         /**
807          */

808         public void checkNotationDeclSystemId (String JavaDoc systemId) throws InvalidArgumentException {
809             if ( systemId == null ) {
810                 return;
811             }
812             checkSystemId (Util.THIS.getString ("PROP_NotationDeclSystemId"), systemId);
813         }
814         
815         /**
816          */

817         public boolean isValidNotationDeclSystemId (String JavaDoc systemId) {
818             try {
819                 checkNotationDeclSystemId (systemId);
820             } catch (InvalidArgumentException exc) {
821                 return false;
822             }
823             return true;
824         }
825         
826         
827         /**
828          */

829         public void checkDocumentEncoding (String JavaDoc encoding) throws InvalidArgumentException {
830             if ( encoding == null )
831                 return;
832             checkEncoding (Util.THIS.getString ("PROP_DocumentEncoding"), encoding);
833         }
834         
835         /**
836          */

837         public boolean isValidDocumentEncoding (String JavaDoc encoding) {
838             try {
839                 checkDocumentEncoding (encoding);
840             } catch (InvalidArgumentException exc) {
841                 return false;
842             }
843             return true;
844         }
845         
846         
847         /**
848          */

849         public void checkDTDEncoding (String JavaDoc encoding) throws InvalidArgumentException {
850             if ( encoding == null )
851                 return;
852             checkEncoding (Util.THIS.getString ("PROP_DTDEncoding"), encoding);
853         }
854         
855         /**
856          */

857         public boolean isValidDTDEncoding (String JavaDoc encoding) {
858             try {
859                 checkDTDEncoding (encoding);
860             } catch (InvalidArgumentException exc) {
861                 return false;
862             }
863             return true;
864         }
865         
866         
867         /**
868          */

869         public void checkCharacterReferenceName (String JavaDoc name) throws InvalidArgumentException {
870             String JavaDoc argName = Util.THIS.getString ("PROP_CharacterReferenceName");
871             
872             checkNullArgument (argName, name);
873             checkEmptyString (argName, name, true);
874             
875             int i = 0;
876             char first = name.charAt (i);
877             if ( first != '#' ) {
878                 throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_first_char", String.valueOf (first)));
879             }
880             
881             i++;
882             if ( name.length () <= i ) {
883                 throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_empty_value"));
884             }
885             
886             char second = name.charAt (i);
887             int radix = 10;
888             if ( second == 'x' ) {
889                 radix = 16;
890                 
891                 i++;
892                 if ( name.length () <= i ) {
893                     throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_empty_value"));
894                 }
895             }
896             String JavaDoc number = name.substring (i);
897             try {
898                 Short.parseShort (number, radix);
899             } catch (NumberFormatException JavaDoc exc) {
900                 throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_content_char", number));
901             }
902             
903 /* for (int len = name.length(); i < len; i++) {
904                 char c = name.charAt (i);
905                 if ( Character.digit (c, radix) == -1 ) {
906                     throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_content_char", String.valueOf (c)));
907                 }
908             }*/

909         }
910         
911         /**
912          */

913         public boolean isValidCharacterReferenceName (String JavaDoc name) {
914             try {
915                 checkCharacterReferenceName (name);
916             } catch (InvalidArgumentException exc) {
917                 return false;
918             }
919             return true;
920         }
921         
922         
923         /**
924          */

925         public void checkEntityDeclInternalText (String JavaDoc internalText) throws InvalidArgumentException {
926             checkNullArgument (Util.THIS.getString ("PROP_EntityDeclInternalText"), internalText);
927             boolean apostrofFound = false;
928             boolean quoteFound = false;
929             for (int i = 0, len = internalText.length (); i < len; i++) {
930                 char c = internalText.charAt (i);
931                 if (c == '\'')
932                     if (quoteFound)
933                         throw new InvalidArgumentException (Util.THIS.getString ("PROP_EntityDeclInternalText"), Util.THIS.getString ("EXC_Invalid_Entity_Decl_Internal_text", internalText));
934                     else
935                         apostrofFound = true;
936                 if (c == '"')
937                     if (apostrofFound)
938                         throw new InvalidArgumentException (Util.THIS.getString ("PROP_EntityDeclInternalText"), Util.THIS.getString ("EXC_Invalid_Entity_Decl_Internal_text", internalText));
939                     else
940                         quoteFound = true;
941                 // todo
942
// if (c == '%' || c == '&')
943
// throw new InvalidArgumentException ("EntityDeclInternalText", Util.THIS.getString ("EXC_Invalid_Entity_Decl_Internal_text", internalText));
944
}
945         }
946         
947         
948         /**
949          */

950         public boolean isValidEntityDeclInternalText (String JavaDoc internalText) {
951             try {
952                 checkEntityDeclInternalText (internalText);
953             } catch (InvalidArgumentException exc) {
954                 return false;
955             }
956             return true;
957         }
958         
959         
960         /**
961          */

962         public void checkAttlistDeclElementName (String JavaDoc elementName) throws InvalidArgumentException {
963             checkElementName (Util.THIS.getString ("PROP_AttlistDeclElementName"), elementName);
964         }
965         
966         /**
967          */

968         public boolean isValidAttlistDeclElementName (String JavaDoc elementName) {
969             try {
970                 checkAttlistDeclElementName (elementName);
971             } catch (InvalidArgumentException exc) {
972                 return false;
973             }
974             return true;
975         }
976         
977         
978         /**
979          */

980         public void checkDTDVersion (String JavaDoc version) throws InvalidArgumentException {
981             if (version == null)
982                 return;
983             if (!!! version.equals ("1.0")) { // NOI18N
984
String JavaDoc arg = Util.THIS.getString ("PROP_DTDVersion");
985                 String JavaDoc msg = Util.THIS.getString ("PROP_invalid_version_number", version);
986                 throw new InvalidArgumentException (arg, msg);
987             }
988         }
989         
990         /**
991          */

992         public boolean isValidDTDVersion (String JavaDoc version) {
993             try {
994                 checkDTDVersion (version);
995             } catch (InvalidArgumentException exc) {
996                 return false;
997             }
998             return true;
999         }
1000        
1001        
1002        /**
1003         */

1004        public void checkDocumentTypeSystemId (String JavaDoc systemId) throws InvalidArgumentException {
1005            if ( systemId == null ) {
1006                return;
1007            }
1008            checkSystemId (Util.THIS.getString ("PROP_DocumentTypeSystemId"), systemId);
1009        }
1010        
1011        /**
1012         */

1013        public boolean isValidDocumentTypeSystemId (String JavaDoc systemId) {
1014            try {
1015                checkDocumentTypeSystemId (systemId);
1016            } catch (InvalidArgumentException exc) {
1017                return false;
1018            }
1019            return true;
1020        }
1021        
1022        
1023        /**
1024         */

1025        public void checkDocumentTypeElementName (String JavaDoc elementName) throws InvalidArgumentException {
1026            checkElementName (Util.THIS.getString ("PROP_DocumentTypeElementName"), elementName);
1027        }
1028        
1029        /**
1030         */

1031        public boolean isValidDocumentTypeElementName (String JavaDoc elementName) {
1032            try {
1033                checkDocumentTypeElementName (elementName);
1034            } catch (InvalidArgumentException exc) {
1035                return false;
1036            }
1037            return true;
1038        }
1039        
1040        
1041        /**
1042         */

1043        public void checkDocumentStandalone (String JavaDoc standalone) throws InvalidArgumentException {
1044            if (standalone == null)
1045                return;
1046            if (standalone.equals ("yes")) // NOI18N
1047
return;
1048            if (standalone.equals ("no")) // NOI18N
1049
return;
1050            throw new InvalidArgumentException (standalone, standalone + Util.THIS.getString ("PROP_is_not_valid_standalone_value"));
1051        }
1052        
1053        /**
1054         */

1055        public boolean isValidDocumentStandalone (String JavaDoc standalone) {
1056            try {
1057                checkDocumentStandalone (standalone);
1058            } catch (InvalidArgumentException exc) {
1059                return false;
1060            }
1061            return true;
1062        }
1063        
1064        
1065        /**
1066         */

1067        public void checkEntityDeclName (String JavaDoc name) throws InvalidArgumentException {
1068            checkXMLName (Util.THIS.getString ("PROP_EntityDeclName"), name);
1069        }
1070        
1071        /**
1072         */

1073        public boolean isValidEntityDeclName (String JavaDoc name) {
1074            try {
1075                checkEntityDeclName (name);
1076            } catch (InvalidArgumentException exc) {
1077                return false;
1078            }
1079            return true;
1080        }
1081        
1082        
1083        /**
1084         */

1085        public void checkAttlistDeclAttributeEnumeratedType (String JavaDoc[] enumeratedType) throws InvalidArgumentException {
1086            if ( enumeratedType == null ) {
1087                return;
1088            }
1089            for (int i = 0, len = enumeratedType.length; i < len; i++)
1090                checkNmToken (Util.THIS.getString ("PROP_AttlistDeclAttributeEnumeratedType"), enumeratedType[i]);
1091        }
1092        
1093        /**
1094         */

1095        public boolean isValidAttlistDeclAttributeEnumeratedType (String JavaDoc[] enumeratedType) {
1096            try {
1097                checkAttlistDeclAttributeEnumeratedType (enumeratedType);
1098            } catch (InvalidArgumentException exc) {
1099                return false;
1100            }
1101            return true;
1102        }
1103        
1104        
1105        /**
1106         */

1107        public void checkProcessingInstructionData (String JavaDoc data) throws InvalidArgumentException {
1108            checkCharacterData (Util.THIS.getString ("PROP_ProcessingInstructionData"), data);
1109            
1110            int index = data.indexOf ("?>"); // NOI18N
1111
if (index != -1) {
1112                throw new InvalidArgumentException (data, Util.THIS.getString ("PROP_invalid_processing_instruction_data"));
1113            }
1114        }
1115        
1116        /**
1117         */

1118        public boolean isValidProcessingInstructionData (String JavaDoc data) {
1119            try {
1120                checkProcessingInstructionData (data);
1121            } catch (InvalidArgumentException exc) {
1122                return false;
1123            }
1124            return true;
1125        }
1126        
1127        /**
1128         */

1129        public void checkEntityDeclNotationName (String JavaDoc notationName) throws InvalidArgumentException {
1130            if ( notationName == null ) {
1131                return;
1132            }
1133            checkNotationName (Util.THIS.getString ("PROP_EntityDeclNotationName"), notationName);
1134        }
1135        
1136        /**
1137         */

1138        public boolean isValidEntityDeclNotationName (String JavaDoc notationName) {
1139            try {
1140                checkEntityDeclNotationName (notationName);
1141            } catch (InvalidArgumentException exc) {
1142                return false;
1143            }
1144            return true;
1145        }
1146        
1147        
1148        /**
1149         */

1150        public void checkElementDeclName (String JavaDoc name) throws InvalidArgumentException {
1151            checkElementName (Util.THIS.getString ("PROP_ElementDeclName"), name);
1152        }
1153        
1154        /**
1155         */

1156        public boolean isValidElementDeclName (String JavaDoc name) {
1157            try {
1158                checkElementDeclName (name);
1159            } catch (InvalidArgumentException exc) {
1160                return false;
1161            }
1162            return true;
1163        }
1164        
1165        
1166        /**
1167         */

1168        public void checkGeneralEntityReferenceName (String JavaDoc name) throws InvalidArgumentException {
1169            checkXMLName (Util.THIS.getString ("PROP_GeneralEntityReferenceName"), name);
1170        }
1171        
1172        /**
1173         */

1174        public boolean isValidGeneralEntityReferenceName (String JavaDoc name) {
1175            try {
1176                checkGeneralEntityReferenceName (name);
1177            } catch (InvalidArgumentException exc) {
1178                return false;
1179            }
1180            return true;
1181        }
1182        
1183        
1184        /**
1185         */

1186        public void checkEntityDeclSystemId (String JavaDoc systemId) throws InvalidArgumentException {
1187            if ( systemId == null ) {
1188                return;
1189            }
1190            checkSystemId (Util.THIS.getString ("PROP_EntityDeclSystemId"), systemId);
1191        }
1192        
1193        /**
1194         */

1195        public boolean isValidEntityDeclSystemId (String JavaDoc systemId) {
1196            try {
1197                checkEntityDeclSystemId (systemId);
1198            } catch (InvalidArgumentException exc) {
1199                return false;
1200            }
1201            return true;
1202        }
1203        
1204        
1205        /**
1206         */

1207        public void checkProcessingInstructionTarget (String JavaDoc target) throws InvalidArgumentException {
1208            String JavaDoc argName = Util.THIS.getString ("PROP_ProcessingInstructionTarget");
1209            checkXMLName (argName, target);
1210            
1211            if (target.equalsIgnoreCase ("xml")) { // NOI18N
1212
throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_content_char", target));
1213            }
1214        }
1215        
1216        /**
1217         */

1218        public boolean isValidProcessingInstructionTarget (String JavaDoc target) {
1219            try {
1220                checkProcessingInstructionTarget (target);
1221            } catch (InvalidArgumentException exc) {
1222                return false;
1223            }
1224            return true;
1225        }
1226        
1227        
1228        /**
1229         */

1230        public void checkEntityDeclPublicId (String JavaDoc publicId) throws InvalidArgumentException {
1231            if ( publicId == null ) {
1232                return;
1233            }
1234            checkPublicId (Util.THIS.getString ("PROP_EntityDeclPublicId"), publicId);
1235        }
1236        
1237        
1238        /**
1239         */

1240        public boolean isValidEntityDeclPublicId (String JavaDoc publicId) {
1241            try {
1242                checkEntityDeclPublicId (publicId);
1243            } catch (InvalidArgumentException exc) {
1244                return false;
1245            }
1246            return true;
1247        }
1248        
1249        
1250        /**
1251         */

1252        public void checkAttlistDeclAttributeDefaultValue (String JavaDoc defaultValue) throws InvalidArgumentException {
1253            if ( defaultValue == null ) {
1254                return;
1255            }
1256            boolean apostrofFound = false;
1257            boolean quoteFound = false;
1258            for (int i = 0, len = defaultValue.length (); i < len; i++) {
1259                char c = defaultValue.charAt (i);
1260                if (c == '\'')
1261                    if (quoteFound)
1262                        throw new InvalidArgumentException (Util.THIS.getString ("PROP_AttlistDeclAttributeDefaultValue"), Util.THIS.getString ("EXC_invalid_attribute_default_value", defaultValue));
1263                    else
1264                        apostrofFound = true;
1265                if (c == '"')
1266                    if (apostrofFound)
1267                        throw new InvalidArgumentException (Util.THIS.getString ("PROP_AttlistDeclAttributeDefaultValue"), Util.THIS.getString ("EXC_invalid_attribute_default_value", defaultValue));
1268                    else
1269                        quoteFound = true;
1270                // todo
1271
// if (c == '%' || c == '&')
1272
// throw new InvalidArgumentException ("AttlistDeclAttributeDefaultValue", Util.THIS.getString ("EXC_invalid_attribute_default_value", defaultValue));
1273
}
1274        }
1275        
1276        /**
1277         */

1278        public boolean isValidAttlistDeclAttributeDefaultValue (String JavaDoc defaultValue) {
1279            try {
1280                checkAttlistDeclAttributeDefaultValue (defaultValue);
1281            } catch (InvalidArgumentException exc) {
1282                return false;
1283            }
1284            return true;
1285        }
1286        
1287        
1288        /**
1289         */

1290        public void checkDocumentFragmentVersion (String JavaDoc version) throws InvalidArgumentException {
1291            if ( version == null )
1292                return;
1293            if (!!! version.equals ("1.0")) { // NOI18N
1294
String JavaDoc arg = Util.THIS.getString ("PROP_DocumentFragmentVersion");
1295                String JavaDoc msg = Util.THIS.getString ("PROP_invalid_version_number", version);
1296                throw new InvalidArgumentException (arg, msg);
1297            }
1298        }
1299        
1300        /**
1301         */

1302        public boolean isValidDocumentFragmentVersion (String JavaDoc version) {
1303            try {
1304                checkDocumentFragmentVersion (version);
1305            } catch (InvalidArgumentException exc) {
1306                return false;
1307            }
1308            return true;
1309        }
1310        
1311        
1312        /**
1313         */

1314        public void checkNotationDeclName (String JavaDoc name) throws InvalidArgumentException {
1315            checkXMLName (Util.THIS.getString ("PROP_NotationDeclName"), name);
1316        }
1317        
1318        /**
1319         */

1320        public boolean isValidNotationDeclName (String JavaDoc name) {
1321            try {
1322                checkNotationDeclName (name);
1323            } catch (InvalidArgumentException exc) {
1324                return false;
1325            }
1326            return true;
1327        }
1328        
1329        
1330        /**
1331         */

1332        public void checkAttributeValue (String JavaDoc value) throws InvalidArgumentException {
1333            String JavaDoc argName = Util.THIS.getString ("PROP_AttributeValue");
1334            checkAttributeValue (argName, value);
1335        }
1336        
1337        /**
1338         */

1339        public boolean isValidAttributeValue (String JavaDoc value) {
1340            try {
1341                checkAttributeValue (value);
1342            } catch (InvalidArgumentException exc) {
1343                return false;
1344            }
1345            return true;
1346        }
1347        
1348        
1349        /**
1350         */

1351        public void checkParameterEntityReferenceName (String JavaDoc name) throws InvalidArgumentException {
1352            checkXMLName (Util.THIS.getString ("PROP_ParameterEntityReferenceName"), name);
1353        }
1354        
1355        /**
1356         */

1357        public boolean isValidParameterEntityReferenceName (String JavaDoc name) {
1358            try {
1359                checkParameterEntityReferenceName (name);
1360            } catch (InvalidArgumentException exc) {
1361                return false;
1362            }
1363            return true;
1364        }
1365        
1366        
1367        /**
1368         */

1369        public void checkDocumentFragmentEncoding (String JavaDoc encoding) throws InvalidArgumentException {
1370            if ( encoding == null )
1371                return;
1372            checkEncoding (Util.THIS.getString ("PROP_DocumentFragmentEncoding"), encoding);
1373        }
1374        
1375        /**
1376         */

1377        public boolean isValidDocumentFragmentEncoding (String JavaDoc encoding) {
1378            try {
1379                checkDocumentFragmentEncoding (encoding);
1380            } catch (InvalidArgumentException exc) {
1381                return false;
1382            }
1383            return true;
1384        }
1385        
1386        
1387        /**
1388         */

1389        public void checkTextData (String JavaDoc data) throws InvalidArgumentException {
1390            String JavaDoc argName = Util.THIS.getString ("PROP_TextData");
1391            checkCharacterData (argName, data);
1392            checkEmptyString (argName, data, false);
1393            
1394            int index = data.indexOf ('<');
1395            if ( index != -1 ) {
1396                throw new InvalidArgumentException (data, Util.THIS.getString ("PROP_invalid_text_data"));
1397            }
1398            index = data.indexOf ('&');
1399            if ( index != -1 ) {
1400                throw new InvalidArgumentException (data, Util.THIS.getString ("PROP_invalid_text_data"));
1401            }
1402            index = data.indexOf ("]]>");
1403            if ( index != -1 ) {
1404                throw new InvalidArgumentException (data, Util.THIS.getString ("PROP_invalid_text_data"));
1405            }
1406        }
1407        
1408        /**
1409         */

1410        public boolean isValidTextData (String JavaDoc data) {
1411            try {
1412                checkTextData (data);
1413            } catch (InvalidArgumentException exc) {
1414                return false;
1415            }
1416            return true;
1417        }
1418        
1419        
1420        /**
1421         */

1422        public void checkDocumentTypePublicId (String JavaDoc publicId) throws InvalidArgumentException {
1423            if ( publicId == null ) {
1424                return;
1425            }
1426            checkPublicId (Util.THIS.getString ("PROP_DocumentTypePublicId"), publicId);
1427        }
1428        
1429        /**
1430         */

1431        public boolean isValidDocumentTypePublicId (String JavaDoc publicId) {
1432            try {
1433                checkDocumentTypePublicId (publicId);
1434            } catch (InvalidArgumentException exc) {
1435                return false;
1436            }
1437            return true;
1438        }
1439        
1440        
1441        /**
1442         */

1443        public void checkElementDeclContentType (TreeElementDecl.ContentType contentType) throws InvalidArgumentException {
1444            checkNullArgument (Util.THIS.getString ("PROP_ElementDeclContentType"), contentType);
1445            // if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("[PENDING]: TreeUtilities::TreeConstraints.checkElementDeclContentType"); // NOI18N
1446
}
1447        
1448        /**
1449         */

1450        public boolean isValidElementDeclContentType (TreeElementDecl.ContentType contentType) {
1451            try {
1452                checkElementDeclContentType (contentType);
1453            } catch (InvalidArgumentException exc) {
1454                return false;
1455            }
1456            return true;
1457        }
1458        
1459        
1460        /**
1461         */

1462        public void checkDocumentVersion (String JavaDoc version) throws InvalidArgumentException {
1463            if ( version == null )
1464                return;
1465            if (!!! version.equals ("1.0")) { // NOI18N
1466
String JavaDoc arg = Util.THIS.getString ("PROP_DocumentVersion");
1467                String JavaDoc msg = Util.THIS.getString ("PROP_invalid_version_number", version);
1468                throw new InvalidArgumentException (arg, msg);
1469            }
1470        }
1471        
1472        /**
1473         */

1474        public boolean isValidDocumentVersion (String JavaDoc version) {
1475            try {
1476                checkDocumentVersion (version);
1477            } catch (InvalidArgumentException exc) {
1478                return false;
1479            }
1480            return true;
1481        }
1482        
1483        
1484        /**
1485         */

1486        public void checkCDATASectionData (String JavaDoc data) throws InvalidArgumentException {
1487            checkCharacterData (Util.THIS.getString ("PROP_CDATASectionData"), data);
1488            
1489            int index = data.indexOf ("]]>"); // NOI18N
1490
if (index != -1) {
1491                throw new InvalidArgumentException (data, Util.THIS.getString ("PROP_invalid_cdata_section_data"));
1492            }
1493        }
1494        
1495        /**
1496         */

1497        public boolean isValidCDATASectionData (String JavaDoc data) {
1498            try {
1499                checkCDATASectionData (data);
1500            } catch (InvalidArgumentException exc) {
1501                return false;
1502            }
1503            return true;
1504        }
1505        
1506        
1507        /**
1508         */

1509        public void checkNotationDeclPublicId (String JavaDoc publicId) throws InvalidArgumentException {
1510            if ( publicId == null ) {
1511                return;
1512            }
1513            checkPublicId (Util.THIS.getString ("PROP_NotationDeclPublicId"), publicId);
1514        }
1515        
1516        /**
1517         */

1518        public boolean isValidNotationDeclPublicId (String JavaDoc publicId) {
1519            try {
1520                checkNotationDeclPublicId (publicId);
1521            } catch (InvalidArgumentException exc) {
1522                return false;
1523            }
1524            return true;
1525        }
1526        
1527        
1528        /**
1529         */

1530        public void checkAttlistDeclAttributeName (String JavaDoc attributeName) throws InvalidArgumentException {
1531            checkAttributeName (Util.THIS.getString ("PROP_AttlistDeclAttributeName"), attributeName);
1532        }
1533        
1534        /**
1535         */

1536        public boolean isValidAttlistDeclAttributeName (String JavaDoc attributeName) {
1537            try {
1538                checkAttlistDeclAttributeName (attributeName);
1539            } catch (InvalidArgumentException exc) {
1540                return false;
1541            }
1542            return true;
1543        }
1544        
1545        
1546        /**
1547         */

1548        public void checkCommentData (String JavaDoc data) throws InvalidArgumentException {
1549            checkCharacterData (Util.THIS.getString ("PROP_CommentData"), data);
1550            
1551            int index = data.indexOf ("--"); // NOI18N
1552
if (index != -1) {
1553                throw new InvalidArgumentException (data, Util.THIS.getString ("PROP_invalid_comment_data"));
1554            }
1555            if (data.endsWith ("-")) { // NOI18N
1556
throw new InvalidArgumentException (data, Util.THIS.getString ("PROP_invalid_comment_data_end"));
1557            }
1558        }
1559        
1560        /**
1561         */

1562        public boolean isValidCommentData (String JavaDoc data) {
1563            try {
1564                checkCommentData (data);
1565            } catch (InvalidArgumentException exc) {
1566                return false;
1567            }
1568            return true;
1569        }
1570        
1571        /**
1572         */

1573        public void checkAttlistDeclAttributeType (short type) throws InvalidArgumentException {
1574            if (( type != TreeAttlistDeclAttributeDef.TYPE_CDATA ) &&
1575            ( type != TreeAttlistDeclAttributeDef.TYPE_ID ) &&
1576            ( type != TreeAttlistDeclAttributeDef.TYPE_IDREF ) &&
1577            ( type != TreeAttlistDeclAttributeDef.TYPE_IDREFS ) &&
1578            ( type != TreeAttlistDeclAttributeDef.TYPE_ENTITY ) &&
1579            ( type != TreeAttlistDeclAttributeDef.TYPE_ENTITIES ) &&
1580            ( type != TreeAttlistDeclAttributeDef.TYPE_NMTOKEN ) &&
1581            ( type != TreeAttlistDeclAttributeDef.TYPE_NMTOKENS ) &&
1582            ( type != TreeAttlistDeclAttributeDef.TYPE_ENUMERATED ) &&
1583            ( type != TreeAttlistDeclAttributeDef.TYPE_NOTATION ) ) {
1584                throw new InvalidArgumentException (new Short JavaDoc (type), Util.THIS.getString ("PROP_invalid_attribute_list_declaration_type"));
1585            }
1586        }
1587        
1588        /**
1589         */

1590        public boolean isValidAttlistDeclAttributeType (short type) {
1591            try {
1592                checkAttlistDeclAttributeType (type);
1593            } catch (InvalidArgumentException exc) {
1594                return false;
1595            }
1596            return true;
1597        }
1598        
1599        /**
1600         */

1601        public void checkAttlistDeclAttributeDefaultType (short defaultType) throws InvalidArgumentException {
1602            if (( defaultType != TreeAttlistDeclAttributeDef.DEFAULT_TYPE_NULL ) &&
1603            ( defaultType != TreeAttlistDeclAttributeDef.DEFAULT_TYPE_REQUIRED ) &&
1604            ( defaultType != TreeAttlistDeclAttributeDef.DEFAULT_TYPE_IMPLIED ) &&
1605            ( defaultType != TreeAttlistDeclAttributeDef.DEFAULT_TYPE_FIXED ) ) {
1606                throw new InvalidArgumentException (new Short JavaDoc (defaultType), Util.THIS.getString ("PROP_invalid_attribute_list_declaration_default_type"));
1607            }
1608        }
1609        
1610        /**
1611         */

1612        public boolean isValidAttlistDeclAttributeDefaultType (short defaultType) {
1613            try {
1614                checkAttlistDeclAttributeDefaultType (defaultType);
1615            } catch (InvalidArgumentException exc) {
1616                return false;
1617            }
1618            return true;
1619        }
1620        
1621    } // end: class Constraints
1622

1623    
1624    //
1625
// Encoding
1626
//
1627

1628    /**
1629     */

1630    public static final Collection JavaDoc getSupportedEncodings () {
1631        return EncodingUtil.getIANA2JavaMap ().keySet ();
1632    }
1633    
1634    /**
1635     */

1636    public static final String JavaDoc iana2java (String JavaDoc iana) {
1637        String JavaDoc java = (String JavaDoc) EncodingUtil.getIANA2JavaMap ().get (iana.toUpperCase ());
1638        return java == null ? iana : java;
1639    }
1640
1641
1642    /**
1643     //!!! this code is copy pasted to xml.core.lib.Convertors!
1644     */

1645    static class EncodingUtil {
1646        
1647        /** IANA to Java encoding mappings */
1648        protected final static Map JavaDoc encodingIANA2JavaMap = new TreeMap JavaDoc ();
1649        
1650        /** */
1651        protected final static Map JavaDoc encodingIANADescriptionMap = new TreeMap JavaDoc ();
1652        
1653        /** */
1654        protected final static Map JavaDoc encodingIANAAliasesMap = new TreeMap JavaDoc ();
1655        
1656        //
1657
// Static initialization
1658
//
1659

1660        static {
1661            encodingIANA2JavaMap.put ("BIG5", "Big5"); // NOI18N
1662
encodingIANADescriptionMap.put ("BIG5", Util.THIS.getString ("NAME_BIG5")); // NOI18N
1663
encodingIANAAliasesMap.put ("BIG5", "BIG5"); // NOI18N
1664

1665            encodingIANA2JavaMap.put ("IBM037", "CP037"); // NOI18N
1666
encodingIANADescriptionMap.put ("IBM037", Util.THIS.getString ("NAME_IBM037")); // NOI18N
1667
encodingIANAAliasesMap.put ("IBM037", "IBM037"); // NOI18N
1668
encodingIANAAliasesMap.put ("EBCDIC-CP-US", "IBM037"); // NOI18N
1669
encodingIANAAliasesMap.put ("EBCDIC-CP-CA", "IBM037"); // NOI18N
1670
encodingIANAAliasesMap.put ("EBCDIC-CP-NL", "IBM037"); // NOI18N
1671
encodingIANAAliasesMap.put ("EBCDIC-CP-WT", "IBM037"); // NOI18N
1672

1673            encodingIANA2JavaMap.put ("IBM277", "CP277"); // NOI18N
1674
encodingIANADescriptionMap.put ("IBM277", Util.THIS.getString ("NAME_IBM277")); // NOI18N
1675
encodingIANAAliasesMap.put ("IBM277", "IBM277"); // NOI18N
1676
encodingIANAAliasesMap.put ("EBCDIC-CP-DK", "IBM277"); // NOI18N
1677
encodingIANAAliasesMap.put ("EBCDIC-CP-NO", "IBM277"); // NOI18N
1678

1679            encodingIANA2JavaMap.put ("IBM278", "CP278"); // NOI18N
1680
encodingIANADescriptionMap.put ("IBM278", Util.THIS.getString ("NAME_IBM277")); // NOI18N
1681
encodingIANAAliasesMap.put ("IBM278", "IBM278"); // NOI18N
1682
encodingIANAAliasesMap.put ("EBCDIC-CP-FI", "IBM278"); // NOI18N
1683
encodingIANAAliasesMap.put ("EBCDIC-CP-SE", "IBM278"); // NOI18N
1684

1685            encodingIANA2JavaMap.put ("IBM280", "CP280"); // NOI18N
1686
encodingIANADescriptionMap.put ("IBM280", Util.THIS.getString ("NAME_IBM280")); // NOI18N
1687
encodingIANAAliasesMap.put ("IBM280", "IBM280"); // NOI18N
1688
encodingIANAAliasesMap.put ("EBCDIC-CP-IT", "IBM280"); // NOI18N
1689

1690            encodingIANA2JavaMap.put ("IBM284", "CP284"); // NOI18N
1691
encodingIANADescriptionMap.put ("IBM284", Util.THIS.getString ("NAME_IBM284")); // NOI18N
1692
encodingIANAAliasesMap.put ("IBM284", "IBM284"); // NOI18N
1693
encodingIANAAliasesMap.put ("EBCDIC-CP-ES", "IBM284"); // NOI18N
1694

1695            encodingIANA2JavaMap.put ("IBM285", "CP285"); // NOI18N
1696
encodingIANADescriptionMap.put ("IBM285", Util.THIS.getString ("NAME_IBM285")); // NOI18N
1697
encodingIANAAliasesMap.put ("IBM285", "IBM285"); // NOI18N
1698
encodingIANAAliasesMap.put ("EBCDIC-CP-GB", "IBM285"); // NOI18N
1699

1700            encodingIANA2JavaMap.put ("IBM297", "CP297"); // NOI18N
1701
encodingIANADescriptionMap.put ("IBM297", Util.THIS.getString ("NAME_IBM297")); // NOI18N
1702
encodingIANAAliasesMap.put ("IBM297", "IBM297"); // NOI18N
1703
encodingIANAAliasesMap.put ("EBCDIC-CP-FR", "IBM297"); // NOI18N
1704

1705            encodingIANA2JavaMap.put ("IBM424", "CP424"); // NOI18N
1706
encodingIANADescriptionMap.put ("IBM424", Util.THIS.getString ("NAME_IBM424")); // NOI18N
1707
encodingIANAAliasesMap.put ("IBM424", "IBM424"); // NOI18N
1708
encodingIANAAliasesMap.put ("EBCDIC-CP-HE", "IBM424"); // NOI18N
1709

1710            encodingIANA2JavaMap.put ("IBM500", "CP500"); // NOI18N
1711
encodingIANADescriptionMap.put ("IBM500", Util.THIS.getString ("NAME_IBM500")); // NOI18N
1712
encodingIANAAliasesMap.put ("IBM500", "IBM500"); // NOI18N
1713
encodingIANAAliasesMap.put ("EBCDIC-CP-CH", "IBM500"); // NOI18N
1714
encodingIANAAliasesMap.put ("EBCDIC-CP-BE", "IBM500"); // NOI18N
1715

1716            encodingIANA2JavaMap.put ("IBM870", "CP870"); // NOI18N
1717
encodingIANADescriptionMap.put ("IBM870", Util.THIS.getString ("NAME_IBM870")); // NOI18N
1718
encodingIANAAliasesMap.put ("IBM870", "IBM870"); // NOI18N
1719
encodingIANAAliasesMap.put ("EBCDIC-CP-ROECE", "IBM870"); // NOI18N
1720
encodingIANAAliasesMap.put ("EBCDIC-CP-YU", "IBM870"); // NOI18N
1721

1722            encodingIANA2JavaMap.put ("IBM871", "CP871"); // NOI18N
1723
encodingIANADescriptionMap.put ("IBM871", Util.THIS.getString ("NAME_IBM871")); // NOI18N
1724
encodingIANAAliasesMap.put ("IBM871", "IBM871"); // NOI18N
1725
encodingIANAAliasesMap.put ("EBCDIC-CP-IS", "IBM871"); // NOI18N
1726

1727            encodingIANA2JavaMap.put ("IBM918", "CP918"); // NOI18N
1728
encodingIANADescriptionMap.put ("IBM918", Util.THIS.getString ("NAME_IBM918")); // NOI18N
1729
encodingIANAAliasesMap.put ("IBM918", "IBM918"); // NOI18N
1730
encodingIANAAliasesMap.put ("EBCDIC-CP-AR2", "IBM918"); // NOI18N
1731

1732            encodingIANA2JavaMap.put ("EUC-JP", "EUCJIS"); // NOI18N
1733
encodingIANADescriptionMap.put ("EUC-JP", Util.THIS.getString ("NAME_EUC-JP")); // NOI18N
1734
encodingIANAAliasesMap.put ("EUC-JP", "EUC-JP"); // NOI18N
1735

1736            encodingIANA2JavaMap.put ("EUC-KR", "KSC5601"); // NOI18N
1737
encodingIANADescriptionMap.put ("EUC-KR", Util.THIS.getString ("NAME_EUC-KR")); // NOI18N
1738
encodingIANAAliasesMap.put ("EUC-KR", "EUC-KR"); // NOI18N
1739

1740            encodingIANA2JavaMap.put ("GB2312", "GB2312"); // NOI18N
1741
encodingIANADescriptionMap.put ("GB2312", Util.THIS.getString ("NAME_GB2312")); // NOI18N
1742
encodingIANAAliasesMap.put ("GB2312", "GB2312"); // NOI18N
1743

1744            encodingIANA2JavaMap.put ("ISO-2022-JP", "JIS"); // NOI18N
1745
encodingIANADescriptionMap.put ("ISO-2022-JP", Util.THIS.getString ("NAME_ISO-2022-JP")); // NOI18N
1746
encodingIANAAliasesMap.put ("ISO-2022-JP", "ISO-2022-JP"); // NOI18N
1747

1748            encodingIANA2JavaMap.put ("ISO-2022-KR", "ISO2022KR"); // NOI18N
1749
encodingIANADescriptionMap.put ("ISO-2022-KR", Util.THIS.getString ("NAME_ISO-2022-KR")); // NOI18N
1750
encodingIANAAliasesMap.put ("ISO-2022-KR", "ISO-2022-KR"); // NOI18N
1751

1752            encodingIANA2JavaMap.put ("ISO-8859-1", "8859_1"); // NOI18N
1753
encodingIANADescriptionMap.put ("ISO-8859-1", Util.THIS.getString ("NAME_ISO-8859-1")); // NOI18N
1754
encodingIANAAliasesMap.put ("ISO-8859-1", "ISO-8859-1"); // NOI18N
1755
encodingIANAAliasesMap.put ("LATIN1", "ISO-8859-1"); // NOI18N
1756
encodingIANAAliasesMap.put ("L1", "ISO-8859-1"); // NOI18N
1757
encodingIANAAliasesMap.put ("IBM819", "ISO-8859-1"); // NOI18N
1758
encodingIANAAliasesMap.put ("CP819", "ISO-8859-1"); // NOI18N
1759

1760            encodingIANA2JavaMap.put ("ISO-8859-2", "8859_2"); // NOI18N
1761
encodingIANADescriptionMap.put ("ISO-8859-2", Util.THIS.getString ("NAME_ISO-8859-2")); // NOI18N
1762
encodingIANAAliasesMap.put ("ISO-8859-2", "ISO-8859-2"); // NOI18N
1763
encodingIANAAliasesMap.put ("LATIN2", "ISO-8859-2"); // NOI18N
1764
encodingIANAAliasesMap.put ("L2", "ISO-8859-2"); // NOI18N
1765

1766            encodingIANA2JavaMap.put ("ISO-8859-3", "8859_3"); // NOI18N
1767
encodingIANADescriptionMap.put ("ISO-8859-3", Util.THIS.getString ("NAME_ISO-8859-3")); // NOI18N
1768
encodingIANAAliasesMap.put ("ISO-8859-3", "ISO-8859-3"); // NOI18N
1769
encodingIANAAliasesMap.put ("LATIN3", "ISO-8859-3"); // NOI18N
1770
encodingIANAAliasesMap.put ("L3", "ISO-8859-3"); // NOI18N
1771

1772            encodingIANA2JavaMap.put ("ISO-8859-4", "8859_4"); // NOI18N
1773
encodingIANADescriptionMap.put ("ISO-8859-4", Util.THIS.getString ("NAME_ISO-8859-4")); // NOI18N
1774
encodingIANAAliasesMap.put ("ISO-8859-4", "ISO-8859-4"); // NOI18N
1775
encodingIANAAliasesMap.put ("LATIN4", "ISO-8859-4"); // NOI18N
1776
encodingIANAAliasesMap.put ("L4", "ISO-8859-4"); // NOI18N
1777

1778            encodingIANA2JavaMap.put ("ISO-8859-5", "8859_5"); // NOI18N
1779
encodingIANADescriptionMap.put ("ISO-8859-5", Util.THIS.getString ("NAME_ISO-8859-5")); // NOI18N
1780
encodingIANAAliasesMap.put ("ISO-8859-5", "ISO-8859-5"); // NOI18N
1781
encodingIANAAliasesMap.put ("CYRILLIC", "ISO-8859-5"); // NOI18N
1782

1783            encodingIANA2JavaMap.put ("ISO-8859-6", "8859_6"); // NOI18N
1784
encodingIANADescriptionMap.put ("ISO-8859-6", Util.THIS.getString ("NAME_ISO-8859-6")); // NOI18N
1785
encodingIANAAliasesMap.put ("ISO-8859-6", "ISO-8859-6"); // NOI18N
1786

1787            encodingIANA2JavaMap.put ("ISO-8859-7", "8859_7"); // NOI18N
1788
encodingIANADescriptionMap.put ("ISO-8859-7", Util.THIS.getString ("NAME_ISO-8859-7")); // NOI18N
1789
encodingIANAAliasesMap.put ("ISO-8859-7", "ISO-8859-7"); // NOI18N
1790
encodingIANAAliasesMap.put ("GREEK", "ISO-8859-7"); // NOI18N
1791
encodingIANAAliasesMap.put ("GREEK8", "ISO-8859-7"); // NOI18N
1792

1793            encodingIANA2JavaMap.put ("ISO-8859-8", "8859_8"); // NOI18N
1794
encodingIANADescriptionMap.put ("ISO-8859-8", Util.THIS.getString ("NAME_ISO-8859-8")); // NOI18N
1795
encodingIANAAliasesMap.put ("ISO-8859-8", "ISO-8859-8"); // NOI18N
1796
encodingIANAAliasesMap.put ("HEBREW", "ISO-8859-8"); // NOI18N
1797

1798            encodingIANA2JavaMap.put ("ISO-8859-9", "8859_9"); // NOI18N
1799
encodingIANADescriptionMap.put ("ISO-8859-9", Util.THIS.getString ("NAME_ISO-8859-9")); // NOI18N
1800
encodingIANAAliasesMap.put ("ISO-8859-9", "ISO-8859-9"); // NOI18N
1801
encodingIANAAliasesMap.put ("LATIN5", "ISO-8859-9"); // NOI18N
1802
encodingIANAAliasesMap.put ("L5", "ISO-8859-9"); // NOI18N
1803

1804            encodingIANA2JavaMap.put ("KOI8-R", "KOI8_R"); // NOI18N
1805
encodingIANADescriptionMap.put ("KOI8-R", Util.THIS.getString ("NAME_KOI8-R")); // NOI18N
1806
encodingIANAAliasesMap.put ("KOI8-R", "KOI8-R"); // NOI18N
1807

1808            encodingIANA2JavaMap.put ("US-ASCII", "8859_1"); // NOI18N
1809
encodingIANADescriptionMap.put ("US-ASCII", Util.THIS.getString ("NAME_ASCII")); // NOI18N
1810
encodingIANAAliasesMap.put ("ASCII", "US-ASCII"); // NOI18N
1811
encodingIANAAliasesMap.put ("US-ASCII", "US-ASCII"); // NOI18N
1812
encodingIANAAliasesMap.put ("ISO646-US", "US-ASCII"); // NOI18N
1813
encodingIANAAliasesMap.put ("IBM367", "US-ASCII"); // NOI18N
1814
encodingIANAAliasesMap.put ("CP367", "US-ASCII"); // NOI18N
1815

1816            encodingIANA2JavaMap.put ("UTF-8", "UTF8"); // NOI18N
1817
encodingIANADescriptionMap.put ("UTF-8", Util.THIS.getString ("NAME_UTF-8")); // NOI18N
1818
encodingIANAAliasesMap.put ("UTF-8", "UTF-8"); // NOI18N
1819

1820            encodingIANA2JavaMap.put ("UTF-16", "Unicode"); // NOI18N
1821
encodingIANADescriptionMap.put ("UTF-16", Util.THIS.getString ("NAME_UTF-16")); // NOI18N
1822
encodingIANAAliasesMap.put ("UTF-16", "UTF-16"); // NOI18N
1823
}
1824        
1825        
1826        /**
1827         */

1828        public static Map JavaDoc getIANA2JavaMap () {
1829            return encodingIANA2JavaMap;
1830        }
1831        
1832    } // end: class EncodingUtil
1833

1834}
1835
Popular Tags