📄 loaderxincluder.java
字号:
if (name.equals("loaderJob")) {
out.write(" xmlns='http://www.objectweb.org'");
out.write(" xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'");
out.write(" xsi:schemaLocation='http://www.objectweb.org http://octopus.objectweb.org/doc/XmlTransform/xml/xmlschema/loaderJob.xsd'");
out.write(" ");
}
// if(name.startsWith("jdbc"))
// counter5++;
// if(!name.startsWith("jdbc") && counter5!=0 && firstPartXml==true){
// LocationOfException.setJdbcNumber(counter5);
// firstPartXml=false;
// counter5=0;
// }
//System.out.println("atts="+atts);
for (int i = 0; i < atts.getLength(); i++) {
out.write(" ");
out.write(atts.getName(i));
out.write("='");
String value = atts.getValue(i);
// + 4 allows space for one entitiy reference.
// If there's more than that, then the StringBuffer
// will automatically expand
// Need to use character references if the encoding
// can't support the character
StringBuffer encodedValue = new StringBuffer(value.length() + 4);
for (int j = 0; j < value.length(); j++) {
char c = value.charAt(j);
if (c == '&')
encodedValue.append("&");
else if (c == '<')
encodedValue.append("<");
else if (c == '>')
encodedValue.append(">");
else if (c == '\'')
encodedValue.append("'");
else
encodedValue.append(c);
}
out.write(encodedValue.toString());
out.write("'");
}
out.write(">");
}
}
catch (IOException e) {
System.err.println(e);
Logger.getCentralLogger().write("normal", e.getMessage());
}
catch (SAXException ex) {
System.err.println(ex);
Logger.getCentralLogger().write("normal", ex.getMessage());
}
}
/** Characters.
* @param ch is array of characters
* @param start is int
* @param length is length of the input parameters
* @throws SAXException
*/
public void characters(char ch[], int start, int length) throws SAXException {
try {
for (int i = 0; i < length; i++) {
char c = ch[start + i];
if (c == '&')
out.write("&");
else if (c == '<')
out.write("<");
else if (c == '\n') {
counter2++;
out.write(c);
} else
out.write(c);
}
}
catch (IOException e) {
System.err.println(e);
Logger.getCentralLogger().write("normal", e.getMessage());
}
}
/** Ignorable whitespace.
* @param ch is array of characters
* @param start is int
* @param length is length of the input parameters
*/
public void ignorableWhitespace(char ch[], int start, int length) {
try {
this.characters(ch, start, length);
}
catch (SAXException e) {
System.err.println(e);
Logger.getCentralLogger().write("normal", e.getMessage());
}
}
/** End element.
* @param name is name of the tag
*/
public void endElement(String name) {
if (!name.equalsIgnoreCase("include") && !name.equalsIgnoreCase("definitionInclude")) {
// if(name.startsWith("jdbc")&&name.endsWith("s"))
// counter5++;
try {
out.write("</");
out.write(name);
out.write(">");
}
catch (IOException e) {
System.err.println(e);
Logger.getCentralLogger().write("normal", e.getMessage());
}
}
}
/** End document. */
public void endDocument() {
try {
out.flush();
}
catch (IOException e) {
System.err.println(e);
Logger.getCentralLogger().write("normal", e.getMessage());
}
}
//
// ErrorHandler methods
//
/** Warning.
* @param ex is SAXParseException exception
*/
public void warning(SAXParseException ex) {
System.err.println("[Warning] " + getLocationString(ex) + ": " + ex.getMessage());
Logger.getCentralLogger().write("normal",
"[Warning] " + getLocationString(ex) + ": " + ex.getMessage());
}
/** Error.
* @param ex is SAXParseException exception
*/
public void error(SAXParseException ex) {
System.err.println("[Error] " + getLocationString(ex) + ": " + ex.getMessage());
Logger.getCentralLogger().write("normal",
"[Error] " + getLocationString(ex) + ": " + ex.getMessage());
}
/** Fatal error.
* @param ex is SAXParseException exception
* @throws SAXException
*/
public void fatalError(SAXParseException ex) throws SAXException {
System.err.println("[Fatal Error] " + getLocationString(ex) + ": " + ex.getMessage());
Logger.getCentralLogger().write("normal",
"[Fatal Error] " + getLocationString(ex) + ": " + ex.getMessage());
throw ex;
}
/** Returns a string of the location.
* @param ex is SAXParseException exception
* @return string
*/
private String getLocationString(SAXParseException ex) {
StringBuffer str = new StringBuffer();
String systemId = ex.getSystemId();
if (systemId != null) {
int index = systemId.lastIndexOf('/');
if (index != -1)
systemId = systemId.substring(index + 1);
str.append(systemId);
}
str.append(':');
str.append(ex.getLineNumber());
str.append(':');
str.append(ex.getColumnNumber());
return str.toString();
}
/**
* <p>
* This utility method reads a document at a specified URL
* and fires off calls to <code>characters()</code>.
* It's used to include files with <code>parse="text"</code>
* </p>
*
* @param url URL of the document that will be read
* @param encoding Encoding of the document; e.g. UTF-8,
* ISO-8859-1, etc.
* @throws SAXException if the requested document cannot
* be downloaded from the specified URL
* or if the encoding is not recognized
*/
private void includeTextDocument(String url, String encoding) throws SAXException {
if (encoding == null || encoding.trim().equals(""))
encoding = "UTF-8";
File sourceXml = new File(url);
URL source;
counter2 = 1;
try {
source = sourceXml.toURL();
}
catch (MalformedURLException e) {
Logger.getCentralLogger().write("normal", "Unresolvable URL :" + e.getMessage());
throw new SAXException("Unresolvable URL :", e);
}
try {
URLConnection uc = source.openConnection();
String encodingFromHeader = uc.getContentEncoding();
if (encodingFromHeader != null)
encoding = encodingFromHeader;
InputStream in = new BufferedInputStream(uc.getInputStream());
InputStreamReader reader = new InputStreamReader(in, encoding);
char[] c = new char[1024];
while (true) {
int charsRead = reader.read(c, 0, 1024);
if (charsRead == -1)
break;
if (charsRead > 0)
this.characters(c, 0, charsRead);
}
counter2 = counter2 + 4;
LocationOfException.setFileLineNumber(counter2, url);
// System.out.println("Sql file "+url+"ima broj linija :"+counter2);
counter2 = 0;
}
catch (UnsupportedEncodingException e) {
Logger.getCentralLogger().write("normal", "Unsupported encoding: " + encoding);
throw new SAXException("Unsupported encoding: " + encoding, e);
}
catch (IOException e) {
Logger.getCentralLogger().write("normal", "Document not found: " + source.toExternalForm());
throw new SAXException("Document not found: " + source.toExternalForm(), e);
}
}
/**
* <p>
* This utility method reads a document at a specified URL
* and fires off calls to various <code>DocumentHandler</code> methods.
* It's used to include files with <code>parse="xml"</code>
* </p>
*
* @param url URL of the document that will be read
* @throws SAXException if the requested document cannot
be downloaded from the specified URL.
*/
private void includeXMLDocument(String url) throws SAXException {
File sourceXml = new File(url);
URL source;
InputStream includeXML = null;
// int counter3=0;
try {
source = sourceXml.toURL();
includeXML = source.openStream();
InputStreamReader isr = new InputStreamReader(includeXML);
BufferedReader br = new BufferedReader(isr);
while (br.readLine() != null)
counter3++;
counter3 = counter3 + 2;
LocationOfException.setFileLineNumber(counter3, url);
// System.out.println("xml file " + url+" ima broj linija :"+counter3);
counter3 = 0;
// LocationOfException.setJdbcNumber(counter2);
}
catch (MalformedURLException e) {
Logger.getCentralLogger().write("normal", "Unresolvable URL :" + e.getMessage());
throw new SAXException("Unresolvable URL :", e);
}
catch (IOException e) {
Logger.getCentralLogger().write("normal", "Error in opening input stream :" + e.getMessage());
throw new SAXException("Error in opening input stream :", e);
}
SAXParser includeParser = new SAXParser();
includeParser.setDocumentHandler(this);
includeParser.setEntityResolver(this);
includeParser.setErrorHandler(this);
try {
includeParser.parse(url);
}
catch (Exception e) {
System.err.println(e);
Logger.getCentralLogger().write("normal", e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -