mirror of
https://github.com/openjdk/jdk.git
synced 2026-07-28 20:03:39 +00:00
8262380: Enhance XML processing passes
Reviewed-by: lancea, naoto, ahgross, rhalade
This commit is contained in:
parent
0e6c01163f
commit
138f59806f
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -39,6 +39,8 @@ import java.io.IOException;
|
||||
*
|
||||
* @author Michael Glavassevich, IBM
|
||||
* @author Neil Graham, IBM
|
||||
*
|
||||
* @LastModified: Apr 2021
|
||||
*/
|
||||
|
||||
public class XML11EntityScanner
|
||||
@ -696,7 +698,7 @@ public class XML11EntityScanner
|
||||
sawIncompleteSurrogatePair)){
|
||||
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
|
||||
"IllegalQName",
|
||||
null,
|
||||
new Object[]{rawname},
|
||||
XMLErrorReporter.SEVERITY_FATAL_ERROR);
|
||||
}
|
||||
//check the result: localpart
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -55,6 +55,7 @@ import java.util.Locale;
|
||||
* @author Arnaud Le Hors, IBM
|
||||
* @author K.Venugopal Sun Microsystems
|
||||
*
|
||||
* @LastModified: Apr 2021
|
||||
*/
|
||||
public class XMLEntityScanner implements XMLLocator {
|
||||
|
||||
@ -860,6 +861,14 @@ public class XMLEntityScanner implements XMLLocator {
|
||||
prefix = fSymbolTable.addSymbol(fCurrentEntity.ch,
|
||||
offset, prefixLength);
|
||||
int len = length - prefixLength - 1;
|
||||
int startLocal = index +1;
|
||||
if (!XMLChar.isNCNameStart(fCurrentEntity.ch[startLocal])){
|
||||
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
|
||||
"IllegalQName",
|
||||
new Object[]{rawname},
|
||||
XMLErrorReporter.SEVERITY_FATAL_ERROR);
|
||||
}
|
||||
|
||||
//check the result: localpart
|
||||
checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, index + 1, len);
|
||||
localpart = fSymbolTable.addSymbol(fCurrentEntity.ch,
|
||||
|
||||
@ -278,7 +278,7 @@
|
||||
|
||||
# Namespaces support
|
||||
# 4. Using Qualified Names
|
||||
IllegalQName = Element or attribute do not match QName production: QName::=(NCName':')?NCName.
|
||||
IllegalQName = Element or attribute \"{0}\" do not match QName production: QName::=(NCName':')?NCName.
|
||||
ElementXMLNSPrefix = Element \"{0}\" cannot have \"xmlns\" as its prefix.
|
||||
ElementPrefixUnbound = The prefix \"{0}\" for element \"{1}\" is not bound.
|
||||
AttributePrefixUnbound = The prefix \"{2}\" for attribute \"{1}\" associated with an element type \"{0}\" is not bound.
|
||||
|
||||
@ -43,6 +43,7 @@ import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import jdk.xml.internal.JdkConstants;
|
||||
import jdk.xml.internal.JdkXmlUtils;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
@ -1978,21 +1979,21 @@ abstract public class ToStream extends SerializerBase {
|
||||
String doctypeSystem = getDoctypeSystem();
|
||||
if (null != doctypeSystem)
|
||||
{
|
||||
if (null == doctypePublic)
|
||||
writer.write(" SYSTEM \"");
|
||||
else
|
||||
writer.write(" \"");
|
||||
char quote = JdkXmlUtils.getQuoteChar(doctypeSystem);
|
||||
if (null == doctypePublic) {
|
||||
writer.write(" SYSTEM");
|
||||
}
|
||||
writer.write(" ");
|
||||
writer.write(quote);
|
||||
|
||||
writer.write(doctypeSystem);
|
||||
|
||||
writer.write(quote);
|
||||
if (closeDecl)
|
||||
{
|
||||
writer.write("\">");
|
||||
writer.write(">");
|
||||
writer.write(m_lineSep, 0, m_lineSepLen);
|
||||
closeDecl = false; // done closing
|
||||
}
|
||||
else
|
||||
writer.write('\"');
|
||||
}
|
||||
boolean dothis = false;
|
||||
if (dothis)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
@ -33,6 +33,7 @@ import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import jdk.xml.internal.JdkXmlUtils;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.CDATASection;
|
||||
import org.w3c.dom.Comment;
|
||||
@ -62,7 +63,7 @@ import org.xml.sax.helpers.LocatorImpl;
|
||||
* parameters and filters if any during serialization.
|
||||
*
|
||||
* @xsl.usage internal
|
||||
* @LastModified: Oct 2017
|
||||
* @LastModified: Apr 2021
|
||||
*/
|
||||
final class DOM3TreeWalker {
|
||||
|
||||
@ -501,7 +502,7 @@ final class DOM3TreeWalker {
|
||||
// DOCTYPE internal subset via an event call, so we write it
|
||||
// out here.
|
||||
Writer writer = fSerializer.getWriter();
|
||||
StringBuffer dtd = new StringBuffer();
|
||||
StringBuilder dtd = new StringBuilder();
|
||||
|
||||
dtd.append("<!DOCTYPE ");
|
||||
dtd.append(docTypeName);
|
||||
@ -512,13 +513,14 @@ final class DOM3TreeWalker {
|
||||
}
|
||||
|
||||
if (null != systemId) {
|
||||
char quote = JdkXmlUtils.getQuoteChar(systemId);
|
||||
if (null == publicId) {
|
||||
dtd.append(" SYSTEM \"");
|
||||
dtd.append(" SYSTEM ").append(quote);
|
||||
} else {
|
||||
dtd.append(" \"");
|
||||
dtd.append(" ").append(quote);
|
||||
}
|
||||
dtd.append(systemId);
|
||||
dtd.append('\"');
|
||||
dtd.append(quote);
|
||||
}
|
||||
|
||||
dtd.append(" [ ");
|
||||
|
||||
@ -366,6 +366,22 @@ public class JdkXmlUtils {
|
||||
return tf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the character to be used to quote the input content. Between
|
||||
* single and double quotes, this method returns the one that is not found
|
||||
* in the input. Returns double quote by default.
|
||||
*
|
||||
* @param s the input string
|
||||
* @return returns the quote not found in the input
|
||||
*/
|
||||
public static char getQuoteChar(String s) {
|
||||
if (s != null && s.indexOf('"') > -1) {
|
||||
return '\'';
|
||||
} else {
|
||||
return '"';
|
||||
}
|
||||
}
|
||||
|
||||
private static XMLReader getXMLReaderWSAXFactory(boolean overrideDefaultParser) {
|
||||
SAXParserFactory saxFactory = getSAXFactory(overrideDefaultParser);
|
||||
try {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user