📄 infoconfigparser.java
字号:
package org.jawin.browser.info;
import org.xml.sax.ext.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import java.io.*;
import org.jawin.browser.config.ConfigManager;
import org.jawin.browser.log.Log;
/**
* SAX parse out the info configuration file, populating the
* InfoConfigManager singleton with configuration which is used
* to generate documentation on browsed nodes.
*
* <p>Title: Jawin Code Generation GUI</p>
* <p>Description: GUI for exploring type libraries and generating Java code</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Open Source Incentive</p>
*
* @author Josh Passenger
* @version 1.0
*/
public class InfoConfigParser extends DefaultHandler
{
/**
* The Sax parser class to use
*/
private String parserName = ConfigManager.getInstance().getString("sax.parser", "org.apache.xerces.parsers.SAXParser");
/**
* The parser that will actually pasre the document
*/
private XMLReader xmlReader = null;
public InfoConfigParser()
{
try
{
xmlReader = XMLReaderFactory.createXMLReader(parserName);
xmlReader.setContentHandler(this);
}
catch (Exception e)
{
Log.getInstance().exception("InfoConfigParser() failed to create SAX parser, no info config is available", e);
}
}
/**
* @todo implement config file parsing and throw SaxException
*
* @param codeGenConfigFile
*/
public void parseInfoConfig(String codeGenConfigFile)
{
FileInputStream fileIn = null;
try
{
fileIn = new FileInputStream(codeGenConfigFile);
InputSource in = new InputSource(fileIn);
xmlReader.parse(in);
}
catch (Exception e)
{
Log.getInstance().exception("InfoConfigParser.parseCodeGenConfig() failed to parse info config file: " + codeGenConfigFile, e);
}
finally
{
if (fileIn != null)
{
try
{
fileIn.close();
}
catch (Exception e)
{
}
}
}
}
/**
* Fired when the start of a doucment is encountered
*
* @throws SAXException thrown if something goes wrong
*/
public void startDocument() throws SAXException
{
InfoConfigManager.getInstance().clearConfig();
}
/**
* Fired when a n element is started
* @param uri
* @param localName
* @param qualifiedName
* @param attributes
* @throws SAXException
*/
public void startElement(String uri, String localName, String qualifiedName, Attributes attributes) throws SAXException
{
if (qualifiedName.equals("info"))
{
String className = getAttribute("class", attributes);
boolean info = Boolean.valueOf(attributes.getValue("info")).booleanValue();
String stylesheet = "";
if (info)
{
stylesheet = getAttribute("stylesheet", attributes);
}
InfoConfig config = new InfoConfig(className, info, stylesheet);
InfoConfigManager.getInstance().addInfoConfig(config);
}
}
/**
* Fetches the value of a required attribute
*
* @param name the name of the attribute to fetch
* @param attributes the attributes on the node
* @return the value of the named attribute
* @throws SAXException thrown if the attribute does not exist
*/
private String getAttribute(String name, Attributes attributes) throws SAXException
{
String value = attributes.getValue(name);
if (value == null || value.equals(""))
{
throw new SAXException("InfoConfigParser.getAttribute() a required attribute was missing: " + name);
}
return value;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -