forked from eclipse-lemminx/lemminx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validation only happens on starting VS code
Fixes redhat-developer/vscode-xml#647 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
ba438fe
commit f72787a
Showing
11 changed files
with
414 additions
and
30 deletions.
There are no files selected for viewing
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
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
124 changes: 124 additions & 0 deletions
124
...eclipse/lemminx/extensions/contentmodel/participants/diagnostics/LSPXMLEntityManager.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,124 @@ | ||
package org.eclipse.lemminx.extensions.contentmodel.participants.diagnostics; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
|
||
import org.apache.xerces.impl.XMLEntityManager; | ||
import org.apache.xerces.impl.XMLErrorReporter; | ||
import org.apache.xerces.impl.xs.XSDDescription; | ||
import org.apache.xerces.xni.XMLLocator; | ||
import org.apache.xerces.xni.XMLResourceIdentifier; | ||
import org.apache.xerces.xni.XNIException; | ||
import org.apache.xerces.xni.parser.XMLInputSource; | ||
import org.eclipse.lemminx.extensions.contentmodel.participants.DTDErrorCode; | ||
import org.eclipse.lemminx.extensions.xerces.xmlmodel.msg.XMLModelMessageFormatter; | ||
|
||
class LSPXMLEntityManager extends XMLEntityManager { | ||
|
||
private final XMLErrorReporter errorReporter; | ||
|
||
private final LSPXMLGrammarPool grammarPool; | ||
private boolean hasProblemsWithReferencedDTD; | ||
|
||
public LSPXMLEntityManager(XMLErrorReporter errorReporter, LSPXMLGrammarPool grammarPool) { | ||
this.errorReporter = errorReporter; | ||
this.grammarPool = grammarPool; | ||
this.hasProblemsWithReferencedDTD = false; | ||
} | ||
|
||
@Override | ||
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException { | ||
if(resourceIdentifier instanceof XSDDescription) { | ||
return super.resolveEntity(resourceIdentifier); | ||
} | ||
try { | ||
return super.resolveEntity(resourceIdentifier); | ||
} catch (Exception e) { | ||
reportError(resourceIdentifier.getLiteralSystemId(), e); | ||
XMLInputSource in = new XMLInputSource(resourceIdentifier); | ||
in.setCharacterStream(new StringReader("")); | ||
return in; | ||
} | ||
} | ||
|
||
@Override | ||
public String setupCurrentEntity(String name, XMLInputSource xmlInputSource, boolean literal, boolean isExternal) | ||
throws IOException, XNIException { | ||
try { | ||
return super.setupCurrentEntity(name, xmlInputSource, literal, isExternal); | ||
} catch (Exception e) { | ||
reportError(xmlInputSource.getSystemId(), e); | ||
XMLInputSource in = new XMLInputSource(xmlInputSource.getPublicId(), xmlInputSource.getSystemId(), | ||
xmlInputSource.getBaseSystemId(), new StringReader(""), null); | ||
return super.setupCurrentEntity(name, in, literal, isExternal); | ||
} | ||
} | ||
|
||
private void reportError(String location, Exception e) { | ||
hasProblemsWithReferencedDTD = true; | ||
errorReporter.reportError(new XMLLocator() { | ||
|
||
@Override | ||
public String getXMLVersion() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPublicId() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getLiteralSystemId() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getLineNumber() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public String getExpandedSystemId() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getEncoding() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getColumnNumber() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getCharacterOffset() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public String getBaseSystemId() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
}, XMLModelMessageFormatter.XML_MODEL_DOMAIN, DTDErrorCode.dtd_not_found.getCode(), | ||
new Object[] { null, location }, XMLErrorReporter.SEVERITY_ERROR, e); | ||
} | ||
|
||
public void dispose() { | ||
if (hasProblemsWithReferencedDTD) { | ||
grammarPool.clear(); | ||
} | ||
// problems.forEach(uri -> grammarPool.removeGrammar(uri)); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...se/lemminx/extensions/contentmodel/participants/diagnostics/LSPXMLGrammarPoolWrapper.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,77 @@ | ||
package org.eclipse.lemminx.extensions.contentmodel.participants.diagnostics; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.xerces.xni.grammars.Grammar; | ||
import org.apache.xerces.xni.grammars.XMLGrammarDescription; | ||
|
||
public class LSPXMLGrammarPoolWrapper extends LSPXMLGrammarPool { | ||
|
||
private final LSPXMLGrammarPool delegate; | ||
|
||
private final List<Grammar> cachedGrammars; | ||
|
||
public LSPXMLGrammarPoolWrapper(LSPXMLGrammarPool delegate) { | ||
this.delegate = delegate; | ||
this.cachedGrammars = new ArrayList<>(); | ||
} | ||
|
||
public Grammar[] retrieveInitialGrammarSet(String grammarType) { | ||
return delegate.retrieveInitialGrammarSet(grammarType); | ||
} | ||
|
||
public void cacheGrammars(String grammarType, Grammar[] grammars) { | ||
for (Grammar grammar : grammars) { | ||
cachedGrammars.add(grammar); | ||
} | ||
delegate.cacheGrammars(grammarType, grammars); | ||
} | ||
|
||
public int hashCode() { | ||
return delegate.hashCode(); | ||
} | ||
|
||
public Grammar retrieveGrammar(XMLGrammarDescription desc) { | ||
return delegate.retrieveGrammar(desc); | ||
} | ||
|
||
public Grammar removeGrammar(XMLGrammarDescription desc) { | ||
return delegate.removeGrammar(desc); | ||
} | ||
|
||
public boolean equals(Object obj) { | ||
return delegate.equals(obj); | ||
} | ||
|
||
public void removeGrammar(String grammarURI) { | ||
delegate.removeGrammar(grammarURI); | ||
} | ||
|
||
public void lockPool() { | ||
delegate.lockPool(); | ||
} | ||
|
||
public void unlockPool() { | ||
delegate.unlockPool(); | ||
} | ||
|
||
public void clear() { | ||
for (Grammar grammar : cachedGrammars) { | ||
delegate.removeGrammar(grammar.getGrammarDescription()); | ||
} | ||
} | ||
|
||
public boolean equals(XMLGrammarDescription desc1, XMLGrammarDescription desc2) { | ||
return delegate.equals(desc1, desc2); | ||
} | ||
|
||
public int hashCode(XMLGrammarDescription desc) { | ||
return delegate.hashCode(desc); | ||
} | ||
|
||
public String toString() { | ||
return delegate.toString(); | ||
} | ||
|
||
} |
Oops, something went wrong.