KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > xml > XMLUtils


1 /*
2  * Copyright 1999-2005 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 package org.apache.cocoon.xml;
17
18 import java.io.StringWriter JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import javax.xml.transform.OutputKeys JavaDoc;
26 import javax.xml.transform.TransformerException JavaDoc;
27 import javax.xml.transform.TransformerFactory JavaDoc;
28 import javax.xml.transform.sax.SAXTransformerFactory JavaDoc;
29 import javax.xml.transform.sax.TransformerHandler JavaDoc;
30 import javax.xml.transform.stream.StreamResult JavaDoc;
31
32 import org.apache.cocoon.ProcessingException;
33 import org.apache.cocoon.xml.dom.DOMStreamer;
34 import org.w3c.dom.Attr JavaDoc;
35 import org.w3c.dom.Document JavaDoc;
36 import org.w3c.dom.Element JavaDoc;
37 import org.w3c.dom.NamedNodeMap JavaDoc;
38 import org.w3c.dom.Node JavaDoc;
39 import org.xml.sax.Attributes JavaDoc;
40 import org.xml.sax.ContentHandler JavaDoc;
41 import org.xml.sax.SAXException JavaDoc;
42 import org.xml.sax.ext.LexicalHandler JavaDoc;
43
44 /**
45  * XML utility methods.
46  *
47  * @author <a HREF="mailto:barozzi@nicolaken.com">Nicola Ken Barozzi</a>
48  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
49  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
50  * @version $Id: XMLUtils.java 343993 2005-11-13 22:46:05Z antonio $
51  */

