0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041: package org.netbeans.tax;
0042:
0043: import java.util.Map;
0044: import java.util.TreeMap;
0045: import java.util.Collection;
0046: import java.io.ByteArrayInputStream;
0047: import java.io.IOException;
0048: import java.io.InputStreamReader;
0049:
0050: import org.netbeans.tax.spec.AttlistDecl;
0051: import org.netbeans.tax.spec.Attribute;
0052: import org.netbeans.tax.spec.CDATASection;
0053: import org.netbeans.tax.spec.CharacterReference;
0054: import org.netbeans.tax.spec.Comment;
0055: import org.netbeans.tax.spec.ConditionalSection;
0056: import org.netbeans.tax.spec.DocumentFragment;
0057: import org.netbeans.tax.spec.Document;
0058: import org.netbeans.tax.spec.DocumentType;
0059: import org.netbeans.tax.spec.DTD;
0060: import org.netbeans.tax.spec.ElementDecl;
0061: import org.netbeans.tax.spec.Element;
0062: import org.netbeans.tax.spec.EntityDecl;
0063: import org.netbeans.tax.spec.GeneralEntityReference;
0064: import org.netbeans.tax.spec.NotationDecl;
0065: import org.netbeans.tax.spec.ParameterEntityReference;
0066: import org.netbeans.tax.spec.ProcessingInstruction;
0067: import org.netbeans.tax.spec.Text;
0068:
0069: /**
0070: *
0071: * @author Libor Kramolis
0072: * @version 0.1
0073: */
0074: public final class TreeUtilities {
0075:
0076: /** */
0077: private static Constraints constraints = new Constraints();
0078:
0079: //
0080: // Node.Constraints
0081: //
0082:
0083: /**
0084: */
0085: public static final void checkAttributeName(TreeName treeName)
0086: throws InvalidArgumentException {
0087: constraints.checkAttributeName(treeName);
0088: }
0089:
0090: /**
0091: */
0092: public static final boolean isValidAttributeName(TreeName treeName) {
0093: return constraints.isValidAttributeName(treeName);
0094: }
0095:
0096: /**
0097: */
0098: public static final void checkElementTagName(
0099: TreeName elementTreeName) throws InvalidArgumentException {
0100: constraints.checkElementTagName(elementTreeName);
0101: }
0102:
0103: /**
0104: */
0105: public static final boolean isValidElementTagName(
0106: TreeName elementTreeName) {
0107: return constraints.isValidElementTagName(elementTreeName);
0108: }
0109:
0110: /**
0111: */
0112: public static final void checkNotationDeclSystemId(String systemId)
0113: throws InvalidArgumentException {
0114: constraints.checkNotationDeclSystemId(systemId);
0115: }
0116:
0117: /**
0118: */
0119: public static final boolean isValidNotationDeclSystemId(
0120: String systemId) {
0121: return constraints.isValidNotationDeclSystemId(systemId);
0122: }
0123:
0124: /**
0125: */
0126: public static final void checkDocumentEncoding(String encoding)
0127: throws InvalidArgumentException {
0128: constraints.checkDocumentEncoding(encoding);
0129: }
0130:
0131: /**
0132: */
0133: public static final boolean isValidDocumentEncoding(String encoding) {
0134: return constraints.isValidDocumentEncoding(encoding);
0135: }
0136:
0137: /**
0138: */
0139: public static final void checkDTDEncoding(String encoding)
0140: throws InvalidArgumentException {
0141: constraints.checkDTDEncoding(encoding);
0142: }
0143:
0144: /**
0145: */
0146: public static final boolean isValidDTDEncoding(String encoding) {
0147: return constraints.isValidDTDEncoding(encoding);
0148: }
0149:
0150: /**
0151: */
0152: public static final void checkCharacterReferenceName(String name)
0153: throws InvalidArgumentException {
0154: constraints.checkCharacterReferenceName(name);
0155: }
0156:
0157: /**
0158: */
0159: public static final boolean isValidCharacterReferenceName(
0160: String name) {
0161: return constraints.isValidCharacterReferenceName(name);
0162: }
0163:
0164: /**
0165: */
0166: public static final void checkEntityDeclInternalText(
0167: String internalText) throws InvalidArgumentException {
0168: constraints.checkEntityDeclInternalText(internalText);
0169: }
0170:
0171: /**
0172: */
0173: public static final boolean isValidEntityDeclInternalText(
0174: String internalText) {
0175: return constraints.isValidEntityDeclInternalText(internalText);
0176: }
0177:
0178: /**
0179: */
0180: public static final void checkAttlistDeclElementName(
0181: String elementName) throws InvalidArgumentException {
0182: constraints.checkAttlistDeclElementName(elementName);
0183: }
0184:
0185: /**
0186: */
0187: public static final boolean isValidAttlistDeclElementName(
0188: String elementName) {
0189: return constraints.isValidAttlistDeclElementName(elementName);
0190: }
0191:
0192: /**
0193: */
0194: public static final void checkDTDVersion(String version)
0195: throws InvalidArgumentException {
0196: constraints.checkDTDVersion(version);
0197: }
0198:
0199: /**
0200: */
0201: public static final boolean isValidDTDVersion(String version) {
0202: return constraints.isValidDTDVersion(version);
0203: }
0204:
0205: /**
0206: */
0207: public static final void checkDocumentTypeSystemId(String systemId)
0208: throws InvalidArgumentException {
0209: constraints.checkDocumentTypeSystemId(systemId);
0210: }
0211:
0212: /**
0213: */
0214: public static final boolean isValidDocumentTypeSystemId(
0215: String systemId) {
0216: return constraints.isValidDocumentTypeSystemId(systemId);
0217: }
0218:
0219: /**
0220: */
0221: public static final void checkDocumentTypeElementName(
0222: String elementName) throws InvalidArgumentException {
0223: constraints.checkDocumentTypeElementName(elementName);
0224: }
0225:
0226: /**
0227: */
0228: public static final boolean isValidDocumentTypeElementName(
0229: String elementName) {
0230: return constraints.isValidDocumentTypeElementName(elementName);
0231: }
0232:
0233: /**
0234: */
0235: public static final void checkDocumentStandalone(String standalone)
0236: throws InvalidArgumentException {
0237: constraints.checkDocumentStandalone(standalone);
0238: }
0239:
0240: /**
0241: */
0242: public static final boolean isValidDocumentStandalone(
0243: String standalone) {
0244: return constraints.isValidDocumentStandalone(standalone);
0245: }
0246:
0247: /**
0248: */
0249: public static final void checkEntityDeclName(String name)
0250: throws InvalidArgumentException {
0251: constraints.checkEntityDeclName(name);
0252: }
0253:
0254: /**
0255: */
0256: public static final boolean isValidEntityDeclName(String name) {
0257: return constraints.isValidEntityDeclName(name);
0258: }
0259:
0260: /**
0261: */
0262: public static final void checkAttlistDeclAttributeEnumeratedType(
0263: String[] enumeratedType) throws InvalidArgumentException {
0264: constraints
0265: .checkAttlistDeclAttributeEnumeratedType(enumeratedType);
0266: }
0267:
0268: /**
0269: */
0270: public static final boolean isValidAttlistDeclAttributeEnumeratedType(
0271: String[] enumeratedType) {
0272: return constraints
0273: .isValidAttlistDeclAttributeEnumeratedType(enumeratedType);
0274: }
0275:
0276: /**
0277: */
0278: public static final void checkProcessingInstructionData(String data)
0279: throws InvalidArgumentException {
0280: constraints.checkProcessingInstructionData(data);
0281: }
0282:
0283: /**
0284: */
0285: public static final boolean isValidProcessingInstructionData(
0286: String data) {
0287: return constraints.isValidProcessingInstructionData(data);
0288: }
0289:
0290: /**
0291: */
0292: public static final void checkEntityDeclNotationName(
0293: String notationName) throws InvalidArgumentException {
0294: constraints.checkEntityDeclNotationName(notationName);
0295: }
0296:
0297: /**
0298: */
0299: public static final boolean isValidEntityDeclNotationName(
0300: String notationName) {
0301: return constraints.isValidEntityDeclNotationName(notationName);
0302: }
0303:
0304: /**
0305: */
0306: public static final void checkElementDeclName(String name)
0307: throws InvalidArgumentException {
0308: constraints.checkElementDeclName(name);
0309: }
0310:
0311: /**
0312: */
0313: public static final boolean isValidElementDeclName(String name) {
0314: return constraints.isValidElementDeclName(name);
0315: }
0316:
0317: /**
0318: */
0319: public static final void checkGeneralEntityReferenceName(String name)
0320: throws InvalidArgumentException {
0321: constraints.checkGeneralEntityReferenceName(name);
0322: }
0323:
0324: /**
0325: */
0326: public static final boolean isValidGeneralEntityReferenceName(
0327: String name) {
0328: return constraints.isValidGeneralEntityReferenceName(name);
0329: }
0330:
0331: /**
0332: */
0333: public static final void checkEntityDeclSystemId(String systemId)
0334: throws InvalidArgumentException {
0335: constraints.checkEntityDeclSystemId(systemId);
0336: }
0337:
0338: /**
0339: */
0340: public static final boolean isValidEntityDeclSystemId(
0341: String systemId) {
0342: return constraints.isValidEntityDeclSystemId(systemId);
0343: }
0344:
0345: /**
0346: */
0347: public static final void checkProcessingInstructionTarget(
0348: String target) throws InvalidArgumentException {
0349: constraints.checkProcessingInstructionTarget(target);
0350: }
0351:
0352: /**
0353: */
0354: public static final boolean isValidProcessingInstructionTarget(
0355: String target) {
0356: return constraints.isValidProcessingInstructionTarget(target);
0357: }
0358:
0359: /**
0360: */
0361: public static final void checkEntityDeclPublicId(String publicId)
0362: throws InvalidArgumentException {
0363: constraints.checkEntityDeclPublicId(publicId);
0364: }
0365:
0366: /**
0367: */
0368: public static final boolean isValidEntityDeclPublicId(
0369: String publicId) {
0370: return constraints.isValidEntityDeclPublicId(publicId);
0371: }
0372:
0373: /**
0374: */
0375: public static final void checkAttlistDeclAttributeDefaultValue(
0376: String defaultValue) throws InvalidArgumentException {
0377: constraints.checkAttlistDeclAttributeDefaultValue(defaultValue);
0378: }
0379:
0380: /**
0381: */
0382: public static final boolean isValidAttlistDeclAttributeDefaultValue(
0383: String defaultValue) {
0384: return constraints
0385: .isValidAttlistDeclAttributeDefaultValue(defaultValue);
0386: }
0387:
0388: /**
0389: */
0390: public static final void checkDocumentFragmentVersion(String version)
0391: throws InvalidArgumentException {
0392: constraints.checkDocumentFragmentVersion(version);
0393: }
0394:
0395: /**
0396: */
0397: public static final boolean isValidDocumentFragmentVersion(
0398: String version) {
0399: return constraints.isValidDocumentFragmentVersion(version);
0400: }
0401:
0402: /**
0403: */
0404: public static final void checkNotationDeclName(String name)
0405: throws InvalidArgumentException {
0406: constraints.checkNotationDeclName(name);
0407: }
0408:
0409: /**
0410: */
0411: public static final boolean isValidNotationDeclName(String name) {
0412: return constraints.isValidNotationDeclName(name);
0413: }
0414:
0415: /**
0416: */
0417: public static final void checkAttributeValue(String value)
0418: throws InvalidArgumentException {
0419: constraints.checkAttributeValue(value);
0420: }
0421:
0422: /**
0423: */
0424: public static final boolean isValidAttributeValue(String value) {
0425: return constraints.isValidAttributeValue(value);
0426: }
0427:
0428: /**
0429: */
0430: public static final void checkParameterEntityReferenceName(
0431: String name) throws InvalidArgumentException {
0432: constraints.checkParameterEntityReferenceName(name);
0433: }
0434:
0435: /**
0436: */
0437: public static final boolean isValidParameterEntityReferenceName(
0438: String name) {
0439: return constraints.isValidParameterEntityReferenceName(name);
0440: }
0441:
0442: /**
0443: */
0444: public static final void checkDocumentFragmentEncoding(
0445: String encoding) throws InvalidArgumentException {
0446: constraints.checkDocumentFragmentEncoding(encoding);
0447: }
0448:
0449: /**
0450: */
0451: public static final boolean isValidDocumentFragmentEncoding(
0452: String encoding) {
0453: return constraints.isValidDocumentFragmentEncoding(encoding);
0454: }
0455:
0456: /**
0457: */
0458: public static final void checkTextData(String data)
0459: throws InvalidArgumentException {
0460: constraints.checkTextData(data);
0461: }
0462:
0463: /**
0464: */
0465: public static final boolean isValidTextData(String data) {
0466: return constraints.isValidTextData(data);
0467: }
0468:
0469: /**
0470: */
0471: public static final void checkDocumentTypePublicId(String publicId)
0472: throws InvalidArgumentException {
0473: constraints.checkDocumentTypePublicId(publicId);
0474: }
0475:
0476: /**
0477: */
0478: public static final boolean isValidDocumentTypePublicId(
0479: String publicId) {
0480: return constraints.isValidDocumentTypePublicId(publicId);
0481: }
0482:
0483: /**
0484: */
0485: public static final void checkElementDeclContentType(
0486: TreeElementDecl.ContentType contentType)
0487: throws InvalidArgumentException {
0488: constraints.checkElementDeclContentType(contentType);
0489: }
0490:
0491: /**
0492: */
0493: public static final boolean isValidElementDeclContentType(
0494: TreeElementDecl.ContentType contentType) {
0495: return constraints.isValidElementDeclContentType(contentType);
0496: }
0497:
0498: /**
0499: */
0500: public static final void checkDocumentVersion(String version)
0501: throws InvalidArgumentException {
0502: constraints.checkDocumentVersion(version);
0503: }
0504:
0505: /**
0506: */
0507: public static final boolean isValidDocumentVersion(String version) {
0508: return constraints.isValidDocumentVersion(version);
0509: }
0510:
0511: /**
0512: */
0513: public static final void checkCDATASectionData(String data)
0514: throws InvalidArgumentException {
0515: constraints.checkCDATASectionData(data);
0516: }
0517:
0518: /**
0519: */
0520: public static final boolean isValidCDATASectionData(String data) {
0521: return constraints.isValidCDATASectionData(data);
0522: }
0523:
0524: /**
0525: */
0526: public static final void checkNotationDeclPublicId(String publicId)
0527: throws InvalidArgumentException {
0528: constraints.checkNotationDeclPublicId(publicId);
0529: }
0530:
0531: /**
0532: */
0533: public static final boolean isValidNotationDeclPublicId(
0534: String publicId) {
0535: return constraints.isValidNotationDeclPublicId(publicId);
0536: }
0537:
0538: /**
0539: */
0540: public static final void checkAttlistDeclAttributeName(
0541: String attributeName) throws InvalidArgumentException {
0542: constraints.checkAttlistDeclAttributeName(attributeName);
0543: }
0544:
0545: /**
0546: */
0547: public static final boolean isValidAttlistDeclAttributeName(
0548: String attributeName) {
0549: return constraints
0550: .isValidAttlistDeclAttributeName(attributeName);
0551: }
0552:
0553: /**
0554: */
0555: public static final void checkCommentData(String data)
0556: throws InvalidArgumentException {
0557: constraints.checkCommentData(data);
0558: }
0559:
0560: /**
0561: */
0562: public static final boolean isValidCommentData(String data) {
0563: return constraints.isValidCommentData(data);
0564: }
0565:
0566: /**
0567: */
0568: public static final void checkAttlistDeclAttributeType(short type)
0569: throws InvalidArgumentException {
0570: constraints.checkAttlistDeclAttributeType(type);
0571: }
0572:
0573: /**
0574: */
0575: public static final boolean isValidAttlistDeclAttributeType(
0576: short type) {
0577: return constraints.isValidAttlistDeclAttributeType(type);
0578: }
0579:
0580: /**
0581: */
0582: public static final void checkAttlistDeclAttributeDefaultType(
0583: short defaultType) throws InvalidArgumentException {
0584: constraints.checkAttlistDeclAttributeDefaultType(defaultType);
0585: }
0586:
0587: /**
0588: */
0589: public static final boolean isValidAttlistDeclAttributeDefaultType(
0590: short defaultType) {
0591: return constraints
0592: .isValidAttlistDeclAttributeDefaultType(defaultType);
0593: }
0594:
0595: //
0596: // Constraints
0597: //
0598:
0599: /**
0600: *
0601: */
0602: private static final class Constraints extends UnicodeClasses
0603: implements AttlistDecl.Constraints, Attribute.Constraints,
0604: CDATASection.Constraints, CharacterReference.Constraints,
0605: Comment.Constraints, ConditionalSection.Constraints,
0606: DocumentFragment.Constraints, Document.Constraints,
0607: DocumentType.Constraints, DTD.Constraints,
0608: ElementDecl.Constraints, Element.Constraints,
0609: EntityDecl.Constraints, GeneralEntityReference.Constraints,
0610: NotationDecl.Constraints,
0611: ParameterEntityReference.Constraints,
0612: ProcessingInstruction.Constraints, Text.Constraints {
0613:
0614: //
0615: // itself
0616: //
0617:
0618: /**
0619: */
0620: private static void checkNullArgument(String argName,
0621: Object argValue) throws InvalidArgumentException {
0622: if (argValue == null) {
0623: throw new InvalidArgumentException(argName, Util.THIS
0624: .getString("PROP_invalid_null_value"));
0625: }
0626: }
0627:
0628: /**
0629: */
0630: private static void checkEmptyString(String argName,
0631: String string, boolean trim)
0632: throws InvalidArgumentException {
0633: if ((string.length() == 0)
0634: || (trim && (string.trim().equals("")))) { // NOI18N
0635: throw new InvalidArgumentException(argName, Util.THIS
0636: .getString("PROP_invalid_empty_value"));
0637: }
0638: }
0639:
0640: //
0641: // global constraints
0642: //
0643:
0644: /**
0645: * @see http://www.w3.org/TR/REC-xml#NT-Name
0646: */
0647: private static void checkXMLName(String argName, String name)
0648: throws InvalidArgumentException {
0649: checkNullArgument(argName, name);
0650: checkEmptyString(argName, name, true);
0651:
0652: char first = name.charAt(0);
0653: if (!!!isXMLNameStartChar(first)) {
0654: throw new InvalidArgumentException(argName, Util.THIS
0655: .getString("PROP_invalid_first_char", String
0656: .valueOf(first)));
0657: }
0658:
0659: for (int i = 0, len = name.length(); i < len; i++) {
0660: char c = name.charAt(i);
0661: if (!!!isXMLNameChar(c)) {
0662: throw new InvalidArgumentException(argName,
0663: Util.THIS.getString(
0664: "PROP_invalid_content_char", String
0665: .valueOf(c)));
0666: }
0667: }
0668: }
0669:
0670: /**
0671: * @see http://www.w3.org/TR/REC-xml#NT-Nmtoken
0672: */
0673: private static void checkNmToken(String argName, String token)
0674: throws InvalidArgumentException {
0675:
0676: checkNullArgument(argName, token);
0677: checkEmptyString(argName, token, true);
0678:
0679: for (int i = 0, len = token.length(); i < len; i++) {
0680: char c = token.charAt(i);
0681: if (!!!isXMLNameChar(c)) {
0682: throw new InvalidArgumentException(argName,
0683: Util.THIS.getString(
0684: "PROP_invalid_content_char", String
0685: .valueOf(c)));
0686: }
0687: }
0688:
0689: }
0690:
0691: /**
0692: * @see http://www.w3.org/TR/REC-xml-names/#NT-NCName
0693: */
0694: private static void checkXMLNCName(String argName, String name)
0695: throws InvalidArgumentException {
0696: checkNullArgument(argName, name);
0697: checkEmptyString(argName, name, true);
0698:
0699: char first = name.charAt(0);
0700: if (!!!isXMLNCNameStartChar(first)) {
0701: throw new InvalidArgumentException(argName, Util.THIS
0702: .getString("PROP_invalid_first_char", String
0703: .valueOf(first)));
0704: }
0705:
0706: for (int i = 0, len = name.length(); i < len; i++) {
0707: char c = name.charAt(i);
0708: if (!!!isXMLNCNameChar(c)) {
0709: throw new InvalidArgumentException(argName,
0710: Util.THIS.getString(
0711: "PROP_invalid_content_char", String
0712: .valueOf(c)));
0713: }
0714: }
0715: }
0716:
0717: /**
0718: */
0719: private static void checkNamespacePrefix(String prefix)
0720: throws InvalidArgumentException {
0721: String argName = Util.THIS
0722: .getString("PROP_NamespacePrefix");
0723: checkXMLNCName(argName, prefix);
0724: }
0725:
0726: /**
0727: */
0728: private static void checkNamespaceURI(String uri)
0729: throws InvalidArgumentException {
0730: String argName = Util.THIS.getString("PROP_NamespaceURI");
0731: checkAttributeValue(argName, uri);
0732: }
0733:
0734: /**
0735: */
0736: private static void checkElementName(String argName, String name)
0737: throws InvalidArgumentException {
0738: checkNullArgument(argName, name);
0739: checkXMLName(argName, name);
0740: }
0741:
0742: /**
0743: */
0744: private static void checkAttributeName(String argName,
0745: String name) throws InvalidArgumentException {
0746: checkNullArgument(argName, name);
0747: checkXMLName(argName, name);
0748: }
0749:
0750: /**
0751: */
0752: private static void checkAttributeValue(String argName,
0753: String value) throws InvalidArgumentException {
0754: checkNullArgument(argName, value);
0755: checkCharacterData(argName, value);
0756:
0757: int index = value.indexOf('<');
0758: if (index != -1) {
0759: throw new InvalidArgumentException(argName,
0760: Util.THIS.getString(
0761: "EXC_invalid_attribute_value", value));
0762: }
0763: index = value.indexOf('&');
0764: if (index != -1) {
0765: throw new InvalidArgumentException(argName,
0766: Util.THIS.getString(
0767: "EXC_invalid_attribute_value", value));
0768: }
0769:
0770: boolean apostrofFound = false;
0771: boolean quoteFound = false;
0772: for (int i = 0, len = value.length(); i < len; i++) {
0773: char c = value.charAt(i);
0774: if (c == '\'')
0775: if (quoteFound)
0776: throw new InvalidArgumentException(argName,
0777: Util.THIS.getString(
0778: "EXC_invalid_attribute_value",
0779: value));
0780: else
0781: apostrofFound = true;
0782: if (c == '"')
0783: if (apostrofFound)
0784: throw new InvalidArgumentException(argName,
0785: Util.THIS.getString(
0786: "EXC_invalid_attribute_value",
0787: value));
0788: else
0789: quoteFound = true;
0790: }
0791: }
0792:
0793: /**
0794: */
0795: private static void checkCharacterData(String argName,
0796: String text) throws InvalidArgumentException {
0797: checkNullArgument(argName, text);
0798:
0799: // do check
0800: for (int i = 0, len = text.length(); i < len; i++) {
0801: char c = text.charAt(i);
0802: if (!!!isXMLChar(c)) {
0803: throw new InvalidArgumentException(argName,
0804: Util.THIS.getString(
0805: "PROP_invalid_content_char", "0x"
0806: + Integer.toHexString(c))); // NOI18N
0807: }
0808: }
0809: }
0810:
0811: /**
0812: */
0813: private static void checkSystemId(String argName,
0814: String systemId) throws InvalidArgumentException {
0815: boolean apostrofFound = false;
0816: boolean quoteFound = false;
0817: for (int i = 0, len = systemId.length(); i < len; i++) {
0818: char c = systemId.charAt(i);
0819: if (c == '\'')
0820: if (quoteFound)
0821: throw new InvalidArgumentException(argName,
0822: Util.THIS.getString(
0823: "EXC_Invalid_system_id",
0824: systemId));
0825: else
0826: apostrofFound = true;
0827: if (c == '"')
0828: if (apostrofFound)
0829: throw new InvalidArgumentException(argName,
0830: Util.THIS.getString(
0831: "EXC_Invalid_system_id",
0832: systemId));
0833: else
0834: quoteFound = true;
0835: }
0836: }
0837:
0838: /**
0839: */
0840: private static void checkPublicId(String argName,
0841: String publicId) throws InvalidArgumentException {
0842: boolean apostrofFound = false;
0843: boolean quoteFound = false;
0844: for (int i = 0, len = publicId.length(); i < len; i++) {
0845: char c = publicId.charAt(i);
0846: if (c == '\'') {
0847: if (quoteFound) {
0848: throw new InvalidArgumentException(argName,
0849: Util.THIS.getString(
0850: "EXC_Invalid_public_id",
0851: publicId));
0852: } else {
0853: apostrofFound = true;
0854: }
0855: } else if (c == '"') {
0856: if (apostrofFound) {
0857: throw new InvalidArgumentException(argName,
0858: Util.THIS.getString(
0859: "EXC_Invalid_public_id",
0860: publicId));
0861: } else {
0862: quoteFound = true;
0863: }
0864: } else if (isXMLPubidLiteral(c) == false) {
0865: throw new InvalidArgumentException(argName,
0866: Util.THIS.getString(
0867: "EXC_Invalid_public_id", publicId));
0868: }
0869: }
0870: }
0871:
0872: /**
0873: */
0874: private static void checkNotationName(String argName,
0875: String name) throws InvalidArgumentException {
0876: checkNullArgument(argName, name);
0877: checkXMLName(argName, name);
0878: }
0879:
0880: /**
0881: */
0882: private static void checkEncoding(String argName,
0883: String encoding) throws InvalidArgumentException {
0884: if (Util.THIS.isLoggable()) /* then */
0885: Util.THIS
0886: .debug("TreeUtilities::checkEncoding: encoding = "
0887: + encoding); // NOI18N
0888:
0889: ByteArrayInputStream stream = new ByteArrayInputStream(
0890: new byte[0]);
0891:
0892: if (Util.THIS.isLoggable()) /* then */
0893: Util.THIS.debug(" ::checkEncoding: stream = "
0894: + stream); // NOI18N
0895:
0896: try {
0897: InputStreamReader reader = new InputStreamReader(
0898: stream, iana2java(encoding));
0899:
0900: if (Util.THIS.isLoggable()) /* then */
0901: Util.THIS.debug(" ::checkEncoding: reader = "
0902: + reader); // NOI18N
0903: } catch (IOException exc) {
0904: if (Util.THIS.isLoggable()) /* then */
0905: Util.THIS.debug(
0906: " ::checkEncoding: IOException !!!",
0907: exc); // NOI18N
0908:
0909: throw new InvalidArgumentException(argName, Util.THIS
0910: .getString("EXC_Invalid_encoding", encoding));
0911: }
0912: }
0913:
0914: /**
0915: */
0916: public void checkAttributeName(TreeName treeName)
0917: throws InvalidArgumentException {
0918: String argName = Util.THIS.getString("PROP_AttributeName");
0919: checkAttributeName(argName, treeName.getQualifiedName());
0920: }
0921:
0922: /**
0923: */
0924: public boolean isValidAttributeName(TreeName treeName) {
0925: try {
0926: checkAttributeName(treeName);
0927: } catch (InvalidArgumentException exc) {
0928: return false;
0929: }
0930: return true;
0931: }
0932:
0933: /**
0934: */
0935: public void checkElementTagName(TreeName elementTreeName)
0936: throws InvalidArgumentException {
0937: checkElementName(
0938: Util.THIS.getString("PROP_ElementTagName"),
0939: elementTreeName.getQualifiedName());
0940: }
0941:
0942: /**
0943: */
0944: public boolean isValidElementTagName(TreeName elementTreeName) {
0945: try {
0946: checkElementTagName(elementTreeName);
0947: } catch (InvalidArgumentException exc) {
0948: return false;
0949: }
0950: return true;
0951: }
0952:
0953: /**
0954: */
0955: public void checkNotationDeclSystemId(String systemId)
0956: throws InvalidArgumentException {
0957: if (systemId == null) {
0958: return;
0959: }
0960: checkSystemId(Util.THIS
0961: .getString("PROP_NotationDeclSystemId"), systemId);
0962: }
0963:
0964: /**
0965: */
0966: public boolean isValidNotationDeclSystemId(String systemId) {
0967: try {
0968: checkNotationDeclSystemId(systemId);
0969: } catch (InvalidArgumentException exc) {
0970: return false;
0971: }
0972: return true;
0973: }
0974:
0975: /**
0976: */
0977: public void checkDocumentEncoding(String encoding)
0978: throws InvalidArgumentException {
0979: if (encoding == null)
0980: return;
0981: checkEncoding(Util.THIS.getString("PROP_DocumentEncoding"),
0982: encoding);
0983: }
0984:
0985: /**
0986: */
0987: public boolean isValidDocumentEncoding(String encoding) {
0988: try {
0989: checkDocumentEncoding(encoding);
0990: } catch (InvalidArgumentException exc) {
0991: return false;
0992: }
0993: return true;
0994: }
0995:
0996: /**
0997: */
0998: public void checkDTDEncoding(String encoding)
0999: throws InvalidArgumentException {
1000: if (encoding == null)
1001: return;
1002: checkEncoding(Util.THIS.getString("PROP_DTDEncoding"),
1003: encoding);
1004: }
1005:
1006: /**
1007: */
1008: public boolean isValidDTDEncoding(String encoding) {
1009: try {
1010: checkDTDEncoding(encoding);
1011: } catch (InvalidArgumentException exc) {
1012: return false;
1013: }
1014: return true;
1015: }
1016:
1017: /**
1018: */
1019: public void checkCharacterReferenceName(String name)
1020: throws InvalidArgumentException {
1021: String argName = Util.THIS
1022: .getString("PROP_CharacterReferenceName");
1023:
1024: checkNullArgument(argName, name);
1025: checkEmptyString(argName, name, true);
1026:
1027: int i = 0;
1028: char first = name.charAt(i);
1029: if (first != '#') {
1030: throw new InvalidArgumentException(argName, Util.THIS
1031: .getString("PROP_invalid_first_char", String
1032: .valueOf(first)));
1033: }
1034:
1035: i++;
1036: if (name.length() <= i) {
1037: throw new InvalidArgumentException(argName, Util.THIS
1038: .getString("PROP_invalid_empty_value"));
1039: }
1040:
1041: char second = name.charAt(i);
1042: int radix = 10;
1043: if (second == 'x') {
1044: radix = 16;
1045:
1046: i++;
1047: if (name.length() <= i) {
1048: throw new InvalidArgumentException(
1049: argName,
1050: Util.THIS
1051: .getString("PROP_invalid_empty_value"));
1052: }
1053: }
1054: String number = name.substring(i);
1055: try {
1056: Short.parseShort(number, radix);
1057: } catch (NumberFormatException exc) {
1058: throw new InvalidArgumentException(argName, Util.THIS
1059: .getString("PROP_invalid_content_char", number));
1060: }
1061:
1062: /* for (int len = name.length(); i < len; i++) {
1063: char c = name.charAt (i);
1064: if ( Character.digit (c, radix) == -1 ) {
1065: throw new InvalidArgumentException (argName, Util.THIS.getString ("PROP_invalid_content_char", String.valueOf (c)));
1066: }
1067: }*/
1068: }
1069:
1070: /**
1071: */
1072: public boolean isValidCharacterReferenceName(String name) {
1073: try {
1074: checkCharacterReferenceName(name);
1075: } catch (InvalidArgumentException exc) {
1076: return false;
1077: }
1078: return true;
1079: }
1080:
1081: /**
1082: */
1083: public void checkEntityDeclInternalText(String internalText)
1084: throws InvalidArgumentException {
1085: checkNullArgument(Util.THIS
1086: .getString("PROP_EntityDeclInternalText"),
1087: internalText);
1088: boolean apostrofFound = false;
1089: boolean quoteFound = false;
1090: for (int i = 0, len = internalText.length(); i < len; i++) {
1091: char c = internalText.charAt(i);
1092: if (c == '\'')
1093: if (quoteFound)
1094: throw new InvalidArgumentException(
1095: Util.THIS
1096: .getString("PROP_EntityDeclInternalText"),
1097: Util.THIS
1098: .getString(
1099: "EXC_Invalid_Entity_Decl_Internal_text",
1100: internalText));
1101: else
1102: apostrofFound = true;
1103: if (c == '"')
1104: if (apostrofFound)
1105: throw new InvalidArgumentException(
1106: Util.THIS
1107: .getString("PROP_EntityDeclInternalText"),
1108: Util.THIS
1109: .getString(
1110: "EXC_Invalid_Entity_Decl_Internal_text",
1111: internalText));
1112: else
1113: quoteFound = true;
1114: // todo
1115: // if (c == '%' || c == '&')
1116: // throw new InvalidArgumentException ("EntityDeclInternalText", Util.THIS.getString ("EXC_Invalid_Entity_Decl_Internal_text", internalText));
1117: }
1118: }
1119:
1120: /**
1121: */
1122: public boolean isValidEntityDeclInternalText(String internalText) {
1123: try {
1124: checkEntityDeclInternalText(internalText);
1125: } catch (InvalidArgumentException exc) {
1126: return false;
1127: }
1128: return true;
1129: }
1130:
1131: /**
1132: */
1133: public void checkAttlistDeclElementName(String elementName)
1134: throws InvalidArgumentException {
1135: checkElementName(Util.THIS
1136: .getString("PROP_AttlistDeclElementName"),
1137: elementName);
1138: }
1139:
1140: /**
1141: */
1142: public boolean isValidAttlistDeclElementName(String elementName) {
1143: try {
1144: checkAttlistDeclElementName(elementName);
1145: } catch (InvalidArgumentException exc) {
1146: return false;
1147: }
1148: return true;
1149: }
1150:
1151: /**
1152: */
1153: public void checkDTDVersion(String version)
1154: throws InvalidArgumentException {
1155: if (version == null)
1156: return;
1157: if (!!!version.equals("1.0")) { // NOI18N
1158: String arg = Util.THIS.getString("PROP_DTDVersion");
1159: String msg = Util.THIS.getString(
1160: "PROP_invalid_version_number", version);
1161: throw new InvalidArgumentException(arg, msg);
1162: }
1163: }
1164:
1165: /**
1166: */
1167: public boolean isValidDTDVersion(String version) {
1168: try {
1169: checkDTDVersion(version);
1170: } catch (InvalidArgumentException exc) {
1171: return false;
1172: }
1173: return true;
1174: }
1175:
1176: /**
1177: */
1178: public void checkDocumentTypeSystemId(String systemId)
1179: throws InvalidArgumentException {
1180: if (systemId == null) {
1181: return;
1182: }
1183: checkSystemId(Util.THIS
1184: .getString("PROP_DocumentTypeSystemId"), systemId);
1185: }
1186:
1187: /**
1188: */
1189: public boolean isValidDocumentTypeSystemId(String systemId) {
1190: try {
1191: checkDocumentTypeSystemId(systemId);
1192: } catch (InvalidArgumentException exc) {
1193: return false;
1194: }
1195: return true;
1196: }
1197:
1198: /**
1199: */
1200: public void checkDocumentTypeElementName(String elementName)
1201: throws InvalidArgumentException {
1202: checkElementName(Util.THIS
1203: .getString("PROP_DocumentTypeElementName"),
1204: elementName);
1205: }
1206:
1207: /**
1208: */
1209: public boolean isValidDocumentTypeElementName(String elementName) {
1210: try {
1211: checkDocumentTypeElementName(elementName);
1212: } catch (InvalidArgumentException exc) {
1213: return false;
1214: }
1215: return true;
1216: }
1217:
1218: /**
1219: */
1220: public void checkDocumentStandalone(String standalone)
1221: throws InvalidArgumentException {
1222: if (standalone == null)
1223: return;
1224: if (standalone.equals("yes")) // NOI18N
1225: return;
1226: if (standalone.equals("no")) // NOI18N
1227: return;
1228: throw new InvalidArgumentException(
1229: standalone,
1230: standalone
1231: + Util.THIS
1232: .getString("PROP_is_not_valid_standalone_value"));
1233: }
1234:
1235: /**
1236: */
1237: public boolean isValidDocumentStandalone(String standalone) {
1238: try {
1239: checkDocumentStandalone(standalone);
1240: } catch (InvalidArgumentException exc) {
1241: return false;
1242: }
1243: return true;
1244: }
1245:
1246: /**
1247: */
1248: public void checkEntityDeclName(String name)
1249: throws InvalidArgumentException {
1250: checkXMLName(Util.THIS.getString("PROP_EntityDeclName"),
1251: name);
1252: }
1253:
1254: /**
1255: */
1256: public boolean isValidEntityDeclName(String name) {
1257: try {
1258: checkEntityDeclName(name);
1259: } catch (InvalidArgumentException exc) {
1260: return false;
1261: }
1262: return true;
1263: }
1264:
1265: /**
1266: */
1267: public void checkAttlistDeclAttributeEnumeratedType(
1268: String[] enumeratedType)
1269: throws InvalidArgumentException {
1270: if (enumeratedType == null) {
1271: return;
1272: }
1273: for (int i = 0, len = enumeratedType.length; i < len; i++)
1274: checkNmToken(
1275: Util.THIS
1276: .getString("PROP_AttlistDeclAttributeEnumeratedType"),
1277: enumeratedType[i]);
1278: }
1279:
1280: /**
1281: */
1282: public boolean isValidAttlistDeclAttributeEnumeratedType(
1283: String[] enumeratedType) {
1284: try {
1285: checkAttlistDeclAttributeEnumeratedType(enumeratedType);
1286: } catch (InvalidArgumentException exc) {
1287: return false;
1288: }
1289: return true;
1290: }
1291:
1292: /**
1293: */
1294: public void checkProcessingInstructionData(String data)
1295: throws InvalidArgumentException {
1296: checkCharacterData(Util.THIS
1297: .getString("PROP_ProcessingInstructionData"), data);
1298:
1299: int index = data.indexOf("?>"); // NOI18N
1300: if (index != -1) {
1301: throw new InvalidArgumentException(
1302: data,
1303: Util.THIS
1304: .getString("PROP_invalid_processing_instruction_data"));
1305: }
1306: }
1307:
1308: /**
1309: */
1310: public boolean isValidProcessingInstructionData(String data) {
1311: try {
1312: checkProcessingInstructionData(data);
1313: } catch (InvalidArgumentException exc) {
1314: return false;
1315: }
1316: return true;
1317: }
1318:
1319: /**
1320: */
1321: public void checkEntityDeclNotationName(String notationName)
1322: throws InvalidArgumentException {
1323: if (notationName == null) {
1324: return;
1325: }
1326: checkNotationName(Util.THIS
1327: .getString("PROP_EntityDeclNotationName"),
1328: notationName);
1329: }
1330:
1331: /**
1332: */
1333: public boolean isValidEntityDeclNotationName(String notationName) {
1334: try {
1335: checkEntityDeclNotationName(notationName);
1336: } catch (InvalidArgumentException exc) {
1337: return false;
1338: }
1339: return true;
1340: }
1341:
1342: /**
1343: */
1344: public void checkElementDeclName(String name)
1345: throws InvalidArgumentException {
1346: checkElementName(Util.THIS
1347: .getString("PROP_ElementDeclName"), name);
1348: }
1349:
1350: /**
1351: */
1352: public boolean isValidElementDeclName(String name) {
1353: try {
1354: checkElementDeclName(name);
1355: } catch (InvalidArgumentException exc) {
1356: return false;
1357: }
1358: return true;
1359: }
1360:
1361: /**
1362: */
1363: public void checkGeneralEntityReferenceName(String name)
1364: throws InvalidArgumentException {
1365: checkXMLName(Util.THIS
1366: .getString("PROP_GeneralEntityReferenceName"), name);
1367: }
1368:
1369: /**
1370: */
1371: public boolean isValidGeneralEntityReferenceName(String name) {
1372: try {
1373: checkGeneralEntityReferenceName(name);
1374: } catch (InvalidArgumentException exc) {
1375: return false;
1376: }
1377: return true;
1378: }
1379:
1380: /**
1381: */
1382: public void checkEntityDeclSystemId(String systemId)
1383: throws InvalidArgumentException {
1384: if (systemId == null) {
1385: return;
1386: }
1387: checkSystemId(Util.THIS
1388: .getString("PROP_EntityDeclSystemId"), systemId);
1389: }
1390:
1391: /**
1392: */
1393: public boolean isValidEntityDeclSystemId(String systemId) {
1394: try {
1395: checkEntityDeclSystemId(systemId);
1396: } catch (InvalidArgumentException exc) {
1397: return false;
1398: }
1399: return true;
1400: }
1401:
1402: /**
1403: */
1404: public void checkProcessingInstructionTarget(String target)
1405: throws InvalidArgumentException {
1406: String argName = Util.THIS
1407: .getString("PROP_ProcessingInstructionTarget");
1408: checkXMLName(argName, target);
1409:
1410: if (target.equalsIgnoreCase("xml")) { // NOI18N
1411: throw new InvalidArgumentException(argName, Util.THIS
1412: .getString("PROP_invalid_content_char", target));
1413: }
1414: }
1415:
1416: /**
1417: */
1418: public boolean isValidProcessingInstructionTarget(String target) {
1419: try {
1420: checkProcessingInstructionTarget(target);
1421: } catch (InvalidArgumentException exc) {
1422: return false;
1423: }
1424: return true;
1425: }
1426:
1427: /**
1428: */
1429: public void checkEntityDeclPublicId(String publicId)
1430: throws InvalidArgumentException {
1431: if (publicId == null) {
1432: return;
1433: }
1434: checkPublicId(Util.THIS
1435: .getString("PROP_EntityDeclPublicId"), publicId);
1436: }
1437:
1438: /**
1439: */
1440: public boolean isValidEntityDeclPublicId(String publicId) {
1441: try {
1442: checkEntityDeclPublicId(publicId);
1443: } catch (InvalidArgumentException exc) {
1444: return false;
1445: }
1446: return true;
1447: }
1448:
1449: /**
1450: */
1451: public void checkAttlistDeclAttributeDefaultValue(
1452: String defaultValue) throws InvalidArgumentException {
1453: if (defaultValue == null) {
1454: return;
1455: }
1456: boolean apostrofFound = false;
1457: boolean quoteFound = false;
1458: for (int i = 0, len = defaultValue.length(); i < len; i++) {
1459: char c = defaultValue.charAt(i);
1460: if (c == '\'')
1461: if (quoteFound)
1462: throw new InvalidArgumentException(
1463: Util.THIS
1464: .getString("PROP_AttlistDeclAttributeDefaultValue"),
1465: Util.THIS
1466: .getString(
1467: "EXC_invalid_attribute_default_value",
1468: defaultValue));
1469: else
1470: apostrofFound = true;
1471: if (c == '"')
1472: if (apostrofFound)
1473: throw new InvalidArgumentException(
1474: Util.THIS
1475: .getString("PROP_AttlistDeclAttributeDefaultValue"),
1476: Util.THIS
1477: .getString(
1478: "EXC_invalid_attribute_default_value",
1479: defaultValue));
1480: else
1481: quoteFound = true;
1482: // todo
1483: // if (c == '%' || c == '&')
1484: // throw new InvalidArgumentException ("AttlistDeclAttributeDefaultValue", Util.THIS.getString ("EXC_invalid_attribute_default_value", defaultValue));
1485: }
1486: }
1487:
1488: /**
1489: */
1490: public boolean isValidAttlistDeclAttributeDefaultValue(
1491: String defaultValue) {
1492: try {
1493: checkAttlistDeclAttributeDefaultValue(defaultValue);
1494: } catch (InvalidArgumentException exc) {
1495: return false;
1496: }
1497: return true;
1498: }
1499:
1500: /**
1501: */
1502: public void checkDocumentFragmentVersion(String version)
1503: throws InvalidArgumentException {
1504: if (version == null)
1505: return;
1506: if (!!!version.equals("1.0")) { // NOI18N
1507: String arg = Util.THIS
1508: .getString("PROP_DocumentFragmentVersion");
1509: String msg = Util.THIS.getString(
1510: "PROP_invalid_version_number", version);
1511: throw new InvalidArgumentException(arg, msg);
1512: }
1513: }
1514:
1515: /**
1516: */
1517: public boolean isValidDocumentFragmentVersion(String version) {
1518: try {
1519: checkDocumentFragmentVersion(version);
1520: } catch (InvalidArgumentException exc) {
1521: return false;
1522: }
1523: return true;
1524: }
1525:
1526: /**
1527: */
1528: public void checkNotationDeclName(String name)
1529: throws InvalidArgumentException {
1530: checkXMLName(Util.THIS.getString("PROP_NotationDeclName"),
1531: name);
1532: }
1533:
1534: /**
1535: */
1536: public boolean isValidNotationDeclName(String name) {
1537: try {
1538: checkNotationDeclName(name);
1539: } catch (InvalidArgumentException exc) {
1540: return false;
1541: }
1542: return true;
1543: }
1544:
1545: /**
1546: */
1547: public void checkAttributeValue(String value)
1548: throws InvalidArgumentException {
1549: String argName = Util.THIS.getString("PROP_AttributeValue");
1550: checkAttributeValue(argName, value);
1551: }
1552:
1553: /**
1554: */
1555: public boolean isValidAttributeValue(String value) {
1556: try {
1557: checkAttributeValue(value);
1558: } catch (InvalidArgumentException exc) {
1559: return false;
1560: }
1561: return true;
1562: }
1563:
1564: /**
1565: */
1566: public void checkParameterEntityReferenceName(String name)
1567: throws InvalidArgumentException {
1568: checkXMLName(Util.THIS
1569: .getString("PROP_ParameterEntityReferenceName"),
1570: name);
1571: }
1572:
1573: /**
1574: */
1575: public boolean isValidParameterEntityReferenceName(String name) {
1576: try {
1577: checkParameterEntityReferenceName(name);
1578: } catch (InvalidArgumentException exc) {
1579: return false;
1580: }
1581: return true;
1582: }
1583:
1584: /**
1585: */
1586: public void checkDocumentFragmentEncoding(String encoding)
1587: throws InvalidArgumentException {
1588: if (encoding == null)
1589: return;
1590: checkEncoding(Util.THIS
1591: .getString("PROP_DocumentFragmentEncoding"),
1592: encoding);
1593: }
1594:
1595: /**
1596: */
1597: public boolean isValidDocumentFragmentEncoding(String encoding) {
1598: try {
1599: checkDocumentFragmentEncoding(encoding);
1600: } catch (InvalidArgumentException exc) {
1601: return false;
1602: }
1603: return true;
1604: }
1605:
1606: /**
1607: */
1608: public void checkTextData(String data)
1609: throws InvalidArgumentException {
1610: String argName = Util.THIS.getString("PROP_TextData");
1611: checkCharacterData(argName, data);
1612: checkEmptyString(argName, data, false);
1613:
1614: int index = data.indexOf('<');
1615: if (index != -1) {
1616: throw new InvalidArgumentException(data, Util.THIS
1617: .getString("PROP_invalid_text_data"));
1618: }
1619: index = data.indexOf('&');
1620: if (index != -1) {
1621: throw new InvalidArgumentException(data, Util.THIS
1622: .getString("PROP_invalid_text_data"));
1623: }
1624: index = data.indexOf("]]>");
1625: if (index != -1) {
1626: throw new InvalidArgumentException(data, Util.THIS
1627: .getString("PROP_invalid_text_data"));
1628: }
1629: }
1630:
1631: /**
1632: */
1633: public boolean isValidTextData(String data) {
1634: try {
1635: checkTextData(data);
1636: } catch (InvalidArgumentException exc) {
1637: return false;
1638: }
1639: return true;
1640: }
1641:
1642: /**
1643: */
1644: public void checkDocumentTypePublicId(String publicId)
1645: throws InvalidArgumentException {
1646: if (publicId == null) {
1647: return;
1648: }
1649: checkPublicId(Util.THIS
1650: .getString("PROP_DocumentTypePublicId"), publicId);
1651: }
1652:
1653: /**
1654: */
1655: public boolean isValidDocumentTypePublicId(String publicId) {
1656: try {
1657: checkDocumentTypePublicId(publicId);
1658: } catch (InvalidArgumentException exc) {
1659: return false;
1660: }
1661: return true;
1662: }
1663:
1664: /**
1665: */
1666: public void checkElementDeclContentType(
1667: TreeElementDecl.ContentType contentType)
1668: throws InvalidArgumentException {
1669: checkNullArgument(Util.THIS
1670: .getString("PROP_ElementDeclContentType"),
1671: contentType);
1672: // if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("[PENDING]: TreeUtilities::TreeConstraints.checkElementDeclContentType"); // NOI18N
1673: }
1674:
1675: /**
1676: */
1677: public boolean isValidElementDeclContentType(
1678: TreeElementDecl.ContentType contentType) {
1679: try {
1680: checkElementDeclContentType(contentType);
1681: } catch (InvalidArgumentException exc) {
1682: return false;
1683: }
1684: return true;
1685: }
1686:
1687: /**
1688: */
1689: public void checkDocumentVersion(String version)
1690: throws InvalidArgumentException {
1691: if (version == null)
1692: return;
1693: if (!!!version.equals("1.0")) { // NOI18N
1694: String arg = Util.THIS
1695: .getString("PROP_DocumentVersion");
1696: String msg = Util.THIS.getString(
1697: "PROP_invalid_version_number", version);
1698: throw new InvalidArgumentException(arg, msg);
1699: }
1700: }
1701:
1702: /**
1703: */
1704: public boolean isValidDocumentVersion(String version) {
1705: try {
1706: checkDocumentVersion(version);
1707: } catch (InvalidArgumentException exc) {
1708: return false;
1709: }
1710: return true;
1711: }
1712:
1713: /**
1714: */
1715: public void checkCDATASectionData(String data)
1716: throws InvalidArgumentException {
1717: checkCharacterData(Util.THIS
1718: .getString("PROP_CDATASectionData"), data);
1719:
1720: int index = data.indexOf("]]>"); // NOI18N
1721: if (index != -1) {
1722: throw new InvalidArgumentException(data, Util.THIS
1723: .getString("PROP_invalid_cdata_section_data"));
1724: }
1725: }
1726:
1727: /**
1728: */
1729: public boolean isValidCDATASectionData(String data) {
1730: try {
1731: checkCDATASectionData(data);
1732: } catch (InvalidArgumentException exc) {
1733: return false;
1734: }
1735: return true;
1736: }
1737:
1738: /**
1739: */
1740: public void checkNotationDeclPublicId(String publicId)
1741: throws InvalidArgumentException {
1742: if (publicId == null) {
1743: return;
1744: }
1745: checkPublicId(Util.THIS
1746: .getString("PROP_NotationDeclPublicId"), publicId);
1747: }
1748:
1749: /**
1750: */
1751: public boolean isValidNotationDeclPublicId(String publicId) {
1752: try {
1753: checkNotationDeclPublicId(publicId);
1754: } catch (InvalidArgumentException exc) {
1755: return false;
1756: }
1757: return true;
1758: }
1759:
1760: /**
1761: */
1762: public void checkAttlistDeclAttributeName(String attributeName)
1763: throws InvalidArgumentException {
1764: checkAttributeName(Util.THIS
1765: .getString("PROP_AttlistDeclAttributeName"),
1766: attributeName);
1767: }
1768:
1769: /**
1770: */
1771: public boolean isValidAttlistDeclAttributeName(
1772: String attributeName) {
1773: try {
1774: checkAttlistDeclAttributeName(attributeName);
1775: } catch (InvalidArgumentException exc) {
1776: return false;
1777: }
1778: return true;
1779: }
1780:
1781: /**
1782: */
1783: public void checkCommentData(String data)
1784: throws InvalidArgumentException {
1785: checkCharacterData(Util.THIS.getString("PROP_CommentData"),
1786: data);
1787:
1788: int index = data.indexOf("--"); // NOI18N
1789: if (index != -1) {
1790: throw new InvalidArgumentException(data, Util.THIS
1791: .getString("PROP_invalid_comment_data"));
1792: }
1793: if (data.endsWith("-")) { // NOI18N
1794: throw new InvalidArgumentException(data, Util.THIS
1795: .getString("PROP_invalid_comment_data_end"));
1796: }
1797: }
1798:
1799: /**
1800: */
1801: public boolean isValidCommentData(String data) {
1802: try {
1803: checkCommentData(data);
1804: } catch (InvalidArgumentException exc) {
1805: return false;
1806: }
1807: return true;
1808: }
1809:
1810: /**
1811: */
1812: public void checkAttlistDeclAttributeType(short type)
1813: throws InvalidArgumentException {
1814: if ((type != TreeAttlistDeclAttributeDef.TYPE_CDATA)
1815: && (type != TreeAttlistDeclAttributeDef.TYPE_ID)
1816: && (type != TreeAttlistDeclAttributeDef.TYPE_IDREF)
1817: && (type != TreeAttlistDeclAttributeDef.TYPE_IDREFS)
1818: && (type != TreeAttlistDeclAttributeDef.TYPE_ENTITY)
1819: && (type != TreeAttlistDeclAttributeDef.TYPE_ENTITIES)
1820: && (type != TreeAttlistDeclAttributeDef.TYPE_NMTOKEN)
1821: && (type != TreeAttlistDeclAttributeDef.TYPE_NMTOKENS)
1822: && (type != TreeAttlistDeclAttributeDef.TYPE_ENUMERATED)
1823: && (type != TreeAttlistDeclAttributeDef.TYPE_NOTATION)) {
1824: throw new InvalidArgumentException(
1825: new Short(type),
1826: Util.THIS
1827: .getString("PROP_invalid_attribute_list_declaration_type"));
1828: }
1829: }
1830:
1831: /**
1832: */
1833: public boolean isValidAttlistDeclAttributeType(short type) {
1834: try {
1835: checkAttlistDeclAttributeType(type);
1836: } catch (InvalidArgumentException exc) {
1837: return false;
1838: }
1839: return true;
1840: }
1841:
1842: /**
1843: */
1844: public void checkAttlistDeclAttributeDefaultType(
1845: short defaultType) throws InvalidArgumentException {
1846: if ((defaultType != TreeAttlistDeclAttributeDef.DEFAULT_TYPE_NULL)
1847: && (defaultType != TreeAttlistDeclAttributeDef.DEFAULT_TYPE_REQUIRED)
1848: && (defaultType != TreeAttlistDeclAttributeDef.DEFAULT_TYPE_IMPLIED)
1849: && (defaultType != TreeAttlistDeclAttributeDef.DEFAULT_TYPE_FIXED)) {
1850: throw new InvalidArgumentException(
1851: new Short(defaultType),
1852: Util.THIS
1853: .getString("PROP_invalid_attribute_list_declaration_default_type"));
1854: }
1855: }
1856:
1857: /**
1858: */
1859: public boolean isValidAttlistDeclAttributeDefaultType(
1860: short defaultType) {
1861: try {
1862: checkAttlistDeclAttributeDefaultType(defaultType);
1863: } catch (InvalidArgumentException exc) {
1864: return false;
1865: }
1866: return true;
1867: }
1868:
1869: } // end: class Constraints
1870:
1871: //
1872: // Encoding
1873: //
1874:
1875: /**
1876: */
1877: public static final Collection getSupportedEncodings() {
1878: return EncodingUtil.getIANA2JavaMap().keySet();
1879: }
1880:
1881: /**
1882: */
1883: public static final String iana2java(String iana) {
1884: String java = (String) EncodingUtil.getIANA2JavaMap().get(
1885: iana.toUpperCase());
1886: return java == null ? iana : java;
1887: }
1888:
1889: /**
1890: //!!! this code is copy pasted to xml.core.lib.Convertors!
1891: */
1892: static class EncodingUtil {
1893:
1894: /** IANA to Java encoding mappings */
1895: protected final static Map encodingIANA2JavaMap = new TreeMap();
1896:
1897: /** */
1898: protected final static Map encodingIANADescriptionMap = new TreeMap();
1899:
1900: /** */
1901: protected final static Map encodingIANAAliasesMap = new TreeMap();
1902:
1903: //
1904: // Static initialization
1905: //
1906:
1907: static {
1908: encodingIANA2JavaMap.put("BIG5", "Big5"); // NOI18N
1909: encodingIANADescriptionMap.put("BIG5", Util.THIS
1910: .getString("NAME_BIG5")); // NOI18N
1911: encodingIANAAliasesMap.put("BIG5", "BIG5"); // NOI18N
1912:
1913: encodingIANA2JavaMap.put("IBM037", "CP037"); // NOI18N
1914: encodingIANADescriptionMap.put("IBM037", Util.THIS
1915: .getString("NAME_IBM037")); // NOI18N
1916: encodingIANAAliasesMap.put("IBM037", "IBM037"); // NOI18N
1917: encodingIANAAliasesMap.put("EBCDIC-CP-US", "IBM037"); // NOI18N
1918: encodingIANAAliasesMap.put("EBCDIC-CP-CA", "IBM037"); // NOI18N
1919: encodingIANAAliasesMap.put("EBCDIC-CP-NL", "IBM037"); // NOI18N
1920: encodingIANAAliasesMap.put("EBCDIC-CP-WT", "IBM037"); // NOI18N
1921:
1922: encodingIANA2JavaMap.put("IBM277", "CP277"); // NOI18N
1923: encodingIANADescriptionMap.put("IBM277", Util.THIS
1924: .getString("NAME_IBM277")); // NOI18N
1925: encodingIANAAliasesMap.put("IBM277", "IBM277"); // NOI18N
1926: encodingIANAAliasesMap.put("EBCDIC-CP-DK", "IBM277"); // NOI18N
1927: encodingIANAAliasesMap.put("EBCDIC-CP-NO", "IBM277"); // NOI18N
1928:
1929: encodingIANA2JavaMap.put("IBM278", "CP278"); // NOI18N
1930: encodingIANADescriptionMap.put("IBM278", Util.THIS
1931: .getString("NAME_IBM277")); // NOI18N
1932: encodingIANAAliasesMap.put("IBM278", "IBM278"); // NOI18N
1933: encodingIANAAliasesMap.put("EBCDIC-CP-FI", "IBM278"); // NOI18N
1934: encodingIANAAliasesMap.put("EBCDIC-CP-SE", "IBM278"); // NOI18N
1935:
1936: encodingIANA2JavaMap.put("IBM280", "CP280"); // NOI18N
1937: encodingIANADescriptionMap.put("IBM280", Util.THIS
1938: .getString("NAME_IBM280")); // NOI18N
1939: encodingIANAAliasesMap.put("IBM280", "IBM280"); // NOI18N
1940: encodingIANAAliasesMap.put("EBCDIC-CP-IT", "IBM280"); // NOI18N
1941:
1942: encodingIANA2JavaMap.put("IBM284", "CP284"); // NOI18N
1943: encodingIANADescriptionMap.put("IBM284", Util.THIS
1944: .getString("NAME_IBM284")); // NOI18N
1945: encodingIANAAliasesMap.put("IBM284", "IBM284"); // NOI18N
1946: encodingIANAAliasesMap.put("EBCDIC-CP-ES", "IBM284"); // NOI18N
1947:
1948: encodingIANA2JavaMap.put("IBM285", "CP285"); // NOI18N
1949: encodingIANADescriptionMap.put("IBM285", Util.THIS
1950: .getString("NAME_IBM285")); // NOI18N
1951: encodingIANAAliasesMap.put("IBM285", "IBM285"); // NOI18N
1952: encodingIANAAliasesMap.put("EBCDIC-CP-GB", "IBM285"); // NOI18N
1953:
1954: encodingIANA2JavaMap.put("IBM297", "CP297"); // NOI18N
1955: encodingIANADescriptionMap.put("IBM297", Util.THIS
1956: .getString("NAME_IBM297")); // NOI18N
1957: encodingIANAAliasesMap.put("IBM297", "IBM297"); // NOI18N
1958: encodingIANAAliasesMap.put("EBCDIC-CP-FR", "IBM297"); // NOI18N
1959:
1960: encodingIANA2JavaMap.put("IBM424", "CP424"); // NOI18N
1961: encodingIANADescriptionMap.put("IBM424", Util.THIS
1962: .getString("NAME_IBM424")); // NOI18N
1963: encodingIANAAliasesMap.put("IBM424", "IBM424"); // NOI18N
1964: encodingIANAAliasesMap.put("EBCDIC-CP-HE", "IBM424"); // NOI18N
1965:
1966: encodingIANA2JavaMap.put("IBM500", "CP500"); // NOI18N
1967: encodingIANADescriptionMap.put("IBM500", Util.THIS
1968: .getString("NAME_IBM500")); // NOI18N
1969: encodingIANAAliasesMap.put("IBM500", "IBM500"); // NOI18N
1970: encodingIANAAliasesMap.put("EBCDIC-CP-CH", "IBM500"); // NOI18N
1971: encodingIANAAliasesMap.put("EBCDIC-CP-BE", "IBM500"); // NOI18N
1972:
1973: encodingIANA2JavaMap.put("IBM870", "CP870"); // NOI18N
1974: encodingIANADescriptionMap.put("IBM870", Util.THIS
1975: .getString("NAME_IBM870")); // NOI18N
1976: encodingIANAAliasesMap.put("IBM870", "IBM870"); // NOI18N
1977: encodingIANAAliasesMap.put("EBCDIC-CP-ROECE", "IBM870"); // NOI18N
1978: encodingIANAAliasesMap.put("EBCDIC-CP-YU", "IBM870"); // NOI18N
1979:
1980: encodingIANA2JavaMap.put("IBM871", "CP871"); // NOI18N
1981: encodingIANADescriptionMap.put("IBM871", Util.THIS
1982: .getString("NAME_IBM871")); // NOI18N
1983: encodingIANAAliasesMap.put("IBM871", "IBM871"); // NOI18N
1984: encodingIANAAliasesMap.put("EBCDIC-CP-IS", "IBM871"); // NOI18N
1985:
1986: encodingIANA2JavaMap.put("IBM918", "CP918"); // NOI18N
1987: encodingIANADescriptionMap.put("IBM918", Util.THIS
1988: .getString("NAME_IBM918")); // NOI18N
1989: encodingIANAAliasesMap.put("IBM918", "IBM918"); // NOI18N
1990: encodingIANAAliasesMap.put("EBCDIC-CP-AR2", "IBM918"); // NOI18N
1991:
1992: encodingIANA2JavaMap.put("EUC-JP", "EUCJIS"); // NOI18N
1993: encodingIANADescriptionMap.put("EUC-JP", Util.THIS
1994: .getString("NAME_EUC-JP")); // NOI18N
1995: encodingIANAAliasesMap.put("EUC-JP", "EUC-JP"); // NOI18N
1996:
1997: encodingIANA2JavaMap.put("EUC-KR", "KSC5601"); // NOI18N
1998: encodingIANADescriptionMap.put("EUC-KR", Util.THIS
1999: .getString("NAME_EUC-KR")); // NOI18N
2000: encodingIANAAliasesMap.put("EUC-KR", "EUC-KR"); // NOI18N
2001:
2002: encodingIANA2JavaMap.put("GB2312", "GB2312"); // NOI18N
2003: encodingIANADescriptionMap.put("GB2312", Util.THIS
2004: .getString("NAME_GB2312")); // NOI18N
2005: encodingIANAAliasesMap.put("GB2312", "GB2312"); // NOI18N
2006:
2007: encodingIANA2JavaMap.put("ISO-2022-JP", "JIS"); // NOI18N
2008: encodingIANADescriptionMap.put("ISO-2022-JP", Util.THIS
2009: .getString("NAME_ISO-2022-JP")); // NOI18N
2010: encodingIANAAliasesMap.put("ISO-2022-JP", "ISO-2022-JP"); // NOI18N
2011:
2012: encodingIANA2JavaMap.put("ISO-2022-KR", "ISO2022KR"); // NOI18N
2013: encodingIANADescriptionMap.put("ISO-2022-KR", Util.THIS
2014: .getString("NAME_ISO-2022-KR")); // NOI18N
2015: encodingIANAAliasesMap.put("ISO-2022-KR", "ISO-2022-KR"); // NOI18N
2016:
2017: encodingIANA2JavaMap.put("ISO-8859-1", "8859_1"); // NOI18N
2018: encodingIANADescriptionMap.put("ISO-8859-1", Util.THIS
2019: .getString("NAME_ISO-8859-1")); // NOI18N
2020: encodingIANAAliasesMap.put("ISO-8859-1", "ISO-8859-1"); // NOI18N
2021: encodingIANAAliasesMap.put("LATIN1", "ISO-8859-1"); // NOI18N
2022: encodingIANAAliasesMap.put("L1", "ISO-8859-1"); // NOI18N
2023: encodingIANAAliasesMap.put("IBM819", "ISO-8859-1"); // NOI18N
2024: encodingIANAAliasesMap.put("CP819", "ISO-8859-1"); // NOI18N
2025:
2026: encodingIANA2JavaMap.put("ISO-8859-2", "8859_2"); // NOI18N
2027: encodingIANADescriptionMap.put("ISO-8859-2", Util.THIS
2028: .getString("NAME_ISO-8859-2")); // NOI18N
2029: encodingIANAAliasesMap.put("ISO-8859-2", "ISO-8859-2"); // NOI18N
2030: encodingIANAAliasesMap.put("LATIN2", "ISO-8859-2"); // NOI18N
2031: encodingIANAAliasesMap.put("L2", "ISO-8859-2"); // NOI18N
2032:
2033: encodingIANA2JavaMap.put("ISO-8859-3", "8859_3"); // NOI18N
2034: encodingIANADescriptionMap.put("ISO-8859-3", Util.THIS
2035: .getString("NAME_ISO-8859-3")); // NOI18N
2036: encodingIANAAliasesMap.put("ISO-8859-3", "ISO-8859-3"); // NOI18N
2037: encodingIANAAliasesMap.put("LATIN3", "ISO-8859-3"); // NOI18N
2038: encodingIANAAliasesMap.put("L3", "ISO-8859-3"); // NOI18N
2039:
2040: encodingIANA2JavaMap.put("ISO-8859-4", "8859_4"); // NOI18N
2041: encodingIANADescriptionMap.put("ISO-8859-4", Util.THIS
2042: .getString("NAME_ISO-8859-4")); // NOI18N
2043: encodingIANAAliasesMap.put("ISO-8859-4", "ISO-8859-4"); // NOI18N
2044: encodingIANAAliasesMap.put("LATIN4", "ISO-8859-4"); // NOI18N
2045: encodingIANAAliasesMap.put("L4", "ISO-8859-4"); // NOI18N
2046:
2047: encodingIANA2JavaMap.put("ISO-8859-5", "8859_5"); // NOI18N
2048: encodingIANADescriptionMap.put("ISO-8859-5", Util.THIS
2049: .getString("NAME_ISO-8859-5")); // NOI18N
2050: encodingIANAAliasesMap.put("ISO-8859-5", "ISO-8859-5"); // NOI18N
2051: encodingIANAAliasesMap.put("CYRILLIC", "ISO-8859-5"); // NOI18N
2052:
2053: encodingIANA2JavaMap.put("ISO-8859-6", "8859_6"); // NOI18N
2054: encodingIANADescriptionMap.put("ISO-8859-6", Util.THIS
2055: .getString("NAME_ISO-8859-6")); // NOI18N
2056: encodingIANAAliasesMap.put("ISO-8859-6", "ISO-8859-6"); // NOI18N
2057:
2058: encodingIANA2JavaMap.put("ISO-8859-7", "8859_7"); // NOI18N
2059: encodingIANADescriptionMap.put("ISO-8859-7", Util.THIS
2060: .getString("NAME_ISO-8859-7")); // NOI18N
2061: encodingIANAAliasesMap.put("ISO-8859-7", "ISO-8859-7"); // NOI18N
2062: encodingIANAAliasesMap.put("GREEK", "ISO-8859-7"); // NOI18N
2063: encodingIANAAliasesMap.put("GREEK8", "ISO-8859-7"); // NOI18N
2064:
2065: encodingIANA2JavaMap.put("ISO-8859-8", "8859_8"); // NOI18N
2066: encodingIANADescriptionMap.put("ISO-8859-8", Util.THIS
2067: .getString("NAME_ISO-8859-8")); // NOI18N
2068: encodingIANAAliasesMap.put("ISO-8859-8", "ISO-8859-8"); // NOI18N
2069: encodingIANAAliasesMap.put("HEBREW", "ISO-8859-8"); // NOI18N
2070:
2071: encodingIANA2JavaMap.put("ISO-8859-9", "8859_9"); // NOI18N
2072: encodingIANADescriptionMap.put("ISO-8859-9", Util.THIS
2073: .getString("NAME_ISO-8859-9")); // NOI18N
2074: encodingIANAAliasesMap.put("ISO-8859-9", "ISO-8859-9"); // NOI18N
2075: encodingIANAAliasesMap.put("LATIN5", "ISO-8859-9"); // NOI18N
2076: encodingIANAAliasesMap.put("L5", "ISO-8859-9"); // NOI18N
2077:
2078: encodingIANA2JavaMap.put("KOI8-R", "KOI8_R"); // NOI18N
2079: encodingIANADescriptionMap.put("KOI8-R", Util.THIS
2080: .getString("NAME_KOI8-R")); // NOI18N
2081: encodingIANAAliasesMap.put("KOI8-R", "KOI8-R"); // NOI18N
2082:
2083: encodingIANA2JavaMap.put("US-ASCII", "8859_1"); // NOI18N
2084: encodingIANADescriptionMap.put("US-ASCII", Util.THIS
2085: .getString("NAME_ASCII")); // NOI18N
2086: encodingIANAAliasesMap.put("ASCII", "US-ASCII"); // NOI18N
2087: encodingIANAAliasesMap.put("US-ASCII", "US-ASCII"); // NOI18N
2088: encodingIANAAliasesMap.put("ISO646-US", "US-ASCII"); // NOI18N
2089: encodingIANAAliasesMap.put("IBM367", "US-ASCII"); // NOI18N
2090: encodingIANAAliasesMap.put("CP367", "US-ASCII"); // NOI18N
2091:
2092: encodingIANA2JavaMap.put("UTF-8", "UTF8"); // NOI18N
2093: encodingIANADescriptionMap.put("UTF-8", Util.THIS
2094: .getString("NAME_UTF-8")); // NOI18N
2095: encodingIANAAliasesMap.put("UTF-8", "UTF-8"); // NOI18N
2096:
2097: encodingIANA2JavaMap.put("UTF-16", "Unicode"); // NOI18N
2098: encodingIANADescriptionMap.put("UTF-16", Util.THIS
2099: .getString("NAME_UTF-16")); // NOI18N
2100: encodingIANAAliasesMap.put("UTF-16", "UTF-16"); // NOI18N
2101: }
2102:
2103: /**
2104: */
2105: public static Map getIANA2JavaMap() {
2106: return encodingIANA2JavaMap;
2107: }
2108:
2109: } // end: class EncodingUtil
2110:
2111: }
|