本文整理汇总了Java中org.w3c.dom.DOMErrorHandler类的典型用法代码示例。如果您正苦于以下问题:Java DOMErrorHandler类的具体用法?Java DOMErrorHandler怎么用?Java DOMErrorHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DOMErrorHandler类属于org.w3c.dom包,在下文中一共展示了DOMErrorHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reportDOMError
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
/**
* Reports a DOM error to the user handler.
*
* If the error is fatal, the processing will be always aborted.
*/
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
String message, short severity, String type ) {
if( errorHandler!=null ) {
error.reset();
error.fMessage = message;
error.fSeverity = severity;
error.fLocator = locator;
error.fType = type;
error.fRelatedData = locator.fRelatedNode;
if(!errorHandler.handleError(error))
throw abort;
}
if( severity==DOMError.SEVERITY_FATAL_ERROR )
throw abort;
}
示例2: reportDOMError
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
/**
* Reports a DOM error to the user handler.
*
* If the error is fatal, the processing will be always aborted.
*/
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
String message, short severity, String type ) {
if( errorHandler!=null ) {
error.reset();
error.fMessage = message;
error.fSeverity = severity;
error.fLocator = locator;
error.fType = type;
error.fRelatedData = locator.fRelatedNode;
if(!errorHandler.handleError(error))
throw new AbortException();
}
if( severity==DOMError.SEVERITY_FATAL_ERROR )
throw new AbortException();
}
示例3: DOM3TreeWalker
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
/**
* Constructor.
* @param contentHandler serialHandler The implemention of the SerializationHandler interface
*/
DOM3TreeWalker(
SerializationHandler serialHandler,
DOMErrorHandler errHandler,
LSSerializerFilter filter,
String newLine) {
fSerializer = serialHandler;
//fErrorHandler = errHandler == null ? new DOMErrorHandlerImpl() : errHandler; // Should we be using the default?
fErrorHandler = errHandler;
fFilter = filter;
fLexicalHandler = null;
fNewLine = newLine;
fNSBinder = new NamespaceSupport();
fLocalNSBinder = new NamespaceSupport();
fDOMConfigProperties = fSerializer.getOutputFormat();
fSerializer.setDocumentLocator(fLocator);
initProperties(fDOMConfigProperties);
}
示例4: XSParser
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
public XSParser(LSResourceResolver entityResolver, DOMErrorHandler errorHandler){
System.setProperty(DOMImplementationRegistry.PROPERTY, DOMXSImplementationSourceImpl.class.getName());
DOMImplementationRegistry registry;
try{
registry = DOMImplementationRegistry.newInstance();
}catch(Exception ex){
throw new ImpossibleException(ex);
}
XSImplementationImpl xsImpl = (XSImplementationImpl)registry.getDOMImplementation("XS-Loader");
xsLoader = xsImpl.createXSLoader(null);
DOMConfiguration config = xsLoader.getConfig();
config.setParameter(Constants.DOM_VALIDATE, Boolean.TRUE);
if(entityResolver!=null)
config.setParameter(Constants.DOM_RESOURCE_RESOLVER, entityResolver);
if(errorHandler!=null)
config.setParameter(Constants.DOM_ERROR_HANDLER, errorHandler);
}
示例5: reportDOMError
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
/**
* Reports a DOM error to the user handler.
*
* If the error is fatal, the processing will be always aborted.
*/
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
String message, short severity, String type ) {
if( errorHandler!=null ) {
error.reset();
error.fMessage = message;
error.fSeverity = severity;
error.fLocator = locator;
error.fType = type;
error.fRelatedData = locator.fRelatedNode;
if(!errorHandler.handleError(error))
throw abort;
}
if( severity==DOMError.SEVERITY_FATAL_ERROR )
throw abort;
}
示例6: canSetParameter
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
/**
* Checks if setting a parameter to a specific value is supported.
*
* @see org.w3c.dom.DOMConfiguration#canSetParameter(java.lang.String, java.lang.Object)
* @since DOM Level 3
* @param name A String containing the DOMConfiguration parameter name.
* @param value An Object specifying the value of the corresponding parameter.
*/
public boolean canSetParameter(String name, Object value) {
if (value instanceof Boolean){
if ( name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)
|| name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)
|| name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)
|| name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)
|| name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)
|| name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)
|| name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)
|| name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)
|| name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)
|| name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)
|| name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)
|| name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)){
// both values supported
return true;
}
else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)
|| name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION)
|| name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)
|| name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)
|| name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)
// || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
) {
// true is not supported
return !((Boolean)value).booleanValue();
}
else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
// false is not supported
return ((Boolean)value).booleanValue();
}
}
else if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER) &&
value == null || value instanceof DOMErrorHandler){
return true;
}
return false;
}
示例7: testMain
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
@Test
public void testMain() throws Exception {
final boolean[] hadError = new boolean[1];
DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBF.newDocumentBuilder();
Document doc = docBuilder.getDOMImplementation().createDocument("namespaceURI", "ns:root", null);
CDATASection cdata = doc.createCDATASection("text1]]>text2");
doc.getDocumentElement().appendChild(cdata);
DOMConfiguration config = doc.getDomConfig();
DOMErrorHandler erroHandler = new DOMErrorHandler() {
public boolean handleError(DOMError error) {
System.out.println(error.getMessage());
Assert.assertEquals(error.getType(), "cdata-sections-splitted");
Assert.assertFalse(hadError[0], "two errors were reported");
hadError[0] = true;
return false;
}
};
config.setParameter("error-handler", erroHandler);
doc.normalizeDocument();
Assert.assertTrue(hadError[0]);
}
示例8: normalizeDocument
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
/**
* <b>DOM</b>: Implements {@link org.w3c.dom.Document#normalizeDocument()}.
* XXX Does not handle the 'entities' parameter yet.
*/
public void normalizeDocument() {
if (domConfig == null) {
domConfig = new DocumentConfiguration();
}
boolean cdataSections = domConfig.getBooleanParameter
(DOMConstants.DOM_CDATA_SECTIONS_PARAM);
boolean comments = domConfig.getBooleanParameter
(DOMConstants.DOM_COMMENTS_PARAM);
boolean elementContentWhitespace = domConfig.getBooleanParameter
(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE_PARAM);
boolean namespaceDeclarations = domConfig.getBooleanParameter
(DOMConstants.DOM_NAMESPACE_DECLARATIONS_PARAM);
boolean namespaces = domConfig.getBooleanParameter
(DOMConstants.DOM_NAMESPACES_PARAM);
boolean splitCdataSections = domConfig.getBooleanParameter
(DOMConstants.DOM_SPLIT_CDATA_SECTIONS_PARAM);
DOMErrorHandler errorHandler = (DOMErrorHandler) domConfig.getParameter
(DOMConstants.DOM_ERROR_HANDLER_PARAM);
normalizeDocument(getDocumentElement(),
cdataSections,
comments,
elementContentWhitespace,
namespaceDeclarations,
namespaces,
splitCdataSections,
errorHandler);
}
示例9: splitCdata
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
/**
* Splits the given CDATA node if required.
*/
protected boolean splitCdata(Element e,
Node n,
DOMErrorHandler errorHandler) {
String s2 = n.getNodeValue();
int index = s2.indexOf(XMLConstants.XML_CDATA_END);
if (index != -1) {
String before = s2.substring(0, index + 2);
String after = s2.substring(index + 2);
n.setNodeValue(before);
Node next = n.getNextSibling();
if (next == null) {
e.appendChild(createCDATASection(after));
} else {
e.insertBefore(createCDATASection(after),
next);
}
if (errorHandler != null) {
if (!errorHandler.handleError(createDOMError(
DOMConstants.DOM_CDATA_SECTIONS_SPLITTED_ERROR,
DOMError.SEVERITY_WARNING,
"cdata.section.split",
new Object[] {},
n,
null))) {
return false;
}
}
}
return true;
}
示例10: canSetParameter
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
/**
* Returns whether the given parameter can be set to the given value.
*/
public boolean canSetParameter(String name, Object value) {
if (name.equals(DOMConstants.DOM_ERROR_HANDLER_PARAM)) {
return value == null || value instanceof DOMErrorHandler;
}
Integer i = (Integer) booleanParamIndexes.get(name);
if (i == null || value == null || !(value instanceof Boolean)) {
return false;
}
int index = i.intValue();
boolean val = ((Boolean) value).booleanValue();
return !booleanParamReadOnly[index]
|| booleanParamValues[index] == val;
}
示例11: canSetParameter
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
public boolean canSetParameter(String name, Object value)
{
name = name.toLowerCase();
if ("error-handler".equals(name))
{
return (value == null || value instanceof DOMErrorHandler);
}
return ("cdata-sections".equals(name) ||
"comments".equals(name) ||
"entities".equals(name) ||
"namespace-declarations".equals(name) ||
"split-cdata-sections".equals(name));
}
示例12: canSetParameter
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
public boolean canSetParameter(String name, Object value)
{
name = name.toLowerCase();
if ("error-handler".equals(name))
{
return (value == null || value instanceof DOMErrorHandler);
}
else if (contains(name))
{
return true;
}
else if ("canonical-form".equals(name) ||
"check-character-normalization".equals(name) ||
"datatype-normalization".equals(name) ||
"normalize-characters".equals(name) ||
"validate".equals(name) ||
"validate-if-schema".equals(name))
{
return "false".equals(value.toString());
}
else if ("namespaces".equals(name) ||
"well-formed".equals(name))
{
return "true".equals(value.toString());
}
return false;
}
示例13: validate
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
public static void validate(Document d, String schema, DOMErrorHandler handler) {
DOMConfiguration config = d.getDomConfig();
config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
config.setParameter("validate", true);
config.setParameter("schema-location", schema);
config.setParameter("resource-resolver", new ClasspathResourceResolver());
config.setParameter("error-handler", handler);
d.normalizeDocument();
}
示例14: canSetParameter
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
/**
* Checks if setting a parameter to a specific value is supported.
*
* @see org.w3c.dom.DOMConfiguration#canSetParameter(java.lang.String, java.lang.Object)
* @since DOM Level 3
* @param name A String containing the DOMConfiguration parameter name.
* @param value An Object specifying the value of the corresponding parameter.
*/
public boolean canSetParameter(String name, Object value) {
if (value instanceof Boolean){
if ( name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)
|| name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)
|| name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)
|| name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)
|| name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)
|| name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)
|| name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)
|| name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)
|| name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)
|| name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)
|| name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)
|| name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)){
// both values supported
return true;
}
else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)
|| name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION)
|| name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)
|| name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)
|| name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)
// || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
) {
// true is not supported
return !((Boolean)value).booleanValue();
}
else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
// false is not supported
return ((Boolean)value).booleanValue();
}
}
else if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER) &&
value == null || value instanceof DOMErrorHandler){
return true;
}
return false;
}
示例15: DOM3TreeWalker
import org.w3c.dom.DOMErrorHandler; //导入依赖的package包/类
/**
* Constructor.
* @param contentHandler serialHandler The implemention of the SerializationHandler interface
*/
DOM3TreeWalker(
SerializationHandler serialHandler,
DOMErrorHandler errHandler,
LSSerializerFilter filter,
String newLine) {
fSerializer = serialHandler;
//fErrorHandler = errHandler == null ? new DOMErrorHandlerImpl() : errHandler; // Should we be using the default?
fErrorHandler = errHandler;
fFilter = filter;
fLexicalHandler = null;
fNewLine = newLine;
fNSBinder = new NamespaceSupport();
fLocalNSBinder = new NamespaceSupport();
fDOMConfigProperties = fSerializer.getOutputFormat();
fSerializer.setDocumentLocator(fLocator);
initProperties(fDOMConfigProperties);
try {
// Bug see Bugzilla 26741
fLocator.setSystemId(
System.getProperty("user.dir") + File.separator + "dummy.xsl");
} catch (SecurityException se) { // user.dir not accessible from applet
}
}