本文整理了Java中javax.xml.parsers.SAXParser.setProperty()
方法的一些代码示例,展示了SAXParser.setProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SAXParser.setProperty()
方法的具体详情如下:
包路径:javax.xml.parsers.SAXParser
类名称:SAXParser
方法名:setProperty
[英]Sets the particular property in the underlying implementation of org.xml.sax.XMLReader. A list of the core features and properties can be found at http://sax.sourceforge.net/?selected=get-set.
[中]在org的底层实现中设置特定属性。xml。萨克斯。XMLReader。核心特性和属性的列表可以在http://sax.sourceforge.net/?selected=get-set上找到。
代码示例来源:origin: jersey/jersey
@Override
public void setProperty(String s, Object o) throws SAXNotRecognizedException, SAXNotSupportedException {
sp.setProperty(s, o);
}
代码示例来源:origin: jeremylong/DependencyCheck
/**
* Constructs a validating secure SAX Parser.
*
* @param schemaStream One or more inputStreams with the schema(s) that the
* parser should be able to validate the XML against, one InputStream per
* schema
* @return a SAX Parser
* @throws ParserConfigurationException is thrown if there is a parser
* configuration exception
* @throws SAXNotRecognizedException thrown if there is an unrecognized
* feature
* @throws SAXNotSupportedException thrown if there is a non-supported
* feature
* @throws SAXException is thrown if there is a SAXException
*/
public static SAXParser buildSecureSaxParser(InputStream... schemaStream) throws ParserConfigurationException,
SAXNotRecognizedException, SAXNotSupportedException, SAXException {
final SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
//setting the following unfortunately breaks reading the old suppression files (version 1).
//factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
final SAXParser saxParser = factory.newSAXParser();
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
saxParser.setProperty(JAXP_SCHEMA_SOURCE, schemaStream);
return saxParser;
}
代码示例来源:origin: commons-digester/commons-digester
/**
* Configure schema validation as recommended by the JAXP 1.2 spec.
* The <code>properties</code> object may contains information about
* the schema local and language.
* @param properties parser optional info
*/
private static void configureOldXerces(SAXParser parser,
Properties properties)
throws ParserConfigurationException,
SAXNotSupportedException {
String schemaLocation = (String)properties.get("schemaLocation");
String schemaLanguage = (String)properties.get("schemaLanguage");
try{
if (schemaLocation != null) {
parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
}
} catch (SAXNotRecognizedException e){
log.info(parser.getClass().getName() + ": "
+ e.getMessage() + " not supported.");
}
}
代码示例来源:origin: plutext/docx4j
/**
* Indents the given XML String.
*
* @param r A reader on XML data
* @param w A writer for the indented XML
*
* @throws IOException If an IOException occurs.
* @throws SAXException If the XML is not well-formed.
* @throws ParserConfigurationException If the parser could not be configured
*/
public static void indent(Reader r, Writer w)
throws SAXException, IOException, ParserConfigurationException {
// create the indenter
XMLIndenter indenter = new XMLIndenter(w);
// initialise the SAX framework
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(false);
factory.setValidating(false);
InputSource source = new InputSource(r);
// parse the XML
SAXParser parser = factory.newSAXParser();
parser.setProperty("http://xml.org/sax/features/external-general-entities", false);
parser.setProperty("http://xml.org/sax/features/external-parameter-entities", false);
parser.setProperty("http://apache.org/xml/features/disallow-doctype-decl", true);
XMLReader xmlreader = parser.getXMLReader();
xmlreader.setContentHandler(indenter);
xmlreader.parse(source);
}
代码示例来源:origin: commons-digester/commons-digester
/**
* Set the current value of the specified property for the underlying
* <code>XMLReader</code> implementation.
* See <a href="http://www.saxproject.org">the saxproject website</a>
* for information about the standard SAX2 properties.
*
* @param property Property name to be set
* @param value Property value to be set
*
* @exception SAXNotRecognizedException if the property name is
* not recognized
* @exception SAXNotSupportedException if the property name is
* recognized but not supported
*/
public void setProperty(String property, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
getParser().setProperty(property, value);
}
代码示例来源:origin: commons-digester/commons-digester
/**
* Create a <code>SAXParser</code> configured to support XML Scheman and DTD
* @param properties parser specific properties/features
* @return an XML Schema/DTD enabled <code>SAXParser</code>
*/
public static SAXParser newSAXParser(Properties properties)
throws ParserConfigurationException,
SAXException,
SAXNotRecognizedException{
SAXParserFactory factory =
(SAXParserFactory)properties.get("SAXParserFactory");
SAXParser parser = factory.newSAXParser();
String schemaLocation = (String)properties.get("schemaLocation");
String schemaLanguage = (String)properties.get("schemaLanguage");
try{
if (schemaLocation != null) {
parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
}
} catch (SAXNotRecognizedException e){
log.info(parser.getClass().getName() + ": "
+ e.getMessage() + " not supported.");
}
return parser;
}
代码示例来源:origin: geoserver/geoserver
sf.setValidating(true);
SAXParser parser = sf.newSAXParser();
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaSource", schemaLocation);
代码示例来源:origin: groovy/groovy-core
/**
* Factory method to create a SAXParser configured to validate according to a particular schema language and
* optionally providing the schema sources to validate with.
*
* @param schemaLanguage the schema language used, e.g. XML Schema or RelaxNG (as per the String representation in javax.xml.XMLConstants)
* @param namespaceAware will the parser be namespace aware
* @param validating will the parser also validate against DTDs
* @param schemas the schemas to validate against
* @return the created SAXParser
* @throws SAXException
* @throws ParserConfigurationException
* @since 1.8.7
*/
public static SAXParser newSAXParser(String schemaLanguage, boolean namespaceAware, boolean validating, Source... schemas) throws SAXException, ParserConfigurationException {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(validating);
factory.setNamespaceAware(namespaceAware);
if (schemas.length != 0) {
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
factory.setSchema(schemaFactory.newSchema(schemas));
}
SAXParser saxParser = factory.newSAXParser();
if (schemas.length == 0) {
saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", schemaLanguage);
}
return saxParser;
}
代码示例来源:origin: apache/geode
parser.setProperty(JAXP_SCHEMA_LANGUAGE, XMLConstants.W3C_XML_SCHEMA_NS_URI);
parser.parse(bis, new DefaultHandlerDelegate(handler));
} catch (CacheXmlException e) {
代码示例来源:origin: resteasy/Resteasy
private static void configParser(SAXParser sp, boolean disableExternalEntities) {
try {
if (!disableExternalEntities)
sp.setProperty("http://javax.xml.XMLConstants/property/accessExternalDTD", "all");
} catch (SAXException e)
{
//expected, jaxp 1.5 not supported
}
}
代码示例来源:origin: apache/tika
setLimit.invoke(mgr, MAX_ENTITY_EXPANSIONS);
parser.setProperty(XERCES_SECURITY_MANAGER_PROPERTY, mgr);
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit", MAX_ENTITY_EXPANSIONS);
} catch (SAXException e) { // NOSONAR - also catch things like NoClassDefError here
代码示例来源:origin: apache/tika
@Override
void reset() {
try {
Object object = saxParser.getProperty(XERCES_SECURITY_MANAGER_PROPERTY);
saxParser.reset();
saxParser.setProperty(XERCES_SECURITY_MANAGER_PROPERTY, object);
} catch (SAXException e) {
LOG.log(Level.WARNING, "problem resetting sax parser", e);
}
try {
XMLReader reader = saxParser.getXMLReader();
clearReader(reader);
} catch (SAXException e) {
}
}
}
代码示例来源:origin: org.apache.xmlbeans/xmlbeans
public static Document xmlText2GenericDom(InputStream is, Document emptyDoc)
throws SAXException, ParserConfigurationException, IOException
{
SAXParser parser = SAXHelper.saxFactory().newSAXParser();
Sax2Dom handler = new Sax2Dom(emptyDoc);
parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
parser.parse(is, handler);
return (Document) handler.getDOM();
}
代码示例来源:origin: geotools/geotools
SAXParser parser = parserFactory.newSAXParser();
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
代码示例来源:origin: geotools/geotools
parser.setProperty(
"http://apache.org/xml/properties/schema/external-schemaLocation",
schemaLocation.toString());
parser.setProperty(SAX_PROPERTY_PREFIX + LEXICAL_HANDLER_PROPERTY, handler);
return parser;
代码示例来源:origin: apache/tika
setLimit.invoke(mgr, MAX_ENTITY_EXPANSIONS);
parser.setProperty(XERCES_SECURITY_MANAGER_PROPERTY, mgr);
hasSecurityManager = true;
} catch (SecurityException e) {
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit", MAX_ENTITY_EXPANSIONS);
canSetJaxPEntity = true;
} catch (SAXException e) { // NOSONAR - also catch things like NoClassDefError here
代码示例来源:origin: camunda/camunda-bpm-platform
public Parse execute() {
try {
InputStream inputStream = streamSource.getInputStream();
parser.getSaxParserFactory().setFeature(XXE_PROCESSING, enableXxeProcessing);
if (schemaResource == null) { // must be done before parser is created
parser.getSaxParserFactory().setNamespaceAware(false);
parser.getSaxParserFactory().setValidating(false);
}
SAXParser saxParser = parser.getSaxParser();
if (schemaResource != null) {
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
saxParser.setProperty(JAXP_SCHEMA_SOURCE, schemaResource);
}
saxParser.parse(inputStream, new ParseHandler(this));
}
catch (Exception e) {
throw LOG.parsingFailureException(name, e);
}
return this;
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Parse execute() {
try {
InputStream inputStream = streamSource.getInputStream();
parser.getSaxParserFactory().setFeature(XXE_PROCESSING, enableXxeProcessing);
if (schemaResource == null) { // must be done before parser is created
parser.getSaxParserFactory().setNamespaceAware(false);
parser.getSaxParserFactory().setValidating(false);
}
SAXParser saxParser = parser.getSaxParser();
if (schemaResource != null) {
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
saxParser.setProperty(JAXP_SCHEMA_SOURCE, schemaResource);
}
saxParser.parse(inputStream, new ParseHandler(this));
}
catch (Exception e) {
throw LOG.parsingFailureException(name, e);
}
return this;
}
代码示例来源:origin: owlcs/owlapi
protected static void addHandler(@Nullable DeclHandler handler, SAXParser parser) {
if (handler != null) {
try {
parser.setProperty(DECLARATION_HANDLER, handler);
} catch (SAXNotRecognizedException | SAXNotSupportedException e) {
LOGGER.warn(DECLARATION_HANDLER + ERROR_TEMPLATE
+ " Entity declarations will not be roundtripped.",
parser.getClass().getName(), e.getMessage());
}
}
}
}
代码示例来源:origin: org.apache.tika/tika-core
@Override
void reset() {
try {
Object object = saxParser.getProperty(XERCES_SECURITY_MANAGER);
saxParser.reset();
saxParser.setProperty(XERCES_SECURITY_MANAGER, object);
} catch (SAXException e) {
}
}
}
内容来源于网络,如有侵权,请联系作者删除!