< prev index next >
src/jdk.xml.bind/share/classes/com/sun/xml/internal/dtdparser/InputEntity.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -34,20 +34,21 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
+import java.util.Arrays;
import java.util.Locale;
/**
* This is how the parser talks to its input entities, of all kinds.
* The entities are in a stack.
- * <p/>
+ * <p>
* <P> For internal entities, the character arrays are referenced here,
* and read from as needed (they're read-only). External entities have
* mutable buffers, that are read into as needed.
- * <p/>
+ * <p>
* <P> <em>Note:</em> This maps CRLF (and CR) to LF without regard for
* whether it's in an external (parsed) entity or not. The XML 1.0 spec
* is inconsistent in explaining EOL handling; this is the sensible way.
*
* @author David Brownell
@@ -146,15 +147,16 @@
if (reader == null) {
InputStream bytes = in.getByteStream();
if (bytes == null)
- reader = XmlReader.createReader(new URL(in.getSystemId())
- .openStream());
+ if (Boolean.valueOf(System.getProperty("enableExternalEntityProcessing")))
+ reader = XmlReader.createReader(new URL(in.getSystemId()).openStream());
+ else
+ fatal("P-082", new Object[] {in.getSystemId()});
else if (in.getEncoding() != null)
- reader = XmlReader.createReader(in.getByteStream(),
- in.getEncoding());
+ reader = XmlReader.createReader(in.getByteStream(), in.getEncoding());
else
reader = XmlReader.createReader(in.getByteStream());
}
next = stack;
buf = new char[BUFSIZ];
@@ -167,11 +169,11 @@
//
public void init(char b [], String name, InputEntity stack, boolean isPE)
throws SAXException {
next = stack;
- buf = b;
+ buf = Arrays.copyOf(b, b.length);
finish = b.length;
this.name = name;
this.isPE = isPE;
checkRecursion(stack);
}
@@ -382,14 +384,14 @@
/**
* normal content; whitespace in markup may be handled
* specially if the parser uses the content model.
- * <p/>
+ * <p>
* <P> content terminates with markup delimiter characters,
* namely ampersand (&amp;) and left angle bracket (&lt;).
- * <p/>
+ * <p>
* <P> the document handler's characters() method is called
* on all the content found
*/
public boolean parsedContent(DTDEventListener docHandler
/*ElementValidator validator*/)
@@ -545,15 +547,15 @@
return true;
}
/**
- * CDATA -- character data, terminated by "]]>" and optionally
+ * CDATA -- character data, terminated by {@code "]]>"} and optionally
* including unescaped markup delimiters (ampersand and left angle
* bracket). This should otherwise be exactly like character data,
* modulo differences in error report details.
- * <p/>
+ * <p>
* <P> The document handler's characters() or ignorableWhitespace()
* methods are invoked on all the character data found
*
* @param docHandler gets callbacks for character data
* @param ignorableWhitespace if true, whitespace characters will
@@ -618,11 +620,11 @@
// As above, we can't repeat CR/CRLF --> LF mapping
if (isInternal())
continue;
if (white) {
- if (whitespaceInvalidMessage != null)
+ if (whitespaceInvalidMessage != null && errHandler != null)
errHandler.error(new SAXParseException(DTDParser.messages.getMessage(locale,
whitespaceInvalidMessage), null));
docHandler.ignorableWhitespace(buf, start,
last - start);
docHandler.ignorableWhitespace(newline, 0, 1);
@@ -657,11 +659,11 @@
//last--;
break;
}
}
if (white) {
- if (whitespaceInvalidMessage != null)
+ if (whitespaceInvalidMessage != null && errHandler != null)
errHandler.error(new SAXParseException(DTDParser.messages.getMessage(locale,
whitespaceInvalidMessage), null));
docHandler.ignorableWhitespace(buf, start, last - start);
} else {
// validator.text ();
@@ -699,11 +701,11 @@
}
/**
* whitespace in markup (flagged to app, discardable)
- * <p/>
+ * <p>
* <P> the document handler's ignorableWhitespace() method
* is called on all the whitespace found
*/
public boolean ignorableWhitespace(DTDEventListener handler)
throws IOException, SAXException {
@@ -757,11 +759,11 @@
}
/**
* returns false iff 'next' string isn't as provided,
* else skips that text and returns true.
- * <p/>
+ * <p>
* <P> NOTE: two alternative string representations are
* both passed in, since one is faster.
*/
public boolean peek(String next, char chars [])
throws IOException, SAXException {
@@ -808,12 +810,13 @@
// fail to be peeked is where it's a symbol ... e.g. for an
// </EndTag> construct. That knowledge could also be applied
// to get rid of the symbol length constraint, since having
// the wrong symbol is a fatal error anyway ...
//
- if (len > buf.length)
- fatal("P-077", new Object[]{new Integer(buf.length)});
+ if (len > buf.length) {
+ fatal("P-077", new Object[]{Integer.valueOf(buf.length)});
+ }
fillbuf();
return peek(next, chars);
}
@@ -982,9 +985,11 @@
SAXParseException x = new SAXParseException(DTDParser.messages.getMessage(locale, messageId, params), null);
// not continuable ... e.g. WF errors
close();
+ if (errHandler != null) {
errHandler.fatalError(x);
+ }
throw x;
}
}
< prev index next >