|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.tasklist.core.translators; import java.util.Collection; import java.util.List; import java.util.Stack; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; /** * Helps to create XML. * * @author Tim Lebedkov * @version $Id: XMLCreator.java,v 1.3 2004/02/20 11:44:32 pkuzel Exp $ */ public class XMLCreator { private ContentHandler ch; private AttributesImpl atts = new AttributesImpl(); private Stack elements = new Stack(); /** * Constructor * * @param ch XML content handler */ public XMLCreator(ContentHandler ch) { this.ch = ch; } /** * Receive notification of character data. * * @param s The characters from the XML document. if null nothing will * be printed * @exception org.xml.sax.SAXException Any SAX exception, possibly * wrapping another exception. */ public void ch(String s) throws SAXException { if(s == null) return; char[] ch = s.toCharArray(); this.ch.characters(ch, 0, ch.length); } /** * Starts an element * * @param qName The qualified name (with prefix), or the * empty string if qualified names are not available. */ public void e(String qName) throws SAXException { atts.clear(); ch.startElement("", "", qName, atts); elements.push(qName); } /** * Starts an element * * @param qName The qualified name (with prefix), or the * empty string if qualified names are not available. * @param attrs Attributes {name, value, name, value}. String[] * if null is used as a value attribute will not be created */ public void e(String qName, Collection attrs) throws SAXException { e(qName, (String[]) attrs.toArray(new String[attrs.size()])); } /** * Starts an element * * @param qName The qualified name (with prefix), or the * empty string if qualified names are not available. * @param attrs Attributes {name, value, name, value} * if null is used as a value attribute will not be created */ private void e(String qName, String[] attrs) throws SAXException { atts.clear(); for(int i = 0; i < attrs.length; i += 2) { if(attrs[i + 1] != null) atts.addAttribute("", "", attrs[i], "", attrs[i + 1]); } ch.startElement("", "", qName, atts); elements.push(qName); } /** * Closes an element */ public void ee() throws SAXException { ch.endElement("", "", (String) elements.pop()); } /** * Receive notification of the beginning of a document. * * |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.