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.
Missing xml-model reference generates multiple similar warnings
Fixes eclipse-lemminx#795 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
2dafd72
commit 15fd1d6
Showing
9 changed files
with
251 additions
and
20 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
71 changes: 71 additions & 0 deletions
71
...src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/XMLModelUtils.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,71 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 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 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.extensions.contentmodel.participants; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.xerces.impl.XMLEntityManager; | ||
import org.apache.xerces.util.URI.MalformedURIException; | ||
import org.eclipse.lemminx.dom.DOMDocument; | ||
import org.eclipse.lemminx.dom.DOMRange; | ||
import org.eclipse.lemminx.dom.XMLModel; | ||
|
||
/** | ||
* XML model utilities. | ||
* | ||
*/ | ||
public class XMLModelUtils { | ||
|
||
/** | ||
* Returns the DOM range of the href of the xml-model processing instruction | ||
* which matches the given hrefLocation. | ||
* | ||
* @param document the DOM document. | ||
* @param hrefLocation the href location. | ||
* @return the DOM range of the href of the xml-model processing instruction | ||
* which matches the given hrefLocation. | ||
*/ | ||
public static DOMRange getHrefNode(DOMDocument document, String hrefLocation) { | ||
if (hrefLocation == null) { | ||
return null; | ||
} | ||
// Check if location comes from a xml-model/@href | ||
List<XMLModel> xmlModels = document.getXMLModels(); | ||
if (!xmlModels.isEmpty()) { | ||
String documentURI = document.getDocumentURI(); | ||
for (XMLModel xmlModel : xmlModels) { | ||
String href = xmlModel.getHref(); | ||
String xmlModelLocation = getResolvedLocation(documentURI, href); | ||
if (hrefLocation.equals(xmlModelLocation)) { | ||
return xmlModel.getHrefNode(); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the expanded system location | ||
* | ||
* @return the expanded system location | ||
*/ | ||
private static String getResolvedLocation(String documentURI, String location) { | ||
if (location == null) { | ||
return null; | ||
} | ||
try { | ||
return XMLEntityManager.expandSystemId(location, documentURI, false); | ||
} catch (MalformedURIException e) { | ||
return location; | ||
} | ||
} | ||
} |
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
117 changes: 117 additions & 0 deletions
117
...ain/java/org/eclipse/lemminx/extensions/xerces/xmlmodel/msg/XMLModelMessageFormatter.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,117 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.eclipse.lemminx.extensions.xerces.xmlmodel.msg; | ||
|
||
import java.util.Locale; | ||
import java.util.MissingResourceException; | ||
import java.util.ResourceBundle; | ||
|
||
import org.apache.xerces.util.MessageFormatter; | ||
|
||
/** | ||
* XMLModelMessageFormatter provides error messages for the xml-model | ||
* Recommendation. | ||
* | ||
* <p> | ||
* This class is a copy/paste of Xerces | ||
* org.apache.xerces.impl.msg.XMLMessageFormatter class. | ||
* </p> | ||
* | ||
* @author Eric Ye, IBM | ||
* @author Angelo ZERR | ||
*/ | ||
public class XMLModelMessageFormatter implements MessageFormatter { | ||
/** | ||
* The domain of messages concerning the XML 1.0 specification. | ||
*/ | ||
public static final String XML_MODEL_DOMAIN = "https://www.w3.org/TR/xml-model/"; | ||
|
||
// private objects to cache the locale and resource bundle | ||
private Locale fLocale = null; | ||
private ResourceBundle fResourceBundle = null; | ||
|
||
// | ||
// MessageFormatter methods | ||
// | ||
|
||
/** | ||
* Formats a message with the specified arguments using the given locale | ||
* information. | ||
* | ||
* @param locale The locale of the message. | ||
* @param key The message key. | ||
* @param arguments The message replacement text arguments. The order of the | ||
* arguments must match that of the placeholders in the actual | ||
* message. | ||
* | ||
* @return Returns the formatted message. | ||
* | ||
* @throws MissingResourceException Thrown if the message with the specified key | ||
* cannot be found. | ||
*/ | ||
public String formatMessage(Locale locale, String key, Object[] arguments) throws MissingResourceException { | ||
|
||
if (locale == null) { | ||
locale = Locale.getDefault(); | ||
} | ||
if (locale != fLocale) { | ||
fResourceBundle = ResourceBundle.getBundle("org.eclipse.lemminx.extensions.xerces.xmlmodel.msg.XMLMessages", | ||
locale); | ||
// memorize the most-recent locale | ||
fLocale = locale; | ||
} | ||
|
||
// format message | ||
String msg; | ||
try { | ||
msg = fResourceBundle.getString(key); | ||
if (arguments != null) { | ||
try { | ||
msg = java.text.MessageFormat.format(msg, arguments); | ||
} catch (Exception e) { | ||
msg = fResourceBundle.getString("FormatFailed"); | ||
msg += " " + fResourceBundle.getString(key); | ||
} | ||
} | ||
} | ||
|
||
// error | ||
catch (MissingResourceException e) { | ||
msg = fResourceBundle.getString("BadMessageKey"); | ||
throw new MissingResourceException(key, msg, key); | ||
} | ||
|
||
// no message | ||
if (msg == null) { | ||
msg = key; | ||
if (arguments.length > 0) { | ||
StringBuilder str = new StringBuilder(msg); | ||
str.append('?'); | ||
for (int i = 0; i < arguments.length; i++) { | ||
if (i > 0) { | ||
str.append('&'); | ||
} | ||
str.append(String.valueOf(arguments[i])); | ||
} | ||
} | ||
} | ||
|
||
return msg; | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
.../main/resources/org/eclipse/lemminx/extensions/xerces/xmlmodel/msg/XMLMessages.properties
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,2 @@ | ||
# added | ||
dtd_not_found = Cannot find DTD ''{1}''. |
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