52 public class XMLUtils {
53
54     /**
55      * Empty attributes immutable object.
56      */

57     public static final Attributes JavaDoc EMPTY_ATTRIBUTES = new ImmutableAttributesImpl();
58
59     private static final SAXTransformerFactory JavaDoc FACTORY = (SAXTransformerFactory JavaDoc) TransformerFactory.newInstance();
60     private static final Properties JavaDoc XML_FORMAT = createDefaultPropertiesForXML(false);
61     private static final Properties JavaDoc XML_FORMAT_NODECL = createDefaultPropertiesForXML(true);
62
63
64     // FIXME: parent parameter not used anymore
65
// Using parent because some dom implementations like jtidy are bugged,
66
// cannot get parent or delete child
67
public static void stripDuplicateAttributes(Node JavaDoc node, Node JavaDoc parent) {
68
69         // The output depends on the type of the node
70
switch(node.getNodeType()) {
71         case Node.DOCUMENT_NODE: {
72             Document JavaDoc doc = (Document JavaDoc)node;
73             Node JavaDoc child = doc.getFirstChild();
74             while(child != null) {
75                 stripDuplicateAttributes(child, node);
76                 child = child.getNextSibling();
77             }
78             break;
79         }
80
81         case Node.ELEMENT_NODE: {
82             Element JavaDoc elt = (Element JavaDoc) node;
83             NamedNodeMap JavaDoc attrs = elt.getAttributes();
84
85             ArrayList JavaDoc nodesToRemove = new ArrayList JavaDoc();
86             int nodesToRemoveNum = 0;
87
88             for(int i = 0; i < attrs.getLength(); i++) {
89                 final Node JavaDoc a = attrs.item(i);
90
91               for(int j = 0; j < attrs.getLength(); j++) {
92                     final Node JavaDoc b = attrs.item(j);
93
94                   //if there are two attributes with same name
95
if (i != j && (a.getNodeName().equals(b.getNodeName()))) {
96                     nodesToRemove.add(b);
97                     nodesToRemoveNum++;
98                   }
99               }
100             }
101
102             for (int i = 0; i < nodesToRemoveNum; i++) {
103               Attr JavaDoc nodeToDelete = (Attr JavaDoc) nodesToRemove.get(i);
104               Element JavaDoc nodeToDeleteParent = (Element JavaDoc)node; //nodeToDelete.getParentNode();
105
nodeToDeleteParent.removeAttributeNode(nodeToDelete);
106             }
107
108             nodesToRemove.clear();
109
110             Node JavaDoc child = elt.getFirstChild();
111             while(child != null) {
112                 stripDuplicateAttributes(child, node);
113                 child = child.getNextSibling();
114             }
115
116             break;
117         }
118
119         default:
120             //do nothing
121
break;
122         }
123     }
124
125     /**
126      * Get an <code>XMLConsumer</code> from a <code>ContentHandler</code> and
127      * a <code>LexicalHandler</code>. If the content handler is already an
128      * <code>XMLConsumer</code>, it is returned as is, otherwise it is wrapped
129      * in an <code>XMLConsumer</code> with the lexical handler.
130      *
131      * @param ch the content handler, which should not be <code>null</code>
132      * @param lh the lexical handler, which can be <code>null</code>
133      * @return an <code>XMLConsumer</code> for <code>ch</code> an <code>lh</code>
134      */

135     public static XMLConsumer getConsumer(ContentHandler JavaDoc ch, LexicalHandler JavaDoc lh) {
136         if (ch instanceof XMLConsumer) {
137             return (XMLConsumer)ch;
138         } else {
139             if (lh == null && ch instanceof LexicalHandler JavaDoc) {
140                 lh = (LexicalHandler JavaDoc)ch;
141             }
142             return new ContentHandlerWrapper(ch, lh);
143         }
144     }
145
146     /**
147      * Get an <code>XMLConsumer</code> from <code>ContentHandler</code>. If the
148      * content handler is already an <code>XMLConsumer</code>, it is returned as
149      * is, otherwise it is wrapped in an <code>XMLConsumer</code>.
150      *
151      * @param ch the content handler, which should not be <code>null</code>
152      * @return an <code>XMLConsumer</code> for <code>ch</code>
153      */

154     public static XMLConsumer getConsumer(ContentHandler JavaDoc ch) {
155         return getConsumer(ch, null);
156     }
157
158     /**
159      * Serialize a DOM node to a String.
160      * The defaultSerializeToXMLFormat() is used to format the serialized xml.
161      * @deprecated use serializeNode(Node, Properties) instead
162      */

163     public static String JavaDoc serializeNodeToXML(Node JavaDoc node)
164     throws ProcessingException {
165         return serializeNode(node, XMLUtils.defaultSerializeToXMLFormat());
166     }
167
168     /**
169      * This is the default properties set used to serialize xml.
170      * It is used by the serializeNodeToXML() method.
171      * The format is as follows:
172      * Method: xml
173      * Encoding: ISO-8859-1
174      * Omit xml declaration: no
175      * Indent: yes
176      * @deprecated Use createPropertiesForXML(false) instead and add the encoding
177      */

178     public static Properties JavaDoc defaultSerializeToXMLFormat() {
179         return defaultSerializeToXMLFormat(false);
180     }
181
182     /**
183      * This is the default properties set used to serialize xml.
184      * It is used by the serializeNodeToXML() method.
185      * The omit xml declaration property can be controlled by the flag.
186      * Method: xml
187      * Encoding: ISO-8859-1
188      * Omit xml declaration: according to the flag
189      * Indent: yes
190      * @deprecated Use createPropertiesForXML(boolean) instead and add the encoding
191      */

192     public static Properties JavaDoc defaultSerializeToXMLFormat(boolean omitXMLDeclaration) {
193         final Properties JavaDoc format = createPropertiesForXML(omitXMLDeclaration);
194         format.put(OutputKeys.ENCODING, "ISO-8859-1");
195         return format;
196     }
197
198     /**
199      * Method for static initializer
200      */

201     private static Properties JavaDoc createDefaultPropertiesForXML(boolean omitXMLDeclaration) {
202         final Properties JavaDoc format = new Properties JavaDoc();
203         format.put(OutputKeys.METHOD, "xml");
204         format.put(OutputKeys.OMIT_XML_DECLARATION, (omitXMLDeclaration ? "yes" : "no"));
205         format.put(OutputKeys.INDENT, "yes");
206         return format;
207     }
208
209     /**
210      * Create a new properties set for serializing xml.
211      * The omit xml declaration property can be controlled by the flag.
212      *
213      * <ul>
214      * <li>Method: xml
215      * <li>Omit xml declaration: according to the flag
216      * <li>Indent: yes
217      * </ul>
218      */

219     public static Properties JavaDoc createPropertiesForXML(boolean omitXMLDeclaration) {
220         /* Properties passed as parameters to the Properties constructor become "default properties".
221            But Xalan does not use the default properties, so they are lost.
222            Therefore, we must promote them to "set properties".
223         */

224         Properties JavaDoc propertiesForXML = new Properties JavaDoc(omitXMLDeclaration? XML_FORMAT_NODECL: XML_FORMAT);
225         for (Enumeration JavaDoc e = propertiesForXML.propertyNames(); e.hasMoreElements(); ) {
226             String JavaDoc propertyName = (String JavaDoc)e.nextElement();
227             propertiesForXML.setProperty(propertyName, propertiesForXML.getProperty(propertyName, ""));
228         }
229         return propertiesForXML;
230     }
231
232     /**
233      * Serialize a DOM node into a string using format created by
234      * <code>createPropertiesForXML(false)</code>.
235      *
236      * @see #createPropertiesForXML
237      */

238     public static String JavaDoc serializeNode(Node JavaDoc node)
239     throws ProcessingException {
240         // Don't create new properties as we do not intend to modify defaults.
241
return serializeNode(node, XML_FORMAT);
242     }
243
244     /**
245      * Serialize a DOM node into a string.
246      * If the node is null the empty string is returned.
247      *
248      * @param format The format of the output to be used by SAX transformer.
249      * @see OutputKeys
250      */

251     public static String JavaDoc serializeNode(Node JavaDoc node, Properties JavaDoc format)
252     throws ProcessingException {
253
254         try {
255             if (node == null) {
256                 return "";
257             }
258
259             StringWriter JavaDoc writer = new StringWriter JavaDoc();
260             TransformerHandler JavaDoc transformerHandler;
261             transformerHandler = FACTORY.newTransformerHandler();
262             transformerHandler.getTransformer().setOutputProperties(format);
263             transformerHandler.setResult(new StreamResult JavaDoc(writer));
264             if (node.getNodeType() != Node.DOCUMENT_NODE) {
265                 transformerHandler.startDocument();
266             }
267             DOMStreamer domStreamer = new DOMStreamer(transformerHandler, transformerHandler);
268             domStreamer.stream(node);
269             if (node.getNodeType() != Node.DOCUMENT_NODE) {
270                 transformerHandler.endDocument();
271             }
272
273             return writer.toString();
274         } catch (TransformerException JavaDoc e) {
275             throw new ProcessingException("TransformerException: " + e, e);
276         } catch (SAXException JavaDoc e) {
277             throw new ProcessingException("SAXException while streaming DOM node to SAX: " + e, e);
278         }
279     }
280
281     /**
282      * Serialize a XMLizable into a string.
283      * If the object is null the empty string is returned.
284      *
285      * @param format The format of the output to be used by SAX transformer.
286      * @see OutputKeys
287      */

288     public static String JavaDoc serialize(org.apache.excalibur.xml.sax.XMLizable xml, Properties JavaDoc format)
289     throws ProcessingException {
290         
291         try {
292             if (xml == null) {
293                 return "";
294             }
295
296             StringWriter JavaDoc writer = new StringWriter JavaDoc();
297             TransformerHandler JavaDoc transformerHandler;
298             transformerHandler = FACTORY.newTransformerHandler();
299             transformerHandler.getTransformer().setOutputProperties(format);
300             transformerHandler.setResult(new StreamResult JavaDoc(writer));
301             transformerHandler.startDocument();
302             xml.toSAX(new EmbeddedXMLPipe(transformerHandler));
303             transformerHandler.endDocument();
304
305             return writer.toString();
306         } catch (TransformerException JavaDoc e) {
307             throw new ProcessingException("TransformerException: " + e, e);
308         } catch (SAXException JavaDoc e) {
309             throw new ProcessingException("SAXException while streaming DOM node to SAX: " + e, e);
310         }
311     }
312
313     /**
314      * Add string data
315      *
316      * @param contentHandler The SAX content handler
317      * @param data The string data
318      */

319     public static void data(ContentHandler JavaDoc contentHandler,
320                             String JavaDoc data)
321     throws SAXException JavaDoc {
322
323         contentHandler.characters(data.toCharArray(), 0, data.length());
324     }
325
326     /**
327      * Implementation of &lt;xsp:expr&gt; for <code>String</code> :
328      * outputs characters representing the value.
329      *
330      * @param contentHandler the SAX content handler
331      * @param text the value
332      */

333     public static void valueOf(ContentHandler JavaDoc contentHandler, String JavaDoc text)
334     throws SAXException JavaDoc {
335
336         if (text != null) {
337             data(contentHandler, text);
338         }
339     }
340
341     /**
342      * Implementation of &lt;xsp:expr&gt; for <code>XMLizable</code> :
343      * outputs the value by calling <code>v.toSax(contentHandler)</code>.
344      *
345      * @param contentHandler the SAX content handler
346      * @param v the XML fragment
347      */

348     public static void valueOf(ContentHandler JavaDoc contentHandler,
349                                org.apache.excalibur.xml.sax.XMLizable v)
350     throws SAXException JavaDoc {
351
352         if (v != null) {
353             v.toSAX(contentHandler);
354         }
355     }
356
357     /**
358      * Implementation of &lt;xsp:expr&gt; for <code>org.w3c.dom.Node</code> :
359      * converts the Node to a SAX event stream.
360      *
361      * @param contentHandler the SAX content handler
362      * @param v the value
363      */

364     public static void valueOf(ContentHandler JavaDoc contentHandler, Node JavaDoc v)
365     throws SAXException JavaDoc {
366
367         if (v != null) {
368             DOMStreamer streamer = new DOMStreamer(contentHandler);
369             if (contentHandler instanceof LexicalHandler JavaDoc) {
370                 streamer.setLexicalHandler((LexicalHandler JavaDoc)contentHandler);
371             }
372             streamer.stream(v);
373         }
374     }
375
376     /**
377      * Implementation of &lt;xsp:expr&gt; for <code>java.util.Collection</code> :
378      * outputs the value by calling <code>xspExpr()</code> on each element of the
379      * collection.
380      *
381      * @param contentHandler the SAX content handler
382      * @param v the XML fragment
383      */

384     public static void valueOf(ContentHandler JavaDoc contentHandler,
385                                Collection JavaDoc v)
386     throws SAXException JavaDoc {
387
388         if (v != null) {
389             Iterator JavaDoc iterator = v.iterator();
390             while (iterator.hasNext()) {
391                 valueOf(contentHandler, iterator.next());
392             }
393         }
394      }
395
396     /**
397      * Implementation of &lt;xsp:expr&gt; for <code>Object</code> depending on its class :
398      * <ul>
399      * <li>if it's an array, call <code>xspExpr()</code> on all its elements,</li>
400      * <li>if it's class has a specific <code>xspExpr()</code>implementation, use it,</li>
401      * <li>else, output it's string representation.</li>
402      * </ul>
403      *
404      * @param contentHandler the SAX content handler
405      * @param v the value
406      */

407     public static void valueOf(ContentHandler JavaDoc contentHandler, Object JavaDoc v)
408     throws SAXException JavaDoc {
409
410         if (v == null) {
411             return;
412         }
413
414         // Array: recurse over each element
415
if (v.getClass().isArray()) {
416             Object JavaDoc[] elements = (Object JavaDoc[]) v;
417
418             for (int i = 0; i < elements.length; i++) {
419                 valueOf(contentHandler, elements[i]);
420             }
421             return;
422          }
423
424          // Check handled object types in case they were not typed in the XSP
425

426          // XMLizable
427
if (v instanceof org.apache.excalibur.xml.sax.XMLizable) {
428              valueOf(contentHandler, (org.apache.excalibur.xml.sax.XMLizable)v);
429              return;
430          }
431
432          // Node
433
if (v instanceof Node JavaDoc) {
434              valueOf(contentHandler, (Node JavaDoc)v);
435              return;
436          }
437
438          // Collection
439
if (v instanceof Collection JavaDoc) {
440              valueOf(contentHandler, (Collection JavaDoc)v);
441              return;
442          }
443
444          // Give up: hope it's a string or has a meaningful string representation
445
data(contentHandler, String.valueOf(v));
446     }
447
448     /**
449      * Create a start and endElement with a empty Namespace and without Attributes
450      *
451      * @param localName The local name (without prefix)
452      * @exception org.xml.sax.SAXException Any SAX exception, possibly
453      * wrapping another exception.
454      * @see #endElement(ContentHandler, String)
455      */

456     public static void createElement(ContentHandler JavaDoc contentHandler,
457                                      String JavaDoc localName)
458     throws SAXException JavaDoc {
459
460         startElement(contentHandler, localName);
461         endElement(contentHandler, localName);
462     }
463
464     /**
465      * Create a start and endElement with a empty Namespace and without Attributes
466      * The content of the Element is set to the stringValue parameter
467      *
468      * @param localName The local name (without prefix)
469      * @param stringValue The content of the Element
470      * @exception org.xml.sax.SAXException Any SAX exception, possibly
471      * wrapping another exception.
472      * @see #endElement(ContentHandler, String)
473      */

474     public static void createElement(ContentHandler JavaDoc contentHandler,
475                                      String JavaDoc localName,
476                                      String JavaDoc stringValue)
477         throws SAXException JavaDoc {
478
479         startElement(contentHandler, localName);
480         data(contentHandler, stringValue);
481         endElement(contentHandler, localName);
482     }
483
484     /**
485      * Create a start and endElement with a empty Namespace
486      *
487      * @param localName The local name (without prefix)
488      * @param atts The attributes attached to the element. If
489      * there are no attributes, it shall be an empty
490      * Attributes object.
491      * @exception org.xml.sax.SAXException Any SAX exception, possibly
492      * wrapping another exception.
493      * @see #endElement(ContentHandler, String)
494      * @see org.xml.sax.Attributes
495      */

496     public static void createElement(ContentHandler JavaDoc contentHandler,
497                                      String JavaDoc localName,
498                                      Attributes JavaDoc atts)
499     throws SAXException JavaDoc {
500
501         startElement(contentHandler, localName, atts);
502         endElement(contentHandler, localName);
503     }
504
505     /**
506      * Create a start and endElement with a empty Namespace
507      * The content of the Element is set to the stringValue parameter
508      *
509      * @param localName The local name (without prefix)
510      * @param atts The attributes attached to the element. If
511      * there are no attributes, it shall be an empty
512      * Attributes object.
513      * @param stringValue The content of the Element
514      * @exception org.xml.sax.SAXException Any SAX exception, possibly
515      * wrapping another exception.
516      * @see #endElement(ContentHandler, String)
517      * @see org.xml.sax.Attributes
518      */

519     public static void createElement(ContentHandler JavaDoc contentHandler,
520                                      String JavaDoc localName,
521                                      Attributes JavaDoc atts,
522                                      String JavaDoc stringValue)
523         throws SAXException JavaDoc {
524
525         startElement(contentHandler, localName, atts);
526         data(contentHandler, stringValue);
527         endElement(contentHandler, localName);
528     }
529
530     /**
531      * Create a start and endElement without Attributes
532      *
533      * @param localName The local name (without prefix)
534      * @exception org.xml.sax.SAXException Any SAX exception, possibly
535      * wrapping another exception.
536      * @see #endElement(ContentHandler, String)
537      */

538     public static void createElementNS(ContentHandler JavaDoc contentHandler,
539                                        String JavaDoc namespaceURI,
540                                        String JavaDoc localName)
541         throws SAXException JavaDoc {
542
543         startElement(contentHandler, namespaceURI, localName);
544         endElement(contentHandler, namespaceURI, localName);
545     }
546
547     /**
548      * Create a start and endElement without Attributes
549      * The content of the Element is set to the stringValue parameter
550      *
551      * @param localName The local name (without prefix)
552      * @param stringValue The content of the Element
553      * @exception org.xml.sax.SAXException Any SAX exception, possibly
554      * wrapping another exception.
555      * @see #endElement(ContentHandler, String)
556      */

557     public static void createElementNS(ContentHandler JavaDoc contentHandler,
558         String JavaDoc namespaceURI,
559         String JavaDoc localName,
560         String JavaDoc stringValue)
561     throws SAXException JavaDoc {
562
563         startElement(contentHandler, namespaceURI, localName);
564         data(contentHandler, stringValue);
565         endElement(contentHandler, namespaceURI, localName);
566     }
567
568     /**
569      * Create a start and endElement
570      *
571      * @param localName The local name (without prefix)
572      * @param atts The attributes attached to the element. If
573      * there are no attributes, it shall be an empty
574      * Attributes object.
575      * @exception org.xml.sax.SAXException Any SAX exception, possibly
576      * wrapping another exception.
577      * @see #endElement(ContentHandler, String)
578      * @see org.xml.sax.Attributes
579      */

580     public static void createElementNS(ContentHandler JavaDoc contentHandler,
581         String JavaDoc namespaceURI,
582         String JavaDoc localName,
583         Attributes JavaDoc atts)
584     throws SAXException JavaDoc {
585
586         startElement(contentHandler, namespaceURI, localName, atts);
587         endElement(contentHandler, namespaceURI, localName);
588     }
589
590     /**
591      * Create a start and endElement with a empty Namespace
592      * The content of the Element is set to the stringValue parameter
593      *
594      * @param localName The local name (without prefix)
595      * @param atts The attributes attached to the element. If
596      * there are no attributes, it shall be an empty
597      * Attributes object.
598      * @param stringValue The content of the Element
599      * @exception org.xml.sax.SAXException Any SAX exception, possibly
600      * wrapping another exception.
601      * @see #endElement(ContentHandler, String)
602      * @see org.xml.sax.Attributes
603      */

604     public static void createElementNS(ContentHandler JavaDoc contentHandler,
605         String JavaDoc namespaceURI,
606         String JavaDoc localName,
607         Attributes JavaDoc atts,
608         String JavaDoc stringValue)
609     throws SAXException JavaDoc {
610
611         startElement(contentHandler, namespaceURI, localName, atts);
612         data(contentHandler, stringValue);
613         endElement(contentHandler, namespaceURI, localName);
614     }
615
616
617     /**
618      * Create endElement with empty Namespace
619      *
620      * <p>For information on the names, see startElement.</p>
621      *
622      * @param localName The local name (without prefix)
623      * @exception org.xml.sax.SAXException Any SAX exception, possibly
624      * wrapping another exception.
625      */

626     public static void endElement(ContentHandler JavaDoc contentHandler,
627                                   String JavaDoc localName)
628     throws SAXException JavaDoc {
629
630         contentHandler.endElement("", localName, localName);
631     }
632
633     /**
634      * Create endElement
635      * Prefix must be mapped to empty String
636      *
637      * <p>For information on the names, see startElement.</p>
638      *
639      * @param localName The local name (without prefix)
640      * @exception org.xml.sax.SAXException Any SAX exception, possibly
641      * wrapping another exception.
642      */

643     public static void endElement(ContentHandler JavaDoc contentHandler,
644                                   String JavaDoc namespaceURI,
645                                   String JavaDoc localName)
646     throws SAXException JavaDoc {
647
648         contentHandler.endElement(namespaceURI, localName, localName);
649     }
650
651     /**
652      * Create a startElement with a empty Namespace and without Attributes
653      *
654      * @param localName The local name (without prefix)
655      * @exception org.xml.sax.SAXException Any SAX exception, possibly
656      * wrapping another exception.
657      * @see #endElement(ContentHandler, String)
658      */

659     public static void startElement(ContentHandler JavaDoc contentHandler,
660                                     String JavaDoc localName)
661     throws SAXException JavaDoc {
662
663         contentHandler.startElement("", localName, localName, EMPTY_ATTRIBUTES);
664     }
665
666     /**
667      * Create a startElement without Attributes
668      * Prefix must be mapped to empty String
669      *
670      * @param namespaceURI The Namespace URI
671      * @param localName The local name (without prefix)
672      * @exception org.xml.sax.SAXException Any SAX exception, possibly
673      * wrapping another exception.
674      * @see #endElement(ContentHandler, String)
675      */

676     public static void startElement(ContentHandler JavaDoc contentHandler,
677                                     String JavaDoc namespaceURI,
678                                     String JavaDoc localName)
679     throws SAXException JavaDoc {
680
681         contentHandler.startElement(namespaceURI, localName, localName, EMPTY_ATTRIBUTES);
682     }
683
684     /**
685      * Create a startElement with a empty Namespace
686      *
687      * @param localName The local name (without prefix)
688      * @param atts The attributes attached to the element. If
689      * there are no attributes, it shall be an empty
690      * Attributes object.
691      * @exception org.xml.sax.SAXException Any SAX exception, possibly
692      * wrapping another exception.
693      * @see #endElement(ContentHandler, String)
694      * @see org.xml.sax.Attributes
695      */

696     public static void startElement(ContentHandler JavaDoc contentHandler,
697                                     String JavaDoc localName,
698                                     Attributes JavaDoc atts)
699     throws SAXException JavaDoc {
700
701         contentHandler.startElement("", localName, localName, atts);
702     }
703
704     /**
705      * Create a startElement with a empty Namespace
706      * Prefix must be mapped to empty String
707      *
708      * @param namespaceURI The Namespace URI
709      * @param localName The local name (without prefix)
710      * @param atts The attributes attached to the element. If
711      * there are no attributes, it shall be an empty
712      * Attributes object.
713      * @exception org.xml.sax.SAXException Any SAX exception, possibly
714      * wrapping another exception.
715      * @see #endElement(ContentHandler, String)
716      * @see org.xml.sax.Attributes
717      */

718     public static void startElement(ContentHandler JavaDoc contentHandler,
719                                     String JavaDoc namespaceURI,
720                                     String JavaDoc localName,
721                                     Attributes JavaDoc atts)
722     throws SAXException JavaDoc {
723
724         contentHandler.startElement(namespaceURI, localName, localName, atts);
725     }
726 }
727
Popular Tags