-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documents with an Internal Subset DOCTYPE shouldn't stop trying to bind
Fix #379 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
c1e0a34
commit 67b93ac
Showing
3 changed files
with
142 additions
and
8 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...e/lsp4xml/extensions/contentmodel/participants/diagnostics/LSPXMLParserConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lsp4xml.extensions.contentmodel.participants.diagnostics; | ||
|
||
import org.apache.xerces.impl.dtd.XMLDTDValidator; | ||
import org.apache.xerces.parsers.XIncludeAwareParserConfiguration; | ||
import org.apache.xerces.xni.XNIException; | ||
import org.apache.xerces.xni.parser.XMLComponentManager; | ||
import org.apache.xerces.xni.parser.XMLConfigurationException; | ||
|
||
/** | ||
* Custom Xerces XML parser configuration to : | ||
* | ||
* <ul> | ||
* <li>disable only DTD validation if required</li> | ||
* </ul> | ||
* | ||
*/ | ||
class LSPXMLParserConfiguration extends XIncludeAwareParserConfiguration { | ||
|
||
private final boolean disableDTDValidation; | ||
|
||
public LSPXMLParserConfiguration(boolean disableDTDValidation) { | ||
this.disableDTDValidation = disableDTDValidation; | ||
} | ||
|
||
@Override | ||
protected void reset() throws XNIException { | ||
super.reset(); | ||
if (disableDTDValidation) { | ||
// reset again DTD validator by setting "http://xml.org/sax/features/validation" | ||
// to false. | ||
disableDTDValidation(); | ||
} | ||
} | ||
|
||
private void disableDTDValidation() { | ||
XMLDTDValidator validator = (XMLDTDValidator) super.getProperty(DTD_VALIDATOR); | ||
if (validator != null) { | ||
// Calling XMLDTDValidator#setFeature("http://xml.org/sax/features/validation", | ||
// false) does nothing. | ||
// The only way to set "http://xml.org/sax/features/validation" to false is to | ||
// call XMLDTDValidator#reset with the proper component. | ||
// We need to create a new component and not use the current configuration | ||
// otherwise set | ||
// "http://xml.org/sax/features/validation" to the configuration | ||
// will update the other component and will disable validation too for XML | ||
// Schema | ||
XMLComponentManager disableDTDComponent = new XMLComponentManager() { | ||
|
||
@Override | ||
public Object getProperty(String propertyId) throws XMLConfigurationException { | ||
return LSPXMLParserConfiguration.this.getProperty(propertyId); | ||
} | ||
|
||
@Override | ||
public boolean getFeature(String featureId) throws XMLConfigurationException { | ||
if ("http://xml.org/sax/features/validation".equals(featureId)) { | ||
return false; | ||
} | ||
return LSPXMLParserConfiguration.this.getFeature(featureId); | ||
} | ||
}; | ||
validator.reset(disableDTDComponent); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters