当前位置: 技术问答>java相关
各位帮我看看下面的代码
来源: 互联网 发布时间:2015-07-03
本文导语: 最近在网上得到XmlParser.java 我编译的时候出现以下错误,我对java的概念理解很少,希望给我指导一下: 环境:win2000+JDK1.4+Tomcat4.03 下面是你的代码: package mvc; import java.util.HashMap; import org.xml.sax.InputSource; import ...
最近在网上得到XmlParser.java
我编译的时候出现以下错误,我对java的概念理解很少,希望给我指导一下:
环境:win2000+JDK1.4+Tomcat4.03
下面是你的代码:
package mvc;
import java.util.HashMap;
import org.xml.sax.InputSource;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
public class XmlParser {
public static final String URL_MAPPING = "url-mapping";
public static final String SCREEN_DEFINITION = "screen-definition";
public static final String URL = "url";
public static final String TEMPLATE = "template";
public static final String RESULT = "result";
public static final String NEXT_SCREEN = "screen";
public static final String SCREEN = "screen";
public static final String SCREEN_NAME = "screen-name";
public static final String PARAMETER = "parameter";
public static final String USE_REQUEST_HANDLER = "useRequestHandler";
public static final String REQUIRES_SIGNIN = "requiresSignin";
public static final String USE_FLOW_HANDLER = "useFlowHandler";
public static final String FLOW_HANDLER_CLASS = "class";
public static final String REQUEST_HANDLER_CLASS = "request-handler-class";
public static final String HANDLER_RESULT = "handler-result";
public static final String FLOW_HANDLER = "flow-handler";
public static final String DEFAULT_SCREEN = "default-screen";
public static final String SIGNIN_ERROR_SCREEN = "signin-error-screen";
public static final String KEY = "key";
public static final String VALUE = "value";
public static final String DIRECT = "direct";
public XmlParser () {
}
public static Element loadDocument (String location) {
Document doc = null;
try {
URL url = new URL(/tech-qa-java/location/index.html);
InputSource xmlInp = new InputSource(url.openStream());
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
doc = parser.parse(xmlInp);
Element root = doc.getDocumentElement();
root.normalize();
return root;
} catch (SAXParseException err) {
Debug.println("XmlParser ** Parsing error" + ", line " +
err.getLineNumber() + ", uri " + err.getSystemId());
Debug.println("XmlParser error: " + err.getMessage());
} catch (SAXException e) {
Debug.println("XmlParser error: " + e);
} catch (java.net.MalformedURLException mfx) {
Debug.println("XmlParser error: " + mfx);
} catch (java.io.IOException e) {
Debug.println("XmlParser error: " + e);
} catch (Exception pce) {
Debug.println("XmlParser error: " + pce);
}
return null;
}
/**
* put your documentation comment here
* @param location
* @return
*/
public static ScreenFlowData loadScreenFlowData (String location) {
Element root = loadDocument(location);
HashMap screenDefinitionMappings = getScreenDefinitions(root);
String defaultScreen = getTagValue(root, DEFAULT_SCREEN);
String signinErrorScreen = getTagValue(root, SIGNIN_ERROR_SCREEN);
return new ScreenFlowData(screenDefinitionMappings, defaultScreen,
signinErrorScreen);
}
/**
* put your documentation comment here
* @param location
* @return
*/
public static HashMap loadScreenDefinitions (String location) {
Element root = loadDocument(location);
return getScreens(root);
}
/**
* put your documentation comment here
* @param location
* @return
*/
public static HashMap loadRequestMappings (String location) {
Element root = loadDocument(location);
return getRequestMappings(root);
}
public static HashMap loadScreenDefinitionMappings (String location) {
Element root = loadDocument(location);
return getScreenDefinitions(root);
}
/**
* 获取tagName结点的子结点subTagName的attribute属性
* put your documentation comment here
* @param location
* @return
*/
private static String getSubTagAttribute (Element root, String tagName,
String subTagName, String attribute) {
String returnString = "";
NodeList list = root.getElementsByTagName(tagName);
for (int loop = 0; loop
我编译的时候出现以下错误,我对java的概念理解很少,希望给我指导一下:
环境:win2000+JDK1.4+Tomcat4.03
下面是你的代码:
package mvc;
import java.util.HashMap;
import org.xml.sax.InputSource;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
public class XmlParser {
public static final String URL_MAPPING = "url-mapping";
public static final String SCREEN_DEFINITION = "screen-definition";
public static final String URL = "url";
public static final String TEMPLATE = "template";
public static final String RESULT = "result";
public static final String NEXT_SCREEN = "screen";
public static final String SCREEN = "screen";
public static final String SCREEN_NAME = "screen-name";
public static final String PARAMETER = "parameter";
public static final String USE_REQUEST_HANDLER = "useRequestHandler";
public static final String REQUIRES_SIGNIN = "requiresSignin";
public static final String USE_FLOW_HANDLER = "useFlowHandler";
public static final String FLOW_HANDLER_CLASS = "class";
public static final String REQUEST_HANDLER_CLASS = "request-handler-class";
public static final String HANDLER_RESULT = "handler-result";
public static final String FLOW_HANDLER = "flow-handler";
public static final String DEFAULT_SCREEN = "default-screen";
public static final String SIGNIN_ERROR_SCREEN = "signin-error-screen";
public static final String KEY = "key";
public static final String VALUE = "value";
public static final String DIRECT = "direct";
public XmlParser () {
}
public static Element loadDocument (String location) {
Document doc = null;
try {
URL url = new URL(/tech-qa-java/location/index.html);
InputSource xmlInp = new InputSource(url.openStream());
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
doc = parser.parse(xmlInp);
Element root = doc.getDocumentElement();
root.normalize();
return root;
} catch (SAXParseException err) {
Debug.println("XmlParser ** Parsing error" + ", line " +
err.getLineNumber() + ", uri " + err.getSystemId());
Debug.println("XmlParser error: " + err.getMessage());
} catch (SAXException e) {
Debug.println("XmlParser error: " + e);
} catch (java.net.MalformedURLException mfx) {
Debug.println("XmlParser error: " + mfx);
} catch (java.io.IOException e) {
Debug.println("XmlParser error: " + e);
} catch (Exception pce) {
Debug.println("XmlParser error: " + pce);
}
return null;
}
/**
* put your documentation comment here
* @param location
* @return
*/
public static ScreenFlowData loadScreenFlowData (String location) {
Element root = loadDocument(location);
HashMap screenDefinitionMappings = getScreenDefinitions(root);
String defaultScreen = getTagValue(root, DEFAULT_SCREEN);
String signinErrorScreen = getTagValue(root, SIGNIN_ERROR_SCREEN);
return new ScreenFlowData(screenDefinitionMappings, defaultScreen,
signinErrorScreen);
}
/**
* put your documentation comment here
* @param location
* @return
*/
public static HashMap loadScreenDefinitions (String location) {
Element root = loadDocument(location);
return getScreens(root);
}
/**
* put your documentation comment here
* @param location
* @return
*/
public static HashMap loadRequestMappings (String location) {
Element root = loadDocument(location);
return getRequestMappings(root);
}
public static HashMap loadScreenDefinitionMappings (String location) {
Element root = loadDocument(location);
return getScreenDefinitions(root);
}
/**
* 获取tagName结点的子结点subTagName的attribute属性
* put your documentation comment here
* @param location
* @return
*/
private static String getSubTagAttribute (Element root, String tagName,
String subTagName, String attribute) {
String returnString = "";
NodeList list = root.getElementsByTagName(tagName);
for (int loop = 0; loop