converterparser.java
来自「swing编写的库存管理程序。毕业设计类」· Java 代码 · 共 536 行 · 第 1/2 页
JAVA
536 行
/**
* ========================================
* JFreeReport : a free Java report library
* ========================================
*
* Project Info: http://www.jfree.org/jfreereport/index.html
* Project Lead: Thomas Morgner (taquera@sherito.org);
*
* (C) Copyright 2000-2003, by Simba Management Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* ------------------------------
* ConverterParser.java
* ------------------------------
* (C)opyright 2003, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: ConverterParser.java,v 1.6 2003/11/07 18:33:53 taqua Exp $
*
* Changes
* -------------------------
* 25-Jul-2003 : Initial version
*
*/
package org.jfree.report.modules.gui.converter.parser;
import java.util.Stack;
import org.jfree.xml.ElementDefinitionHandler;
import org.jfree.xml.Parser;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/**
* The ConverterParser is a filtering proxy implementation that uses the
* mappings defined in this package to modify the parsed attribute values
* on the fly into the new values.
*
* @author Thomas Morgner
*/
public class ConverterParser extends Parser
{
/** The backend parser. */
private final Parser base;
/** the context collection used to create the correct mappings. */
private final Stack currentContext;
/**
* Creates a new ConverterParser using the given parser as backend.
*
* @param base the backend parser that will do all the work.
*/
public ConverterParser(final Parser base)
{
this.base = base;
currentContext = new Stack();
}
/**
* Receive notification of the end of the document.
* Updates the context and forwards the event to the base parser.
*
* @exception SAXException Any SAX exception, possibly wrapping another exception.
*
* @param uri the URI.
* @param localName the element type name.
* @param qName the name.
* @see org.xml.sax.ContentHandler#endDocument
*/
public void endElement(final String uri, final String localName, final String qName)
throws SAXException
{
currentContext.pop();
base.endElement(uri, localName, qName);
}
/**
* Receive notification of the start of an element.
* Updates the context and forwards the event to the base parser.
*
* @param uri the URI.
* @param localName the element type name.
* @param qName the name.
* @param attributes the specified or defaulted attributes.
*
* @exception SAXException Any SAX exception, possibly
* wrapping another exception.
* @see org.xml.sax.ContentHandler#startElement
*/
public void startElement(final String uri, final String localName,
final String qName, final Attributes attributes)
throws SAXException
{
TranslationTableFactory.ContextRule rule = null;
if (currentContext.isEmpty() == false)
{
final Object o = currentContext.peek();
if (o instanceof TranslationTableFactory.ContextRule)
{
rule = (TranslationTableFactory.ContextRule) o;
}
}
rule = TranslationTableFactory.getInstance().buildContext(rule, qName);
if (rule == null)
{
// do not translate ..
currentContext.push(qName);
base.startElement(uri, localName, qName, attributes);
}
else
{
// do translate ..
currentContext.push(rule);
final TranslationTable table =
TranslationTableFactory.getInstance().getTranslationTable(rule);
base.startElement(uri, localName, qName, new ConverterAttributes(attributes, table));
}
}
/**
* Allow the application to resolve external entities.
*
* <p>The Parser will call this method before opening any external
* entity except the top-level document entity (including the
* external DTD subset, external entities referenced within the
* DTD, and external entities referenced within the document
* element): the application may request that the parser resolve
* the entity itself, that it use an alternative URI, or that it
* use an entirely different input source.</p>
*
* <p>If the system identifier is a URL, the SAX parser must
* resolve it fully before reporting it to the application.</p>
*
* <p>The official SAX implementation declares that it also throws an
* IOException, while the JDK1.4 SAX2 implementation doesn't.
* We catch all exceptions here and map them into the SAXException
* to resolve that issue.</p>
*
* @param publicId The public identifier of the external entity
* being referenced, or null if none was supplied.
* @param systemId The system identifier of the external entity
* being referenced.
* @return An InputSource object describing the new input source,
* or null to request that the parser open a regular
* URI connection to the system identifier.
* @exception SAXException Any SAX exception, possibly
* wrapping another exception.
* @see InputSource
*/
public InputSource resolveEntity(final String publicId,
final String systemId)
throws SAXException
{
try
{
return base.resolveEntity(publicId, systemId);
}
catch (Exception oe)
{
// this one drives me crazy, in JDK 1.4 the IOException
// is not defined, but in the official SAX sources it is
// defined. Now depending on which version you compile it
// gives an differen error. I HATE THIS!
throw new SAXException(oe);
}
}
/**
* Receive notification of a notation declaration event.
*
* <p>It is up to the application to record the notation for later
* reference, if necessary.</p>
*
* <p>At least one of publicId and systemId must be non-null.
* If a system identifier is present, and it is a URL, the SAX
* parser must resolve it fully before passing it to the
* application through this event.</p>
*
* <p>There is no guarantee that the notation declaration will be
* reported before any unparsed entities that use it.</p>
*
* @param name The notation name.
* @param publicId The notation's public identifier, or null if
* none was given.
* @param systemId The notation's system identifier, or null if
* none was given.
* @exception SAXException Any SAX exception, possibly
* wrapping another exception.
* @see #unparsedEntityDecl
*/
public void notationDecl(final String name,
final String publicId,
final String systemId)
throws SAXException
{
base.notationDecl(name, publicId, systemId);
}
/**
* Receive notification of an unparsed entity declaration event.
*
* <p>Note that the notation name corresponds to a notation
* reported by the {@link #notationDecl notationDecl} event.
* It is up to the application to record the entity for later
* reference, if necessary.</p>
*
* <p>If the system identifier is a URL, the parser must resolve it
* fully before passing it to the application.</p>
*
* @exception SAXException Any SAX exception, possibly
* wrapping another exception.
* @param name The unparsed entity's name.
* @param publicId The entity's public identifier, or null if none
* was given.
* @param systemId The entity's system identifier.
* @param notationName name The name of the associated notation.
* @see #notationDecl
*/
public void unparsedEntityDecl(final String name,
final String publicId,
final String systemId,
final String notationName)
throws SAXException
{
base.unparsedEntityDecl(name, publicId, systemId, notationName);
}
/**
* Receive notification of a warning.
*
* <p>SAX parsers will use this method to report conditions that
* are not errors or fatal errors as defined by the XML 1.0
* recommendation. The default behaviour is to take no action.</p>
*
* <p>The SAX parser must continue to provide normal parsing events
* after invoking this method: it should still be possible for the
* application to process the document through to the end.</p>
*
* <p>Filters may use this method to report other, non-XML warnings
* as well.</p>
*
* @param exception The warning information encapsulated in a
* SAX parse exception.
* @exception SAXException Any SAX exception, possibly
* wrapping another exception.
* @see SAXParseException
*/
public void warning(final SAXParseException exception)
throws SAXException
{
base.warning(exception);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?