KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > NameToken


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.verifier;
24
25 import java.io.ByteArrayInputStream JavaDoc;
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28
29 import javax.xml.parsers.SAXParserFactory JavaDoc;
30
31 import org.xml.sax.InputSource JavaDoc;
32 import org.xml.sax.XMLReader JavaDoc;
33
34 import com.sun.enterprise.logging.LogDomains;
35 import tools.com.sun.enterprise.util.XMLValidationHandler;
36
37 public class NameToken {
38
39     final static String JavaDoc XMLtop =
40             "<!DOCTYPE NameToken [ <!ELEMENT NameToken EMPTY> <!ATTLIST NameToken value NMTOKEN #REQUIRED>]> <NameToken value=\""; // NOI18N
41

42
43     final static String JavaDoc XMLbottom = "\"/>"; // NOI18N
44

45     // Logger to log messages
46
private static Logger JavaDoc logger = LogDomains.getLogger(
47             LogDomains.AVK_VERIFIER_LOGGER);
48
49     /**
50      * Determine is value is legal NMToken type
51      *
52      * @param value xml element to be checked
53      * @return <code>boolean</code> true if xml element is legal NMToken,
54      * false otherwise
55      */

56     public static boolean isNMTOKEN(String JavaDoc value) {
57 /*
58         com.sun.enterprise.util.LocalStringManagerImpl smh =
59             StringManagerHelper.getLocalStringsManager();
60 */

61         String JavaDoc XMLdoc = XMLtop + value + XMLbottom;
62         logger.log(Level.FINE,
63                 "com.sun.enterprise.tools.verifier.NameToken.print", // NOI18N
64
new Object JavaDoc[]{XMLdoc});
65
66         try {
67             InputSource JavaDoc source = new InputSource JavaDoc(
68                     new ByteArrayInputStream JavaDoc(XMLdoc.getBytes()));
69             SAXParserFactory JavaDoc spf = SAXParserFactory.newInstance();
70             spf.setValidating(true);
71             // ValidatingParser p = new ValidatingParser();
72
XMLReader JavaDoc p = spf.newSAXParser().getXMLReader();
73 // XMLErrorHandler eh = new XMLErrorHandler(null);
74
p.setErrorHandler(new XMLValidationHandler());
75             p.parse(source);
76             return true;
77
78         } catch (Exception JavaDoc e) {
79             return false;
80         }
81     }
82 }
83
84
85
Popular Tags