KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xni > UpperCaseFilter


1 /*
2  * Copyright 2001, 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package xni;
18
19 import org.apache.xerces.xni.Augmentations;
20 import org.apache.xerces.xni.QName;
21 import org.apache.xerces.xni.XMLAttributes;
22 import org.apache.xerces.xni.XNIException;
23  
24 /**
25  * This sample demonstrates how to create a filter for the document
26  * "streaming" information set that turns element names into upper
27  * case.
28  * <p>
29  * <strong>Note:</strong> This sample does not contain a
30  * <code>main</code> method and cannot be run. It is only for
31  * demonstration purposes.
32  *
33  * @author Andy Clark, IBM
34  *
35  * @version $Id: UpperCaseFilter.java,v 1.5 2004/02/24 23:41:05 mrglavas Exp $
36  */

37 public class UpperCaseFilter
38     extends PassThroughFilter {
39     
40     //
41
// Data
42
//
43

44     /**
45      * Temporary QName structure used by the <code>toUpperCase</code>
46      * method. It should not be used anywhere else.
47      *
48      * @see #toUpperCase
49      */

50     private final QName fQName = new QName();
51
52     //
53
// XMLDocumentHandler methods
54
//
55

56     /**
57      * The start of an element.
58      *
59      * @param element The name of the element.
60      * @param attributes The element attributes.
61      *
62      * @throws XNIException Thrown by handler to signal an error.
63      */

64     public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
65         throws XNIException {
66         super.startElement(toUpperCase(element), attributes, augs);
67     } // startElement(QName,XMLAttributes)
68

69     /**
70      * An empty element.
71      *
72      * @param element The name of the element.
73      * @param attributes The element attributes.
74      *
75      * @throws XNIException Thrown by handler to signal an error.
76      */

77     public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
78         throws XNIException {
79         super.emptyElement(toUpperCase(element), attributes, augs);
80     } // emptyElement(QName,XMLAttributes)
81

82     /**
83      * The end of an element.
84      *
85      * @param element The name of the element.
86      *
87      * @throws XNIException Thrown by handler to signal an error.
88      */

89     public void endElement(QName element, Augmentations augs)
90         throws XNIException {
91         super.endElement(toUpperCase(element), augs);
92     } // endElement(QName)
93

94     //
95
// Protected methods
96
//
97

98     /**
99      * This method upper-cases the prefix, localpart, and rawname
100      * fields in the specified QName and returns a different
101      * QName object containing the upper-cased string values.
102      *
103      * @param qname The QName to upper-case.
104      */

105     protected QName toUpperCase(QName qname) {
106         String JavaDoc prefix = qname.prefix != null
107                       ? qname.prefix.toUpperCase() : null;
108         String JavaDoc localpart = qname.localpart != null
109                          ? qname.localpart.toUpperCase() : null;
110         String JavaDoc rawname = qname.rawname != null
111                        ? qname.rawname.toUpperCase() : null;
112         String JavaDoc uri = qname.uri;
113         fQName.setValues(prefix, localpart, rawname, uri);
114         return fQName;
115     } // toUpperCase(QName):QName
116

117 } // class UpperCaseFilter
118
Popular Tags