diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core')
27 files changed, 0 insertions, 3654 deletions
diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/ValidatorHelper.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/ValidatorHelper.java deleted file mode 100644 index acce7775a6..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/ValidatorHelper.java +++ /dev/null @@ -1,346 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation; - -import java.io.InputStream; -import java.io.Reader; -import java.net.URL; -import java.util.List; -import java.util.StringTokenizer; -import java.util.Vector; - -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; -import org.xml.sax.ext.LexicalHandler; - -/** - * A helper class for the XML validator. - * - * @author Craig Salter, IBM - * @author Lawrence Mandel, IBM - */ -public class ValidatorHelper -{ - public List namespaceURIList = new Vector(); - public boolean isGrammarEncountered = false; - public boolean isDTDEncountered = false; - public boolean isNamespaceEncountered = false; - public String schemaLocationString = ""; //$NON-NLS-1$ - public int numDTDElements = 0; - - /** - * Constructor. - */ - public ValidatorHelper() - { - } - - /** - * Create an XML Reader. - * - * @return An XML Reader if one can be created or null. - * @throws Exception - */ - protected XMLReader createXMLReader(String uri) throws Exception - { - XMLReader reader = null; - - reader = new org.apache.xerces.parsers.SAXParser(); - reader.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false); //$NON-NLS-1$ - reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); //$NON-NLS-1$ - reader.setFeature("http://xml.org/sax/features/namespaces", false); //$NON-NLS-1$ - reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); //$NON-NLS-1$ - reader.setContentHandler(new MyContentHandler(uri)); - reader.setErrorHandler(new InternalErrorHandler()); - - LexicalHandler lexicalHandler = new LexicalHandler() - { - public void startDTD (String name, String publicId, String systemId) - { - isGrammarEncountered = true; - isDTDEncountered = true; - } - - public void endDTD() throws SAXException - { - } - - public void startEntity(String name) throws SAXException - { - } - - public void endEntity(String name) throws SAXException - { - } - - public void startCDATA() throws SAXException - { - } - - public void endCDATA() throws SAXException - { - } - - public void comment (char ch[], int start, int length) throws SAXException - { - } - }; - reader.setProperty("http://xml.org/sax/properties/lexical-handler", lexicalHandler); //$NON-NLS-1$ - - return reader; - } - - /** - * An error handler to suppress error and warning information. - */ - private class InternalErrorHandler implements org.xml.sax.ErrorHandler - { - public void error(SAXParseException exception) throws SAXException - { - } - - public void fatalError(SAXParseException exception) throws SAXException - { - } - - public void warning(SAXParseException exception) throws SAXException - { - } - } - - - /** - * Figures out the information needed for validation. - * - * @param uri The uri of the file to validate. - * @param uriResolver A helper to resolve locations. - */ - public void computeValidationInformation(String uri, Reader characterStream, URIResolver uriResolver) - { - try - { - XMLReader reader = createXMLReader(uri); - InputSource inputSource = new InputSource(uri); - inputSource.setCharacterStream(characterStream); - reader.parse(inputSource); - } - catch (Exception e) - { - //System.out.println(e); - } - } - - - - /** - * Handle the content while parsing the file. - */ - class MyContentHandler extends org.xml.sax.helpers.DefaultHandler - { - /* (non-Javadoc) - * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException) - */ - boolean isRootElement = true; - String baseURI; - - MyContentHandler(String uri) - { - this.baseURI = uri; - } - - public void error(SAXParseException e) throws SAXException - { - } - /* (non-Javadoc) - * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) - */ - public void fatalError(SAXParseException e) throws SAXException - { - } - /* (non-Javadoc) - * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException) - */ - public void warning(SAXParseException e) throws SAXException - { - } - public String getPrefix(String name) - { - String prefix = null; - int index = name.indexOf(":"); //$NON-NLS-1$ - if (index != -1) - { - prefix = name.substring(0, index); - } - return prefix; - } - - public String getUnprefixedName(String name) - { - int index = name.indexOf(":"); //$NON-NLS-1$ - if (index != -1) - { - name = name.substring(index + 1); - } - return name; - } - - public String getPrefixedName(String prefix, String localName) - { - return prefix != null && prefix.length() > 0 ? prefix + ":" + localName : localName; //$NON-NLS-1$ - } - - public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) - { - //String explicitLocation = null; - if (isRootElement) - { - - isRootElement = false; - int nAtts = atts.getLength(); - String schemaInstancePrefix = null; - for (int i =0; i < nAtts; i++) - { - String attributeName = atts.getQName(i); - if (attributeName.equals("xmlns") || attributeName.startsWith("xmlns:")) //$NON-NLS-1$ //$NON-NLS-2$ - { - isNamespaceEncountered = true; - String value = atts.getValue(i); - if (value.startsWith("http://www.w3.org/") && value.endsWith("/XMLSchema-instance")) //$NON-NLS-1$ //$NON-NLS-2$ - { - schemaInstancePrefix = attributeName.equals("xmlns") ? "" : getUnprefixedName(attributeName); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } - - String prefix = getPrefix(rawName); - String rootElementNamespaceDeclarationName = (prefix != null && prefix.length() > 0) ? "xmlns:" + prefix : "xmlns"; //$NON-NLS-1$ //$NON-NLS-2$ - String rootElementNamespace = rootElementNamespaceDeclarationName != null ? atts.getValue(rootElementNamespaceDeclarationName) : null; - - String location = null; - - // first we use any 'xsi:schemaLocation' or 'xsi:noNamespaceSchemaLocation' attribute - // to determine a location - if (schemaInstancePrefix != null) - { - location = atts.getValue(getPrefixedName(schemaInstancePrefix, "noNamespaceSchemaLocation")); //$NON-NLS-1$ - if (location == null) - { - String schemaLoc = atts.getValue(getPrefixedName(schemaInstancePrefix, "schemaLocation")); //$NON-NLS-1$ - location = getSchemaLocationForNamespace(schemaLoc, rootElementNamespace); - } - } - if (rootElementNamespace != null) - { - location = URIResolverPlugin.createResolver().resolve(baseURI, rootElementNamespace, location); - location = URIResolverPlugin.createResolver().resolvePhysicalLocation(baseURI, rootElementNamespace, location); - } - - if (location != null) - { - InputStream is = null; - try - { - URL url = new URL(location); - is = url.openStream(); - isGrammarEncountered = true; - } - catch(Exception e) - { - // Do nothing. - } - finally - { - if(is != null) - { - try - { - is.close(); - } - catch(Exception e) - { - // Do nothing. - } - } - } - } - } - } - /* (non-Javadoc) - * @see org.xml.sax.ext.DeclHandler#elementDecl(java.lang.String, java.lang.String) - */ - public void elementDecl(String name, String model) - { - numDTDElements++; - } - - // The xsiSchemaLocationValue is a list of namespace/location pairs that are separated by whitespace - // this method walks the list of pairs looking for the specified namespace and returns the associated - // location. - // - protected String getSchemaLocationForNamespace(String xsiSchemaLocationValue, String namespace) - { - String result = null; - if (xsiSchemaLocationValue != null && namespace != null) - { - - StringTokenizer st = new StringTokenizer(xsiSchemaLocationValue); - while(st.hasMoreTokens()) - { - if(st.nextToken().equals(namespace)) - { - if(st.hasMoreTokens()) - { - result = st.nextToken(); - } - } - else - { - if(st.hasMoreTokens()) - { - st.nextToken(); - } - } - } - } - return result; - } - } - - - /** - * Replace all instances in the string of the old pattern with the new pattern. - * - * @param string The string to replace the patterns in. - * @param oldPattern The old pattern to replace. - * @param newPattern The pattern used for replacement. - * @return The modified string with all occurrances of oldPattern replaced by new Pattern. - */ - protected static String replace(String string, String oldPattern, String newPattern) - { - int index = 0; - while (index != -1) - { - index = string.indexOf(oldPattern, index); - if (index != -1) - { - string = string.substring(0, index) + newPattern + string.substring(index + oldPattern.length()); - index = index + oldPattern.length(); - } - } - return string; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationConfiguration.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationConfiguration.java deleted file mode 100644 index 0e27080f16..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation; - -/** - * An XML validation configuration allows setting specific configuration - * information for a WTP XML validation run. Any features and properties - * set on this configuration should not be confused with those from - * parsers such as Xerces. (This object does not by default wrap features - * and properties from specific parsers.) - */ -public class XMLValidationConfiguration -{ - public static String WARN_NO_GRAMMAR = "WARN_NO_GRAMMAR"; //$NON-NLS-1$ - private boolean warn_no_grammar_value = false; - - /** - * Set a feature of this configuration. - * - * @param feature - * The feature to set. - * @param value - * The value to set for the feature. - * @throws - * An exception is thrown if the feature is not recognized. - */ - public void setFeature(String feature, boolean value) throws Exception - { - if(WARN_NO_GRAMMAR.equals(feature)) - warn_no_grammar_value = value; - else - throw new Exception("Feature not recognized."); //$NON-NLS-1$ - - } - - - /** - * Get the value for a given feature. If the feature is not defined - * this method will throw an exception. - * - * @param feature - * The feature for which to retrieve the value. - * @return - * The feature's value, true or false. - * @throws - * An exception is thrown if the feature is not recognized. - */ - public boolean getFeature(String feature) throws Exception - { - if(WARN_NO_GRAMMAR.equals(feature)) - return warn_no_grammar_value; - - throw new Exception("Feature not recognized."); //$NON-NLS-1$ - } - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationInfo.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationInfo.java deleted file mode 100644 index 6457db9c86..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationInfo.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation; - -import org.apache.xerces.xni.XMLLocator; -import org.eclipse.wst.xml.core.internal.validation.core.ValidationInfo; - - -/** - * A validation information object specific to XML validators. - * - * @author Lawrence Mandel, IBM - */ -public class XMLValidationInfo extends ValidationInfo implements XMLValidationReport -{ - protected boolean grammarEncountered = false; - protected boolean dtdEncountered = false; - protected boolean namespaceEncountered = false; - protected int elementDeclCount = 0; - protected String currentErrorKey; - protected Object messageArguments[] = null; - protected XMLLocator locator = null; - - /** - * Constructor. - * - * @param uri The URI of the file this report describes. - */ - public XMLValidationInfo(String uri) - { - super(uri); - } - - public boolean isGrammarEncountered() - { - return grammarEncountered; - } - - /** - * Set whether a grammar has been encountered or not. - * - * @param grammarEncountered Set true if a grammar has been encountered, false otherwise. - */ - public void setGrammarEncountered(boolean grammarEncountered) - { - this.grammarEncountered = grammarEncountered; - } - - public boolean isDTDWithoutElementDeclarationEncountered() - { - return dtdEncountered && elementDeclCount == 0; - } - - /** - * Set whether a DTD without an element declaration was encountered. - * - * @param dtdWithoutElementDeclarationEncountered Set true if a DTD without an - * element declaration was encountered, false otherwise. - */ - public void setDTDEncountered(boolean dtdEncountered) - { - this.dtdEncountered = dtdEncountered; - } - - public boolean isNamespaceEncountered() - { - return namespaceEncountered; - } - - /** - * Set whether a namespace was encountered. - * - * @param namespaceEncountered Set true if a namespace was encountered, false otherwise. - */ - public void setNamespaceEncountered(boolean namespaceEncountered) - { - this.namespaceEncountered = namespaceEncountered; - } - - /** - * Increase the element declaration count for DTD elements by one. - */ - public void increaseElementDeclarationCount() - { - this.elementDeclCount++; - } - - /** - * Set the number of DTD elements encountered. - * - * @param count The number of DTD elements encountered. - */ - public void setElementDeclarationCount(int count) - { - elementDeclCount = count; - } - - /** - * Get the XML locator if one has been specified. - * - * @return The XML locator if one has been specified or null. - */ - public XMLLocator getXMLLocator() - { - return locator; - } - - /** - * Set the XMLLocator. - * - * @param locator The XMLLocator to set. - */ - public void setXMLLocator(XMLLocator locator) - { - this.locator = locator; - } - - /** - * Get the current error key. - * - * @return Returns the currentErrorKey. - */ - public String getCurrentErrorKey() - { - return currentErrorKey; - } - - /** - * Set the current error key. - * - * @param currentErrorKey The currentErrorKey to set. - */ - public void setCurrentErrorKey(String currentErrorKey) - { - this.currentErrorKey = currentErrorKey; - } - -public Object[] getMessageArguments() { - return messageArguments; -} - - -public void setMessageArguments(Object[] messageArguments) { - this.messageArguments = messageArguments; -} - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationMessages.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationMessages.java deleted file mode 100644 index 59b5c96b4d..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationMessages.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * - */ -package org.eclipse.wst.xml.core.internal.validation; - -import org.eclipse.osgi.util.NLS; - -/** - * Strings used by XML Validation - */ -public class XMLValidationMessages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.wst.xml.core.internal.validation.xmlvalidation";//$NON-NLS-1$ - - public static String _UI_PROBLEMS_VALIDATING_UNKNOWN_HOST; - public static String _UI_PROBLEMS_VALIDATING_FILE_NOT_FOUND; - public static String _UI_PROBLEMS_CONNECTION_REFUSED; - public static String _UI_REF_FILE_ERROR_MESSAGE; - public static String _WARN_NO_GRAMMAR; - public static String Message_XML_validation_message_ui; - - static { - // load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, XMLValidationMessages.class); - } - - private XMLValidationMessages() { - // cannot create new instance - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationReport.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationReport.java deleted file mode 100644 index 7294d9c94a..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidationReport.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation; - -import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport; - -/** - * An interface represention a validation report for XML validation. - * - * @author Lawrence Mandel, IBM - */ -public interface XMLValidationReport extends ValidationReport -{ - - /** - * Returns whether a grammar was encountered during the validation. - * - * @return True if a grammar was encountered, false otherwise. - */ - public boolean isGrammarEncountered(); - - /** - * Returns whether a namespace was encountered. - * - * @return True if a namespace was encountered, false otherwise. - */ - public boolean isNamespaceEncountered(); - - /** - * Returns whether a DTD without element declarations was encountered. - * - * @return True if a DTD without element declarations was encountered. - */ - public boolean isDTDWithoutElementDeclarationEncountered(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidator.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidator.java deleted file mode 100644 index 8b34ad21b2..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidator.java +++ /dev/null @@ -1,600 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation; - -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.net.ConnectException; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; -import org.apache.xerces.impl.XMLErrorReporter; -import org.apache.xerces.parsers.StandardParserConfiguration; -import org.apache.xerces.xni.NamespaceContext; -import org.apache.xerces.xni.XMLLocator; -import org.apache.xerces.xni.XMLResourceIdentifier; -import org.apache.xerces.xni.XNIException; -import org.apache.xerces.xni.parser.XMLEntityResolver; -import org.apache.xerces.xni.parser.XMLInputSource; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; -import org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream; -import org.eclipse.wst.xml.core.internal.validation.core.logging.LoggerFactory; -import org.eclipse.wst.xml.core.internal.validation.errorcustomization.ErrorCustomizationManager; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; -import org.xml.sax.ext.DeclHandler; -import org.xml.sax.helpers.DefaultHandler; - -/** - * This class performs validation using a xerces sax parser. - * Here's a quick overview of the details : - * - an ErrorHandler is used to collect errors into a list (so they may be displayed by the UI) - * - an EntityResolver is used along with the xerces "external-schemaLocation" property to implement XML Catalog support - */ -public class XMLValidator -{ - protected URIResolver uriResolver = null; - //protected MyEntityResolver entityResolver = null; - protected ErrorCustomizationManager errorCustomizationManager; - protected Hashtable ingoredErrorKeyTable = new Hashtable(); - - protected static final String IGNORE_ALWAYS = "IGNORE_ALWAYS"; //$NON-NLS-1$ - protected static final String IGNORE_IF_DTD_WITHOUT_ELEMENT_DECL = "IGNORE_IF_DTD_WITHOUT_ELEMENT_DECL"; //$NON-NLS-1$ - protected static final String PREMATURE_EOF = "PrematureEOF"; //$NON-NLS-1$ - protected static final String ROOT_ELEMENT_TYPE_MUST_MATCH_DOCTYPEDECL = "RootElementTypeMustMatchDoctypedecl"; //$NON-NLS-1$ - protected static final String MSG_ELEMENT_NOT_DECLARED = "MSG_ELEMENT_NOT_DECLARED"; //$NON-NLS-1$ - - // WTP XML validator specific key. - protected static final String NO_GRAMMAR_FOUND = "NO_GRAMMAR_FOUND"; //$NON-NLS-1$ - - private static final String FILE_NOT_FOUND_KEY = "FILE_NOT_FOUND"; //$NON-NLS-1$ - - /** - * Constructor. - */ - public XMLValidator() - { - // Here we add some error keys that we need to filter out when we're validation - // against a DTD without any element declarations. - ingoredErrorKeyTable.put(PREMATURE_EOF, IGNORE_ALWAYS); - ingoredErrorKeyTable.put(ROOT_ELEMENT_TYPE_MUST_MATCH_DOCTYPEDECL, IGNORE_IF_DTD_WITHOUT_ELEMENT_DECL); - ingoredErrorKeyTable.put(MSG_ELEMENT_NOT_DECLARED, IGNORE_IF_DTD_WITHOUT_ELEMENT_DECL); - } - - /** - * Set the URI Resolver to use. - * - * @param uriResolver The URI Resolver to use. - */ - public void setURIResolver(URIResolver uriResolver) - { - this.uriResolver = uriResolver; - //entityResolver = new MyEntityResolver(uriResolver); - } - - - /** - * Create an XML Reader. - * - * @return The newly created XML reader or null if unsuccessful. - * @throws Exception - */ - protected XMLReader createXMLReader(final XMLValidationInfo valinfo, XMLEntityResolver entityResolver) throws Exception - { - XMLReader reader = null; - // move to Xerces-2... add the contextClassLoader stuff - ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader(); - try - { - Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); - StandardParserConfiguration configuration = new MyStandardParserConfiguration(valinfo); - reader = new org.apache.xerces.parsers.SAXParser(configuration) - { - public void startDocument(org.apache.xerces.xni.XMLLocator theLocator, java.lang.String encoding, NamespaceContext nscontext, org.apache.xerces.xni.Augmentations augs) - { - valinfo.setXMLLocator(theLocator); - super.startDocument(theLocator, encoding, nscontext, augs); - } - }; - - reader.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false); //$NON-NLS-1$ - reader.setFeature("http://xml.org/sax/features/namespace-prefixes", valinfo.isNamespaceEncountered()); //$NON-NLS-1$ - reader.setFeature("http://xml.org/sax/features/namespaces", valinfo.isNamespaceEncountered()); //$NON-NLS-1$ - reader.setFeature("http://xml.org/sax/features/validation", valinfo.isGrammarEncountered()); //$NON-NLS-1$ - reader.setFeature("http://apache.org/xml/features/validation/schema", valinfo.isGrammarEncountered()); //$NON-NLS-1$ - reader.setContentHandler(new DefaultHandler() - { - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - - if (errorCustomizationManager == null) - { - errorCustomizationManager = new ErrorCustomizationManager(); -// if (errorCustomizationManager.isDocumentNamespaceApplicable(uri)) -// { -// errorCustomizationManager.setActive(true); -// } - } - errorCustomizationManager.startElement(uri, localName); - } - - public void endElement(String uri, String localName, String qName) throws SAXException { - errorCustomizationManager.endElement(uri, localName); - } - }); - - // MH make sure validation works even when a customer entityResolver is note set (i.e. via setURIResolver()) - if (entityResolver != null) - { - reader.setProperty("http://apache.org/xml/properties/internal/entity-resolver", entityResolver); //$NON-NLS-1$ - } - reader.setProperty("http://xml.org/sax/properties/declaration-handler", new MyDeclHandler()); //$NON-NLS-1$ - } - catch(Exception e) - { - //TODO: log error message; - //e.printStackTrace(); - } - finally - { - Thread.currentThread().setContextClassLoader(prevClassLoader); - } - return reader; - } - - /** - * Validate the file located at the given URI. - * - * @param uri The URI of the file to validate. - * @return Returns an XML validation report. - */ - public XMLValidationReport validate(String uri) - { - return validate(uri, null, new XMLValidationConfiguration()); - } - - final String createStringForInputStream(InputStream inputStream) - { - // Here we are reading the file and storing to a stringbuffer. - StringBuffer fileString = new StringBuffer(); - try - { - InputStreamReader inputReader = new InputStreamReader(inputStream); - BufferedReader reader = new BufferedReader(inputReader); - char[] chars = new char[1024]; - int numberRead = reader.read(chars); - while (numberRead != -1) - { - fileString.append(chars, 0, numberRead); - numberRead = reader.read(chars); - } - } - catch (Exception e) - { - //TODO: log error message - //e.printStackTrace(); - } - return fileString.toString(); - } - /** - * Validate the inputStream - * - * @param uri The URI of the file to validate. - * @param the inputStream of the file to validate - * @return Returns an XML validation report. - */ - public XMLValidationReport validate(String uri, InputStream inputStream) - { - return validate(uri, inputStream, new XMLValidationConfiguration()); - } - /** - * Validate the inputStream - * - * @param uri - * The URI of the file to validate. - * @param inputstream - * The inputStream of the file to validate - * @param configuration - * A configuration for this validation session. - * @return - * Returns an XML validation report. - */ - public XMLValidationReport validate(String uri, InputStream inputStream, XMLValidationConfiguration configuration) - { - Reader reader1 = null; // Used for the preparse. - Reader reader2 = null; // Used for validation parse. - - if (inputStream != null) - { - String string = createStringForInputStream(inputStream); - reader1 = new StringReader(string); - reader2 = new StringReader(string); - } - - XMLValidationInfo valinfo = new XMLValidationInfo(uri); - MyEntityResolver entityResolver = new MyEntityResolver(uriResolver); - ValidatorHelper helper = new ValidatorHelper(); - try - { - helper.computeValidationInformation(uri, reader1, uriResolver); - valinfo.setDTDEncountered(helper.isDTDEncountered); - valinfo.setElementDeclarationCount(helper.numDTDElements); - valinfo.setNamespaceEncountered(helper.isNamespaceEncountered); - valinfo.setGrammarEncountered(helper.isGrammarEncountered); - - XMLReader reader = createXMLReader(valinfo, entityResolver); - XMLErrorHandler errorhandler = new XMLErrorHandler(valinfo); - reader.setErrorHandler(errorhandler); - - InputSource inputSource = new InputSource(uri); - inputSource.setCharacterStream(reader2); - reader.parse(inputSource); - if(configuration.getFeature(XMLValidationConfiguration.WARN_NO_GRAMMAR) && - valinfo.isValid() && !helper.isGrammarEncountered) - { - valinfo.addWarning(XMLValidationMessages._WARN_NO_GRAMMAR, 1, 0, uri, NO_GRAMMAR_FOUND, null); - } - } - catch (SAXParseException saxParseException) - { - // These errors are caught by the error handler. - //addValidationMessage(valinfo, saxParseException); - } - catch (IOException ioException) - { - addValidationMessage(valinfo, ioException); - } - catch (Exception exception) - { - LoggerFactory.getLoggerInstance().logError(exception.getLocalizedMessage(), exception); - } - - - return valinfo; - - } - - /** - * Add a validation message to the specified list. - * - * @param valinfo The validation info object to add the error to. - * @param exception The exception that contains the validation information. - */ - protected void addValidationMessage(XMLValidationInfo valinfo, IOException exception) - { - String validationMessageStr = exception.getMessage(); - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - while(validationMessageStr == null && cause != null){ - String localizedMessage = cause.getLocalizedMessage(); - cause = cause.getCause(); - if(cause == null && localizedMessage != null ) - { - validationMessageStr = localizedMessage; - } - } - - if (validationMessageStr != null) - { - if (cause instanceof FileNotFoundException) - { - validationMessageStr = NLS.bind(XMLValidationMessages._UI_PROBLEMS_VALIDATING_FILE_NOT_FOUND, new Object [] { validationMessageStr }); - } - else if (cause instanceof UnknownHostException) - { - validationMessageStr = NLS.bind(XMLValidationMessages._UI_PROBLEMS_VALIDATING_UNKNOWN_HOST, new Object [] { validationMessageStr }); - } - else if(cause instanceof ConnectException) - { - validationMessageStr = XMLValidationMessages._UI_PROBLEMS_CONNECTION_REFUSED; - } - } - - if (validationMessageStr != null) - { - XMLLocator locator = valinfo.getXMLLocator(); - valinfo.addWarning(validationMessageStr, locator != null ? locator.getLineNumber() : 1, locator != null ? locator.getColumnNumber() : 0, valinfo.getFileURI(), FILE_NOT_FOUND_KEY, null); - } - } - - /** - * Add a validation message to the specified list. - * - * @param valinfo The validation info object to add the error to. - * @param exception The exception that contains the validation information. - */ - protected void addValidationMessage(XMLValidationInfo valinfo, SAXParseException exception) - { - if (exception.getMessage() != null) - { - valinfo.addError(exception.getLocalizedMessage(), exception.getLineNumber(), exception.getColumnNumber(), exception.getSystemId()); - } - } - - - /** - * A custom entity resolver that uses the URI resolver specified to resolve entities. - */ - protected class MyEntityResolver implements XMLEntityResolver - { - private URIResolver uriResolver; - - - /** - * Constructor. - * - * @param uriResolver The URI resolver to use with this entity resolver. - */ - public MyEntityResolver(URIResolver uriResolver) - { - this.uriResolver = uriResolver; - } - - /* (non-Javadoc) - * @see org.apache.xerces.xni.parser.XMLEntityResolver#resolveEntity(org.apache.xerces.xni.XMLResourceIdentifier) - */ - public XMLInputSource resolveEntity(XMLResourceIdentifier rid) throws XNIException, IOException - { - try - { - return _internalResolveEntity(uriResolver, rid); - } - catch(IOException e) - { - //e.printStackTrace(); - } - return null; - } - } - - // cs : I've refactored the common SAX based resolution code into this method for use by other validators - // (i.e. XML Schema, WSDL etc). The other approach is maintain a copy for each validator that has - // identical code. In any case we should strive to ensure that the validators perform resolution consistently. - public static XMLInputSource _internalResolveEntity(URIResolver uriResolver, XMLResourceIdentifier rid) throws IOException - { - XMLInputSource is = null; - - if (uriResolver != null) - { - String id = rid.getPublicId(); - if(id == null) - { - id = rid.getNamespace(); - } - - String location = null; - if (id != null || rid.getLiteralSystemId() != null) - { - location = uriResolver.resolve(rid.getBaseSystemId(), id, rid.getLiteralSystemId()); - } - - if (location != null) - { - String physical = uriResolver.resolvePhysicalLocation(rid.getBaseSystemId(), id, location); - is = new XMLInputSource(rid.getPublicId(), location, location); - - // This block checks that the file exists. If it doesn't we need to throw - // an exception so Xerces will report an error. note: This may not be - // necessary with all versions of Xerces but has specifically been - // experienced with the version included in IBM's 1.4.2 JDK. - InputStream isTemp = null; - try - { - isTemp = new URL(physical).openStream(); - } - finally - { - if(isTemp != null) - { - isTemp.close(); - } - } - is.setByteStream(new LazyURLInputStream(physical)); - } - } - return is; - } - - /** - * An error handler to catch errors encountered while parsing the XML document. - */ - protected class XMLErrorHandler implements org.xml.sax.ErrorHandler - { - - private final int ERROR = 0; - private final int WARNING = 1; - private XMLValidationInfo valinfo; - - /** - * Constructor. - * - * @param valinfo The XML validation info object that will hold the validation messages. - */ - public XMLErrorHandler(XMLValidationInfo valinfo) - { - this.valinfo = valinfo; - } - - /** - * Add a validation message with the given severity. - * - * @param exception The exception that contains the message. - * @param severity The severity of the message. - */ - - protected void addValidationMessage(SAXParseException exception, int severity) - { - if(exception.getSystemId() != null) - { - if(severity == WARNING) - { - valinfo.addWarning(exception.getLocalizedMessage(), exception.getLineNumber(), exception.getColumnNumber(), exception.getSystemId()); - } - else - { - valinfo.addError(exception.getLocalizedMessage(), exception.getLineNumber(), exception.getColumnNumber(), exception.getSystemId(), valinfo.getCurrentErrorKey(), valinfo.getMessageArguments()); - } - } - } - - /* (non-Javadoc) - * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException) - */ - public void error(SAXParseException exception) throws SAXException - { - addValidationMessage(exception, ERROR); - } - - /* (non-Javadoc) - * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) - */ - public void fatalError(SAXParseException exception) throws SAXException - { - addValidationMessage(exception, ERROR); - } - - /* (non-Javadoc) - * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException) - */ - public void warning(SAXParseException exception) throws SAXException - { - addValidationMessage(exception, WARNING); - } - } - - /** - * This class is used to count the elementDecls that are encountered in a DTD. - */ - protected class MyDeclHandler implements DeclHandler - { - - /** - * Constructor. - * - * @param valinfo The XMLValidationInfo object that will count the declarations. - */ - public MyDeclHandler() - { - } - - /* (non-Javadoc) - * @see org.xml.sax.ext.DeclHandler#attributeDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) - */ - public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) - { - } - - /* (non-Javadoc) - * @see org.xml.sax.ext.DeclHandler#elementDecl(java.lang.String, java.lang.String) - */ - public void elementDecl(String name, String model) - { - //valinfo.increaseElementDeclarationCount(); - } - - /* (non-Javadoc) - * @see org.xml.sax.ext.DeclHandler#externalEntityDecl(java.lang.String, java.lang.String, java.lang.String) - */ - public void externalEntityDecl(String name, String publicId, String systemId) - { - } - - /* (non-Javadoc) - * @see org.xml.sax.ext.DeclHandler#internalEntityDecl(java.lang.String, java.lang.String) - */ - public void internalEntityDecl(String name, String value) - { - } - } - - /** - * A StandardParserConfiguration that creates an error reporter which can ignore - * DTD error messages for DTD's with no elements defined. - */ - - protected class MyStandardParserConfiguration extends StandardParserConfiguration - { - XMLValidationInfo valinfo = null; - List reportedExceptions = new ArrayList(); - - /** - * Constructor. - * - * @param valinfo The XMLValidationInfo object to use. - */ - public MyStandardParserConfiguration(XMLValidationInfo valinfo) - { - this.valinfo = valinfo; - } - - /* (non-Javadoc) - * @see org.apache.xerces.parsers.DTDConfiguration#createErrorReporter() - */ - protected XMLErrorReporter createErrorReporter() - { - return new XMLErrorReporter() - { - /* (non-Javadoc) - * @see org.apache.xerces.impl.XMLErrorReporter#reportError(java.lang.String, java.lang.String, java.lang.Object[], short) - */ - public void reportError(String domain, String key, Object[] arguments, short severity) throws XNIException - { - boolean reportError = true; - valinfo.setCurrentErrorKey(key); - valinfo.setMessageArguments(arguments); - String ignoreCondition = (String)ingoredErrorKeyTable.get(key); - if (ignoreCondition != null) - { - if (ignoreCondition.equals(XMLValidator.IGNORE_IF_DTD_WITHOUT_ELEMENT_DECL)) - { - boolean isDTDWithoutElementDeclarationEncountered = valinfo.isDTDWithoutElementDeclarationEncountered(); - reportError = !isDTDWithoutElementDeclarationEncountered; - } - else - { - reportError = false; - } - } - if ("schema_reference.4".equals(key) && arguments.length > 0) //$NON-NLS-1$ - { - Object location = arguments[0]; - if (location != null) - { - if(reportedExceptions.contains(location)) - { - reportError = false; - } - else - { - reportedExceptions.add(location); - } - } - } - if (reportError) - { - super.reportError(domain, key, arguments, severity); - errorCustomizationManager.considerReportedError(valinfo, key, arguments); - } - } - }; - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/AbstractNestedValidator.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/AbstractNestedValidator.java deleted file mode 100644 index 28ea05d926..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/AbstractNestedValidator.java +++ /dev/null @@ -1,472 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation.core; - -import java.io.InputStream; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.validation.internal.core.Message; -import org.eclipse.wst.validation.internal.core.ValidationException; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; -import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; -import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob; - -/** - * An abstract validator that assists validators in running and contributing - * nested messages in the validation results. - * *note: Subclasses do not need to contribute nested messages in order to - * benefit from the use of this class. This class takes care of iterating - * through results for validators that use the standard context. - */ -public abstract class AbstractNestedValidator implements IValidatorJob -{ - // Locally used, non-UI strings. - private static final String REFERENCED_FILE_ERROR_OPEN = "referencedFileError("; //$NON-NLS-1$ - private static final String REFERENCED_FILE_ERROR_CLOSE = ")"; //$NON-NLS-1$ - private static final String REFERENCED_FILE_ERROR = "referencedFileError"; //$NON-NLS-1$ - private static final String FILE_PROTOCOL_NO_SLASH = "file:"; //$NON-NLS-1$ - private static final String FILE_PROTOCOL = "file:///"; //$NON-NLS-1$ - private static final String GROUP_NAME = "groupName"; //$NON-NLS-1$ - private final String GET_FILE = "getFile"; //$NON-NLS-1$ - private final String GET_PROJECT_FILES = "getAllFiles"; //$NON-NLS-1$ - private final String GET_INPUTSTREAM = "inputstream"; //$NON-NLS-1$ - - // Internal strings. These strings are common addition information types. - protected static final String COLUMN_NUMBER_ATTRIBUTE = "columnNumber"; //$NON-NLS-1$ - protected static final String SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = "squiggleSelectionStrategy"; //$NON-NLS-1$ - protected static final String SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = "squiggleNameOrValue"; //$NON-NLS-1$ - - - - /* (non-Javadoc) - * @see org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#validateInJob(org.eclipse.wst.validation.internal.provisional.core.IValidationContext, org.eclipse.wst.validation.internal.provisional.core.IReporter) - */ - public IStatus validateInJob(IValidationContext context, IReporter reporter) throws ValidationException - { - NestedValidatorContext nestedcontext = new NestedValidatorContext(); - setupValidation(nestedcontext); - String[] fileURIs = context.getURIs(); - if (fileURIs != null && fileURIs.length > 0) - { - int numFiles = fileURIs.length; - for (int i = 0; i < numFiles && !reporter.isCancelled(); i++) - { - String fileName = fileURIs[i]; - if (fileName != null) - { - Object []parms = {fileName}; - - IFile file = (IFile) context.loadModel(GET_FILE, parms); - if (file != null && shouldValidate(file)) - { - // The helper may not have a file stored in it but may have an InputStream if being - // called from a source other than the validation framework such as an editor. - if (context.loadModel(GET_INPUTSTREAM) instanceof InputStream) //$NON-NLS-1$ - { - validate(file, (InputStream)context.loadModel(GET_INPUTSTREAM), reporter, nestedcontext); //do we need the fileName? what is int ruleGroup? //$NON-NLS-1$ - } - else - { - validate(file, null, reporter, nestedcontext); - } - } - } - } - } - // TODO: Is this needed? Shouldn't the framework pass the complete list? - // Should I know that I'm validating a project as opposed to files? - else - { - Object []parms = {getValidatorID()}; - Collection files = (Collection) context.loadModel(GET_PROJECT_FILES, parms); - Iterator iter = files.iterator(); - while (iter.hasNext() && !reporter.isCancelled()) - { - IFile file = (IFile) iter.next(); - if(shouldValidate(file)) - { - validate(file, null, reporter, nestedcontext); - } - } - } - - teardownValidation(nestedcontext); - if(reporter.isCancelled()) - return Status.CANCEL_STATUS; - return Status.OK_STATUS; - } - - /** - * Provides the id of this validator. The ID is used by the validation - * framework. It usually is the fully qualified class name of the class - * implementing the IValidator interface. - * - * @return a String with the ID of this validator. - */ - protected String getValidatorID() - { - return this.getClass().getName(); - } - - /** - * Get the name of this validator. The name will be reported to the - * validation framework. - * Subclasses must implement this method. - * - * @return - * The name of this validator. - */ - protected abstract String getValidatorName(); - - /** - * Perform set up before validation runs. Subclasses may implement this - * method to perform validation specific set up. - * - * @param context - * The context of the current validation. - */ - protected void setupValidation(NestedValidatorContext context) - { - // Default implementation does nothing. - } - - /** - * Perform tear down after validation runs. Subclasses may implement this - * method to perform validation specific tear down. - * - * @param context - * The context of the current validation. - */ - protected void teardownValidation(NestedValidatorContext context) - { - // Default implementation does nothing. - } - - /* (non-Javadoc) - * @see org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#getSchedulingRule(org.eclipse.wst.validation.internal.provisional.core.IValidationContext) - */ - public ISchedulingRule getSchedulingRule(IValidationContext arg0) - { - // TODO review whether returning a null rule is correct. Gary had a suggestion in the bug report. - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.validation.internal.provisional.core.IValidator#cleanup(org.eclipse.wst.validation.internal.provisional.core.IReporter) - */ - public void cleanup(IReporter arg0) - { - // No cleanup to perform. Subclasses are free to implement this method. - } - - /* (non-Javadoc) - * @see org.eclipse.wst.validation.internal.provisional.core.IValidator#validate(org.eclipse.wst.validation.internal.provisional.core.IValidationContext, org.eclipse.wst.validation.internal.provisional.core.IReporter) - */ - public void validate(IValidationContext arg0, IReporter arg1) throws ValidationException - { - // This method should not be implemented by validtors implementing the validateInJob - // method. - } - - - /** - * Determine if a given file should be validated. - * - * @param file The file that may be validated. - * @return True if the file should be validated, false otherwise. - */ - private static boolean shouldValidate(IFile file) - { - IResource resource = file; - do - { - if (resource.isDerived() || resource.isTeamPrivateMember() || - !resource.isAccessible() || resource.getName().charAt(0) == '.') - { - return false; - } - resource = resource.getParent(); - }while ((resource.getType() & IResource.PROJECT) == 0); - - return true; - } - - /** - * Validate the given file and use the reporter for the validation messages. - * This method does not perform the validation logic but rather delegates - * to the validate method in subclasses to validate. This method is responsible - * for reporting the messages that result from validation. - * - * @param file - * An IFile to validate. - * @param inputstream - * An InputStream that represents the file. The InputStream may be null - * in which case the files should be validated from the IFile. - * @param reporter - * The reporter with which to report validation messages. - * @param context - * The context of the current validation. - */ - private void validate(IFile file, InputStream inputstream, IReporter reporter, NestedValidatorContext context) - { - Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, NLS.bind(getValidatorName(), new String[]{file.getFullPath().toString()})); - reporter.displaySubtask(this, message); - - IPath path = file.getLocation(); - String uri = createURIForFilePath(path.toString()); - - clearMarkers(file, this, reporter); - ValidationReport valreport = validate(uri, inputstream, context); - - createMarkers(file, valreport.getValidationMessages(), reporter); - - try - { - file.setSessionProperty(ValidationMessage.ERROR_MESSAGE_MAP_QUALIFIED_NAME, valreport.getNestedMessages()); - } - catch(CoreException e) - { - System.out.println("Unable to set nested messages property."); //$NON-NLS-1$ - } - } - - /** - * Validate the given file and use the reporter for the validation messages. - * Clients must implement this method with their specific validation logic. - * - * @param uri - * The URI of the file to validate. - * @param inputstream - * An InputStream that represents the file. The InputStream may be null - * in which case the files should be validated from the IFile. - * @param context - * The context of the current validation. - * @return - * A validation report summarizing the validation. - */ - public abstract ValidationReport validate(String uri, InputStream inputstream, NestedValidatorContext context); - - /** - * This method clears all the markers on the given IFile for a specified - * validator. - * This is a convenience method for subclasses. - * - * @param iFile - * The IFile from which to clear the markers. - * @param validator - * The validator for which to remove the markers. - * @param reporter - * The reporter that can remove the markers. - */ - private void clearMarkers(IFile iFile, IValidator validator, IReporter reporter) - { - if (fileIsAccessible(iFile)) - { - reporter.removeAllMessages(validator, iFile); - } - } - - /** - * Test whether the given file is accessible and may be used for validation. A file is - * available if - * 1. It is not null. - * 2. It exists. - * 3. The project containing the file is accessible. - * - * @param file - * The file to check to ensure it is accessible. - * @return - * True if the file is accessible, false otherwise. - */ - private boolean fileIsAccessible(IFile file) - { - if (file != null && file.exists() && file.getProject().isAccessible()) - { - return true; - } - return false; - } - - /** - * Format a file name into a correct URI. - * This is a convenience method for subclasses. - * - * @param filename - * The file name to format. - * @return - * - * The formatted URI. - */ - private String createURIForFilePath(String filename) - { - if(!filename.startsWith(FILE_PROTOCOL_NO_SLASH)) - { - while(filename.startsWith("/")) //$NON-NLS-1$ - { - filename = filename.substring(1); - } - filename = FILE_PROTOCOL + filename; - } - return filename; - } - - /** - * Create markers for the valiation messages generated from the validation. - * - * @param iFile - * The resource to create the markers on. - * @param valmessages - * The array of validation messages. - */ - public void createMarkers(IFile iFile, ValidationMessage[] valmessages, IReporter reporter) - { - if (!fileIsAccessible(iFile)) - { - return; - } - int nummessages = valmessages.length; - for (int i = 0; i < nummessages; i++) - { - ValidationMessage validationMessage = valmessages[i]; - String uri = validationMessage.getUri(); - - LocalizedMessage message; - if (validationMessage.getSeverity() == ValidationMessage.SEV_LOW) - { - message = new LocalizedMessage(IMessage.NORMAL_SEVERITY, - validationMessage.getMessage(), iFile); - } - else - { - message = new LocalizedMessage(IMessage.HIGH_SEVERITY, validationMessage.getMessage(), iFile); - } - - message.setLineNo(validationMessage.getLineNumber()); - addInfoToMessage(validationMessage, message); - - List nestederrors = validationMessage.getNestedMessages(); - if (nestederrors != null && !nestederrors.isEmpty()) - { - message.setGroupName(REFERENCED_FILE_ERROR_OPEN + uri + REFERENCED_FILE_ERROR_CLOSE); - } - - reporter.addMessage(this, message); - - } - try - { - IMarker[] markers = iFile.findMarkers(null, true, IResource.DEPTH_INFINITE); - for (int i = 0; i < markers.length; i++) - { - IMarker marker = markers[i]; - String groupName = null; - try - { - groupName = (String) marker.getAttribute(GROUP_NAME); - } - catch (Exception e) - { - } - if (groupName != null && groupName.startsWith(REFERENCED_FILE_ERROR)) - { - marker.setAttribute(IMarker.DONE, true); - } - } - } - catch (CoreException e) - { - e.printStackTrace(); - } - } - - /** - * This method allows the addition of information to the validation message - * @param validationmessage - * The ValidationMessage to retrieve the information from. - * @param message - * The IMessage to add the information to. - */ - protected void addInfoToMessage (ValidationMessage validationmessage, IMessage message) - { - // This method may be overidden by subclasses - } - - /** - * A localized message is a specialized type of IMessage that allows setting - * and using a localized message string for a message. - */ - class LocalizedMessage extends Message - { - private String _message = null; - - public LocalizedMessage(int severity, String messageText) - { - this(severity, messageText, null); - } - - public LocalizedMessage(int severity, String messageText, IResource targetObject) - { - this(severity, messageText, (Object) targetObject); - } - - public LocalizedMessage(int severity, String messageText, Object targetObject) - { - super(null, severity, null); - setLocalizedMessage(messageText); - setTargetObject(targetObject); - } - - public void setLocalizedMessage(String message) - { - _message = message; - } - - public String getLocalizedMessage() - { - return _message; - } - - public String getText() - { - return getLocalizedMessage(); - } - - public String getText(ClassLoader cl) - { - return getLocalizedMessage(); - } - - public String getText(Locale l) - { - return getLocalizedMessage(); - } - - public String getText(Locale l, ClassLoader cl) - { - return getLocalizedMessage(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/Helper.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/Helper.java deleted file mode 100644 index d9497af689..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/Helper.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation.core; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.wst.validation.internal.operations.ValidatorManager; -import org.eclipse.wst.validation.internal.operations.WorkbenchContext; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -/** - * A helper class for validation in the validation framework. - * - * @author Ernest Mah (ernest@ca.ibm.com) - * @author Lawrence Mandel, IBM - */ -public class Helper extends WorkbenchContext -{ - public static final String GET_PROJECT_FILES = "getAllFiles"; //$NON-NLS-1$ - public static final String GET_FILE = "getFile"; //$NON-NLS-1$ - //dw private static final IContainer[] NO_CONTAINERS = new IContainer[0]; - public static final String VALIDATION_MARKER = "org.eclipse.wst.validation.problemmarker"; //$NON-NLS-1$ - public static final String VALIDATION_MARKER_OWNER = "owner"; //$NON-NLS-1$ - - /** - * Constructor. - */ - public Helper() - { - super(); - - // the following will register the helper's symbolic methods - Class [] args = new Class[1] ; - args[0] = String.class ; // a string argument denoting a specific JSP. - - registerModel(GET_FILE, "getFile", args);//$NON-NLS-1$ - registerModel(GET_PROJECT_FILES, "getFiles", args);//$NON-NLS-1$ - } - - /** - * Get the IFile for the given filename. - * - * @param filename The name of the file to retrieve. - * @return An IFile representing the file specified or null if it can't be resolved. - */ - public IFile getFile(String filename) - { - // System.out.println("file name = " + filename); - IResource res = getProject().findMember(filename, true); // true means include phantom resources - if (res instanceof IFile) - { - return (IFile) res; - } - return null; - } - - /** - * Get the collection of files from the project that are relevant for the - * validator with the given class name. - * - * @param validatorClassName The name of the validator class. - * @return The collection of files relevant for the validator class specified. - */ - public Collection getFiles(String validatorClassName) - { - IProject project = getProject(); - List files = new ArrayList(); - getFiles(files, project, validatorClassName); - return files; - } - - /** - * Get the collection of files from the project that are relevant for the - * validator with the given class name. - * - * @param files The files relevant for the class name. - * @param resource The resource to look for files in. - * @param validatorClassName The name of the validator class. - */ - protected void getFiles(Collection files, IContainer resource, String validatorClassName) - { - try - { - IResource [] resourceArray = resource.members(false); - for (int i=0; i<resourceArray.length; i++) - { - if (ValidatorManager.getManager().isApplicableTo(validatorClassName, resourceArray[i])) - { - if (resourceArray[i] instanceof IFile) - { - files.add(resourceArray[i]); - } - } - if (resourceArray[i].getType() == IResource.FOLDER) - getFiles(files,(IContainer)resourceArray[i], validatorClassName) ; - } - } - catch (Exception e) {} - } - - -/** - * Return the name of the resource, without the project-specific information - * in front. - * - * This method is used by ValidationOperation to calculate the non-environment - * specific names of the files. Only the IWorkbenchContext implementation knows how - * much information to strip off of the IResource name. For example, if there is - * an EJB Project named "MyEJBProject", and it uses the default names for the - * source and output folders, "source" and "ejbModule", respectively, then the - * current implementation of EJB Helper knows how much of that structure is - * eclipse-specific. - * - * Since the "source" folder contains Java source files, a portable name would - * be the fully-qualified name of the Java class, without the eclipse-specific - * project and folder names in front of the file name. The EJBHelper knows that - * everything up to the "source" folder, for example, can be removed, because, - * according to the definition of the EJB Project, everything contained - * in the source folder is java source code. So if there is an IResource in an - * EJB Project named "/MyEJBProject/source/com/ibm/myclasses/MyJavaFile.java", - * this method would make this name portable by stripping off the - * "/MyEJBProject/source", and returning "com/ibm/myclasses/MyJavaFile.java". - * - * The output of this method is used by the ValidationOperation, when it - * is calculating the list of added/changed/deleted file names for incremental - * validation. If getPortableName(IResource) returns null, that means - * that the IWorkbenchContext's implementation does not support that particular - * type of resource, and the resource should not be included in the array of - * IFileDelta objects in the IValidator's "validate" method. - * - * @param resource The resource to get the name from. - * @return The portable name of the resource. - */ -public String getPortableName(IResource resource) - { - // System.out.println("get portablename for " + resource); - return resource.getProjectRelativePath().toString(); - } - -/** - * When an IValidator associates a target object with an IMessage, - * the WorkbenchReporter eventually resolves that target object - * with an IResource. Sometimes more than one target object resolves - * to the same IResource (usually the IProject, which is the default - * IResource when an IFile cannot be found). This method is called, - * by the WorkbenchReporter, so that the WorkbenchReporter can - * distinguish between the IMessages which are on the same IResource, - * but refer to different target objects. This is needed for the - * removeAllMessages(IValidator, Object) method, so that when one - * target object removes all of its messages, that it doesn't remove - * another target object's messages. - * - * This method may return null only if object is null. Otherwise, an - * id which can uniquely identify a particular object must be returned. - * The id needs to be unique only within one particular IValidator. - * - * @param object The object from which to get the name. - * @return The name of the object or null if the object is null. - */ -public String getTargetObjectName(Object object) - { - if (object == null) - { - return null; - } - - // System.out.println("get targetname for " + object); - return object.toString(); - } - - /** - * Delete the markers of the specified type from the specified resource. - * - * @param resource The resource to delete the markers from. - * @param markerType The type of markers to delete from the resource. - * @param attributeName The name of the attribute which the markers must have to be deleted. - * @param attributeValue The value of the attribute corresponding to attributeName which the markers must have to be deleted. - * @throws CoreException - */ - public static void deleteMarkers(IResource resource, String markerType, final String attributeName, final Object attributeValue) throws CoreException - { - final IMarker[] v400Markers = resource.findMarkers(IMarker.PROBLEM, false, IResource.DEPTH_INFINITE); - final IMarker[] markers = resource.findMarkers(markerType, true, IResource.DEPTH_INFINITE); - IWorkspaceRunnable op = new IWorkspaceRunnable() - { - public void run(IProgressMonitor progressMonitor) throws CoreException - { - // this fixes defect 193406 - // here we remove markers that may have been added by the v400 code - // hopefully the '.markers' metadata files will be removed for the V5 install - // and this kludge will not be needed there - for (int i = 0; i < v400Markers.length; i++) - { - IMarker marker = markers[i]; - marker.delete(); - } - - for (int i = 0; i < markers.length; i++) - { - IMarker marker = markers[i]; - - Object value = marker.getAttribute(attributeName); - if (value != null && - value.equals(attributeValue)) - { - marker.delete(); - } - } - } - }; - - try - { - ResourcesPlugin.getWorkspace().run(op, null); - } - catch (Exception e) { } - } - - /** - * Get the validation framework severity for the given severity. - * - * @param severity The severity to convert to validation framework severity. - * @return The validation framework severity for the given severity. - */ - static public int getValidationFrameworkSeverity(int severity) - { - switch (severity) - { - case IMarker.SEVERITY_ERROR: - return IMessage.HIGH_SEVERITY; - case IMarker.SEVERITY_WARNING: - return IMessage.NORMAL_SEVERITY; - case IMarker.SEVERITY_INFO: - return IMessage.LOW_SEVERITY; - } - return IMessage.LOW_SEVERITY; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/LazyURLInputStream.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/LazyURLInputStream.java deleted file mode 100644 index 834cb0b23a..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/LazyURLInputStream.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation.core; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; - - -/** - * This class allows InputStreams to be created and returned to xerces without - * actually opening file handles or network connections until it is absolutely - * neccessary. - */ -public class LazyURLInputStream extends InputStream -{ - private static int debugTotalOpenStreamCount = 0; - protected InputStream inner; - protected String url; - protected boolean error; - boolean hasMarks; - boolean pretendFileIsStillOpen; - - public LazyURLInputStream(String url) - { - this.url = url; - inner = null; - pretendFileIsStillOpen = false; - } - - private void createInnerStreamIfRequired() throws IOException - { - if (inner == null && !error) - { - debugTotalOpenStreamCount++; - - try - { - inner = new URL(url).openStream(); - pretendFileIsStillOpen = false; - hasMarks = false; - } - finally - { - if (inner == null) - { - error = true; - } - } - } - } - - protected void closeStream() throws IOException { - if (inner != null && !pretendFileIsStillOpen) { - inner.close(); - pretendFileIsStillOpen = true; - } - } - - public int available() throws IOException - { - if (pretendFileIsStillOpen) return 0; - createInnerStreamIfRequired(); - if (inner == null) throw new IOException("Stream not available"); //$NON-NLS-1$ - return inner.available(); - } - - public void close() throws IOException - { - if (pretendFileIsStillOpen) { - // Stop behaving as if the stream were still open. - pretendFileIsStillOpen = false; - } else { - if (inner != null) { - debugTotalOpenStreamCount--; - inner.close(); - } - } - } - - public void mark(int readlimit) - { - if (pretendFileIsStillOpen) return; - hasMarks = true; - try { - createInnerStreamIfRequired(); - inner.mark(readlimit); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public boolean markSupported() - { - if (pretendFileIsStillOpen) return false; - try { - createInnerStreamIfRequired(); - if (inner == null) return false; - return inner.markSupported(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return false; - } - - public int read() throws IOException - { - if (pretendFileIsStillOpen) return -1; - createInnerStreamIfRequired(); - if (inner == null) throw new IOException("Stream not available"); //$NON-NLS-1$ - int bytesRead = inner.read(); - if (bytesRead == -1 && !hasMarks) closeStream(); - return bytesRead; - } - - - public int read(byte[] b) throws IOException { - if (pretendFileIsStillOpen) return -1; - createInnerStreamIfRequired(); - if (inner == null) throw new IOException("Stream not available"); //$NON-NLS-1$ - int bytesRead = inner.read(b); - if (bytesRead == -1 && !hasMarks) closeStream(); - return bytesRead; - } - - public int read(byte[] b, int off, int len) throws IOException - { - if (pretendFileIsStillOpen) return -1; - createInnerStreamIfRequired(); - if (inner == null) throw new IOException("Stream not available"); //$NON-NLS-1$ - int bytesRead = inner.read(b, off, len); - if (bytesRead == -1 && !hasMarks) closeStream(); - return bytesRead; - } - - public void reset() throws IOException - { - if (pretendFileIsStillOpen) return; - createInnerStreamIfRequired(); - if (inner == null) throw new IOException("Stream not available"); //$NON-NLS-1$ - inner.reset(); - } - - public long skip(long n) throws IOException - { - if (pretendFileIsStillOpen) return 0; - createInnerStreamIfRequired(); - if (inner == null) throw new IOException("Stream not available"); //$NON-NLS-1$ - return inner.skip(n); - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/NestedValidatorContext.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/NestedValidatorContext.java deleted file mode 100644 index 3c2710ad42..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/NestedValidatorContext.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation.core; - - -/** - * A context class for validators to be able to determine the context of - * given validation session. Currently this class is only used to identify - * the unique context. - */ -public class NestedValidatorContext -{ -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/ValidationInfo.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/ValidationInfo.java deleted file mode 100644 index fa2e1a597f..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/ValidationInfo.java +++ /dev/null @@ -1,286 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation.core; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.xml.core.internal.validation.XMLValidationMessages; - -/** - * This class handles messages from a validator. This class can handle - * - * @author Lawrence Mandel, IBM - */ -public class ValidationInfo implements ValidationReport -{ - private boolean WRAPPER_ERROR_SUPPORT_ENABLED = true; - public static int SEV_ERROR = 0; - public static int SEV_WARNING = 1; - - private String validating_file_uri = null; - private URL validating_file_url = null; - private boolean valid = true; - private List messages = new ArrayList(); - private HashMap nestedMessages = new HashMap(); - - /** - * Constructor. - * - * @param uri - * The URI of the file for the validation. - */ - public ValidationInfo(String uri) - { - if(uri != null) - { - this.validating_file_uri = uri; - try - { - this.validating_file_url = new URL(uri); - } catch (MalformedURLException e) - { - } - } - } - - public String getFileURI() - { - return validating_file_uri; - } - - public boolean isValid() - { - return valid; - } - - /** - * Add an error message. - * - * @param message The message to add. - * @param line The line location of the message. - * @param column The column location of the message. - * @param uri The URI of the file that contains the message. - */ - public void addError(String message, int line, int column, String uri) - { - addError(message, line, column, uri, null, null); - } - - /** - * - * Add an error message. - * - * @param message The message to add. - * @param line The line location of the message. - * @param column The column location of the message. - * @param uri The URI of the file that contains the message. - * @param key The key for the message. - * @param messageArguments more information about the error - */ - public void addError(String message, int line, int column, String uri, String key, Object[] messageArguments) - { - if(addMessage(message, line, column, uri, SEV_ERROR, key, messageArguments)) - { - valid = false; - } - } - - /** - * Add a warning message. - * - * @param message The string message of the warning. - * @param line The line location of the warning. - * @param column The column location of the warning. - * @param uri The URI of the file that contains the warning. - */ - public void addWarning(String message, int line, int column, String uri) - { - addWarning(message, line, column, uri, null, null); - } - - /** - * - * Add an error message. - * - * @param message The message to add. - * @param line The line location of the message. - * @param column The column location of the message. - * @param uri The URI of the file that contains the message. - * @param key The key for the message. - * @param messageArguments more information about the error - */ - public void addWarning(String message, int line, int column, String uri, String key, Object[] messageArguments) - { - addMessage(message, line, column, uri, SEV_WARNING, key, messageArguments); - } - - /** - * Add a message to the list. Return true if successful, false otherwise. - * - * @param message The message to add to the list. - * @param line The line location of the message. - * @param column The column location of the message. - * @param uri The URI of the file that contains the message. - * @param severity The severity of the message. - * @param key the Xerces error key for this error - * @param messageArguments more information on the error - * @return True if the message was successfully added, false otherwise. - */ - private boolean addMessage(String message, int line, int column, String uri, int severity, String key, Object[] messageArguments) - { - boolean successfullyAdded = false; - // If the message if null there is nothing to add. - if(message == null) - { - return successfullyAdded; - } - String errorURI = normalize(uri); - URL errorURL = null; - if (errorURI != null) - { - try - { - errorURL = new URL(errorURI); - } catch (MalformedURLException e) - { - } - //errorURI = normalizeURI(errorURI); - } - //boolean doDialog = true; - if (errorURL != null) - { - successfullyAdded = true; - // Add to the appropriate list if nested error support is off or - // this message is for the current file. - if (!WRAPPER_ERROR_SUPPORT_ENABLED || validating_file_url.sameFile(errorURL)) - { - - ValidationMessage valmes = new ValidationMessage(message, line, - column, validating_file_uri, key, messageArguments); - if (severity == SEV_ERROR) - { - valmes.setSeverity(ValidationMessage.SEV_NORMAL); - } else if (severity == SEV_WARNING) - { - valmes.setSeverity(ValidationMessage.SEV_LOW); - } - messages.add(valmes); - } - // If nested error support is enabled create a nested error. - else if (WRAPPER_ERROR_SUPPORT_ENABLED) - { - String nesteduri = errorURL.toExternalForm(); - ValidationMessage nestedmess = new ValidationMessage(message, line, - column, nesteduri, key, messageArguments); - if(severity == SEV_WARNING) - { - nestedmess.setSeverity(ValidationMessage.SEV_LOW); - } - else - { - nestedmess.setSeverity(ValidationMessage.SEV_NORMAL); - } - - ValidationMessage container = (ValidationMessage) nestedMessages.get(nesteduri); - if(container == null) - { - container = new ValidationMessage(NLS.bind(XMLValidationMessages._UI_REF_FILE_ERROR_MESSAGE, new Object [] { nesteduri }), 1, 0, nesteduri); - - // Initially set the nested error to a warning. This will automatically be changed - // to an error if a nested message has a severity of error. - container.setSeverity(ValidationMessage.SEV_LOW); - nestedMessages.put(nesteduri, container); - messages.add(container); - } - container.addNestedMessage(nestedmess); - } - } - return successfullyAdded; - } - - - /** - * Add a nested message to the validation information. - * - * @param message The string message of the validation message. - * @param line The line location of the validation message. - * @param column The column location of the validation message. - * @param uri The URI of the validation message. - * @param severity The severity of the validation message. - */ -// public void addNestedMessage(String message, int line, int column, String uri, int severity) -// { -// ValidationMessage nestedmess = new ValidationMessage(message, line, column, uri); -// if(severity == SEV_WARNING) -// { -// nestedmess.setSeverity(ValidationMessage.SEV_LOW); -// } -// else -// { -// nestedmess.setSeverity(ValidationMessage.SEV_NORMAL); -// } -// ValidationMessage container = (ValidationMessage)nestedMessages.get(uri); -// if(container == null) -// { -// container = new ValidationMessage(XMLCoreValidationPlugin.getResourceString(_UI_REF_FILE_ERROR_MESSAGE, uri), 1, 0, validating_file_uri); -// // Initially set the nested error to a warning. This will automatically be changed -// // to an error if a nested message has a severity of error. -// container.setSeverity(ValidationMessage.SEV_LOW); -// nestedMessages.put(uri, container); -// messages.add(container); -// } -// container.addNestedMessage(nestedmess); -// } - - /** - * @see org.eclipse.wsdl.validate.ValidationReport#getValidationMessages() - */ - public ValidationMessage[] getValidationMessages() - { - return (ValidationMessage[])messages.toArray(new ValidationMessage[messages.size()]); - } - - public HashMap getNestedMessages() - { - return nestedMessages; - } - - /** - * Put the URI in a standard format. - * - * @param uri The URI to put into a standard format. - * @return The standard format of the URI. - */ - private String normalize(String uri) - { -// if(uri.startsWith("platform:")) -// { -// try -// { -// uri = Platform.resolve(new URL(uri)).toString(); -// } -// catch(Exception e) -// { -// } -// } - uri = uri.replaceAll("%20"," "); //$NON-NLS-1$ //$NON-NLS-2$ - uri = uri.replaceAll("%5E", "^"); //$NON-NLS-1$ //$NON-NLS-2$ - uri = uri.replace('\\','/'); - - return uri; - } - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/ValidationMessage.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/ValidationMessage.java deleted file mode 100644 index d364d242d6..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/ValidationMessage.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation.core; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -/** - * A class for holding validation message information. Holds the message and the - * message location. - */ -public class ValidationMessage -{ - public static final QualifiedName ERROR_MESSAGE_MAP_QUALIFIED_NAME = new QualifiedName("org.eclipse.wst.xml.validation", "errorMessageMap"); //$NON-NLS-1$ //$NON-NLS-2$ - protected String message; - protected int lineNumber; - protected int columnNumber; - protected String uri; - protected List nestedErrors; - protected String key; - protected Object[] messageArguments; - protected int startOffset; - protected int severity = IMessage.NORMAL_SEVERITY; - public static int SEV_HIGH = IMessage.HIGH_SEVERITY; - public static int SEV_NORMAL = IMessage.NORMAL_SEVERITY; - public static int SEV_LOW = IMessage.LOW_SEVERITY; - - /** - * Constructor. - * - * @param message The message for the validation message. - * @param lineNumber The line location of the message. - * @param columnNumber The column location of the message. - */ - public ValidationMessage(String message, int lineNumber, int columnNumber) - { - this(message, lineNumber, columnNumber, null); - } - - /** - * Constructor. - * - * @param message The message for the validation message. - * @param lineNumber The line location of the message. - * @param columnNumber The column location of the message. - * @param uri The uri of the file the message is for. - */ - public ValidationMessage(String message, int lineNumber, int columnNumber, String uri) - { - this(message, lineNumber, columnNumber, uri, null, null); - } - - /** - * Constructor. - * - * @param message The message for the validation message. - * @param lineNumber The line location of the message. - * @param columnNumber The column location of the message. - * @param uri The uri of the file the message is for. - * @param key a unique string representing the error - * @param messageArguments the arguments Xerces uses to create the message - */ - public ValidationMessage(String message, int lineNumber, int columnNumber, String uri, String key, Object[] messageArguments) - { - this.message = message; - this.lineNumber = lineNumber; - this.columnNumber = columnNumber; - this.uri = uri; - this.key = key; - this.messageArguments = messageArguments; - this.startOffset = 0; - } - - - /** - * Get the message for this valiation message. - * - * @return The message for this validation message. - */ - public String getMessage() - { - return message; - } - - /** - * Get the column location. - * - * @return The column number. - */ - public int getColumnNumber() - { - return columnNumber; - } - - /** - * Get the line location. - * - * @return The line number. - */ - public int getLineNumber() - { - return lineNumber; - } - - /** - * Get the uri for the file that contains the message. - * - * @return The uri of the file that contains the message. - */ - public String getUri() - { - return uri; - } - - /** - * Add a nested validation message to this validation message. - * - * @param validationMessage The validation message to add as a nested message. - */ - public void addNestedMessage(ValidationMessage validationMessage) - { - if (nestedErrors == null) - { - nestedErrors = new ArrayList(); - } - nestedErrors.add(validationMessage); - int validaitonmessageSeverity = validationMessage.getSeverity(); - if(validaitonmessageSeverity == SEV_NORMAL || validaitonmessageSeverity == SEV_HIGH) - { - setSeverity(SEV_NORMAL); - } - } - - /** - * Get the list of nested validation messages. - * - * @return The list of nested validation messages. - */ - public List getNestedMessages() - { - return nestedErrors != null ? nestedErrors : Collections.EMPTY_LIST; - } - - /** - * Get the severity of the defect. - * - * @return The severity of the defect. - */ - public int getSeverity() - { - return severity; - } - - /** - * Set the severity of the message. - * - * @param sev The severity to set. - */ - public void setSeverity(int sev) - { - severity = sev; - } - - public void setStartOffset(int offset) - { - this.startOffset = offset; - } - - /** - * @return Returns the key. - */ - public String getKey() - { - return key; - } - - public Object[] getMessageArguments() - { - return this.messageArguments; - } - - - public void setMessage(String message) - { - this.message = message; - } - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/ValidationReport.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/ValidationReport.java deleted file mode 100644 index c80e023d49..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/ValidationReport.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation.core; - -import java.util.HashMap; - -/** - * An interface for a validation report. - * - * @author Lawrence Mandel, IBM - */ -public interface ValidationReport -{ - /** - * Returns the URI for the file the report refers to. - * - * @return The URI for the file the report refers to. - */ - public String getFileURI(); - - /** - * Returns whether the file is valid. The file may have warnings associated with it. - * - * @return True if the file is valid, false otherwise. - */ - public boolean isValid(); - - /** - * Returns an array of validation messages. - * - * @return An array of validation messages. - */ - public ValidationMessage[] getValidationMessages(); - - public HashMap getNestedMessages(); - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/CommandLineLogger.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/CommandLineLogger.java deleted file mode 100644 index 0b499207f5..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/CommandLineLogger.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation.core.logging; - -/** - * A logger that will print log info to System.out. - * - * @author Lawrence Mandel, IBM - */ -public class CommandLineLogger implements ILogger -{ - public void logError(String error, Throwable exception) - { - System.out.println(error); - System.out.println(exception.toString()); - } - - public void logWarning(String warning, Throwable exception) - { - System.out.println(warning); - System.out.println(exception.toString()); - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/EclipseLogger.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/EclipseLogger.java deleted file mode 100644 index e346947e50..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/EclipseLogger.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation.core.logging; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; - - -/** - * A logger that will log to the log file in the eclipse metadata directory. - */ -public class EclipseLogger implements ILogger -{ - - public void logError(String error, Throwable exception) - { - XMLCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR, XMLCorePlugin.getDefault().getBundle().getSymbolicName(), IStatus.ERROR, error, exception)); - } - - public void logWarning(String warning, Throwable exception) - { - XMLCorePlugin.getDefault().getLog().log(new Status(IStatus.WARNING, XMLCorePlugin.getDefault().getBundle().getSymbolicName(), IStatus.WARNING, warning, exception)); - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/ILogger.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/ILogger.java deleted file mode 100644 index 22b8335bfa..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/ILogger.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation.core.logging; - -/** - * The interface for a standard logger. Allows for logging errors and warnings. - * - * @author Lawrence Mandel, IBM - */ -public interface ILogger -{ - /** - * Log an error message. - * - * @param error The error message to log. - * @param exception The exception to log. - */ - public void logError(String error, Throwable exception); - - /** - * Log a warning message. - * - * @param warning The warning message to log. - * @param exception The exception to log. - */ - public void logWarning(String warning, Throwable exception); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/LoggerFactory.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/LoggerFactory.java deleted file mode 100644 index 9a49c5de46..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/logging/LoggerFactory.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation.core.logging; - -/** - * The logger factory allows for simple use of whatever logging mechanism is in - * place. The tool can specify a custom logging class and can request the - * logger from this class. - * - * @author Lawrence Mandel, IBM - */ -public class LoggerFactory -{ - private static ILogger logger = null; - private static ClassLoader classloader = null; - private static String loggerClass = null; - private static final String commandlinelogger = "org.eclipse.wst.xml.validation.internal.core.logging.CommandLineLogger"; //$NON-NLS-1$ - private static final String eclipselogger = "org.eclipse.wst.xml.validation.internal.core.logging.EclipseLogger"; //$NON-NLS-1$ - private static String defaultlogger = commandlinelogger; - - /** - * Get the one and only instance of the logger. - * - * @return The one and only instance of the logger. - */ - public static ILogger getLoggerInstance() - { - if(logger == null) - { - if(loggerClass != null) - { - if(classloader != null) - { - try - { - Class lc = classloader.loadClass(loggerClass); - logger = (ILogger) lc.newInstance(); - } - catch (Exception e) - { - } - } - if(logger == null) - { - try - { - Class lc = LoggerFactory.class.getClassLoader().loadClass(loggerClass); - logger = (ILogger) lc.newInstance(); - } - catch (Exception e) - { - } - } - } - if(logger == null) - { - try - { - Class lc = LoggerFactory.class.getClassLoader().loadClass(defaultlogger); - logger = (ILogger) lc.newInstance(); - } - catch (Exception e) - { - } - } - } - return logger; - } - - /** - * Specify the logger implementation to be used. - * - * @param classname - * The name of the logger class. - * @param loggerclassloader - * The classloader to use to load the logger. If null, the default - * classloader will be used. - */ - public static void specifyLogger(String classname, ClassLoader loggerclassloader) - { - loggerClass = classname; - classloader = loggerclassloader; - } - - /** - * Set the default logger to the eclipse logger. - */ - public static void useEclipseLogger() - { - defaultlogger = eclipselogger; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/ErrorCustomizationPluginRegistryReader.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/ErrorCustomizationPluginRegistryReader.java deleted file mode 100644 index 44a6481ad2..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/ErrorCustomizationPluginRegistryReader.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation.eclipse; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.wst.xml.core.internal.validation.errorcustomization.ErrorCustomizationRegistry; -import org.eclipse.wst.xml.core.internal.validation.errorcustomization.ErrorMessageCustomizerDelegate; -import org.osgi.framework.Bundle; -/** - * This class reads the plug-in manifests and registers each extension - * error customizer with the ErrorCustomizationRegistry. - */ -public class ErrorCustomizationPluginRegistryReader { - - protected static final String PLUGIN_ID = "org.eclipse.wst.xml.core"; //$NON-NLS-1$ - protected static final String ATT_CLASS = "class"; //$NON-NLS-1$ - protected static final String ATT_NAMESPACE = "namespace"; //$NON-NLS-1$ - protected static final String EXTENSION_POINT_ID = "errorCustomizer"; //$NON-NLS-1$ - protected static final String tagName = EXTENSION_POINT_ID; - - /** - * Read from plugin registry for the errorcustomizer extension. - */ - public void readRegistry() - { - IExtensionRegistry pluginRegistry = Platform.getExtensionRegistry(); - IExtensionPoint point = pluginRegistry.getExtensionPoint(PLUGIN_ID, EXTENSION_POINT_ID); - if (point != null) - { - IConfigurationElement[] elements = point.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) - { - readElement(elements[i]); - } - } - } - - /** - * readElement() - parse and deal with an extension like: - * - * <extension point="org.eclipse.wst.xml.core.errorCustomizer" - * id="specificErrorCustomizer" - * name="Specific Error Customizer"> - * <errorCustomizer - * namespace="http://specificnamespace" - * class="org.eclipse.wst.xml.core.MySpecificErrorCustomizer/> - * </extension> - */ - protected void readElement(IConfigurationElement element) - { - if (element.getName().equals(tagName)) - { - String errorCustomizerClass = element.getAttribute(ATT_CLASS); - String namespace = element.getAttribute(ATT_NAMESPACE); - - if (errorCustomizerClass != null) - { - try - { - Bundle pluginBundle = Platform.getBundle(element.getDeclaringExtension().getContributor().getName()); - ErrorMessageCustomizerDelegate delegate = new ErrorMessageCustomizerDelegate(pluginBundle, errorCustomizerClass); - ErrorCustomizationRegistry.getInstance().addErrorMessageCustomizer(namespace, delegate); - } - catch (Exception e) - { - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/Validator.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/Validator.java deleted file mode 100644 index 6f21d01b5e..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/Validator.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation.eclipse; - -import java.io.InputStream; - -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; -import org.eclipse.wst.xml.core.internal.validation.XMLValidationConfiguration; -import org.eclipse.wst.xml.core.internal.validation.XMLValidationMessages; -import org.eclipse.wst.xml.core.internal.validation.XMLValidationReport; -import org.eclipse.wst.xml.core.internal.validation.core.AbstractNestedValidator; -import org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext; -import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; -import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport; - -public class Validator extends AbstractNestedValidator -{ - protected boolean warnNoGrammar = false; - - /** - * Set any preferences for XML validation. - * - * @see org.eclipse.wst.xml.core.internal.validation.core.AbstractNestedValidator#setupValidation(org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext) - */ - protected void setupValidation(NestedValidatorContext context) - { - super.setupValidation(context); - warnNoGrammar = XMLCorePlugin.getDefault().getPluginPreferences().getBoolean(XMLCorePreferenceNames.WARN_NO_GRAMMAR); - } - -/* (non-Javadoc) - * @see org.eclipse.wst.xml.core.internal.validation.core.AbstractNestedValidator#getValidatorName() - */ - protected String getValidatorName() - { - return XMLValidationMessages.Message_XML_validation_message_ui; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.xml.core.internal.validation.core.AbstractNestedValidator#validate(java.lang.String, java.io.InputStream, org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext) - */ - public ValidationReport validate(String uri, InputStream inputstream, NestedValidatorContext context) - { - XMLValidator validator = XMLValidator.getInstance(); - - XMLValidationConfiguration configuration = new XMLValidationConfiguration(); - try - { - configuration.setFeature(XMLValidationConfiguration.WARN_NO_GRAMMAR, warnNoGrammar); - } - catch(Exception e) - { - // TODO: Unable to set the preference. Log this problem. - } - - XMLValidationReport valreport = null; - if (inputstream != null) - { - valreport = validator.validate(uri, inputstream, configuration); - } - else - { - valreport = validator.validate(uri, null, configuration); - } - - return valreport; - } - - /** - * Store additional information in the message parameters. For XML validation there - * are three additional pieces of information to store: - * param[0] = the column number of the error - * param[1] = the 'squiggle selection strategy' for which DOM part to squiggle - * param[2] = the name or value of what is to be squiggled - * - * @see org.eclipse.wst.xml.core.internal.validation.core.AbstractNestedValidator#addInfoToMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage, org.eclipse.wst.validation.internal.provisional.core.IMessage) - */ - protected void addInfoToMessage(ValidationMessage validationMessage, IMessage message) - { - String key = validationMessage.getKey(); - if(key != null) - { - XMLMessageInfoHelper messageInfoHelper = new XMLMessageInfoHelper(); - String[] messageInfo = messageInfoHelper.createMessageInfo(key, validationMessage.getMessageArguments()); - - message.setAttribute(COLUMN_NUMBER_ATTRIBUTE, new Integer(validationMessage.getColumnNumber())); - message.setAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE, messageInfo[0]); - message.setAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE, messageInfo[1]); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLMessageInfoHelper.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLMessageInfoHelper.java deleted file mode 100644 index 6e2fcf4684..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLMessageInfoHelper.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation.eclipse; - -/** - * The message info helper determines the selection strategy for elements - * in a SSE editor. - * - */ -public class XMLMessageInfoHelper -{ - public XMLMessageInfoHelper() - { - super(); - } - - /** - * Returns an array containing information about what should be underlined with the red "squiggles" - * using the errorKey, and the messageArguments. - * <br>Position 0 of the array returned contains the selection Strategy, or what DOM Element to underline. - * For example "ATTRIBUTE_NAME" - * <br>Position 1 contains the name or value to squiggle. - * <p>For example, if we wanted to squiggle the attribute name of an attribute name - * foo this method would return {"ATTRIBUTE_NAME", "foo"} - * </p> - * @param errorKey - * The error key given by the Xerces parser. - * @param messageArguments - * The arguments used by Xerces to "fill in the blanks" of their messages. - * @return - * An array containing the squiggle information. - * @see org.eclipse.wst.xml.ui.internal.validation.DelegatingSourceValidator - * - */ - public String[] createMessageInfo(String errorKey, Object[] messageArguments) - { - String selectionStrategy = null; - String nameOrValue = null; - - if(errorKey != null) - { - if (errorKey.equals("cvc-complex-type.2.4.a") || errorKey.equals("cvc-complex-type.2.4.d") || errorKey.equals("cvc-complex-type.2.4.b") || errorKey.equals("MSG_CONTENT_INVALID") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - | errorKey.equals("MSG_CONTENT_INCOMPLETE") || errorKey.equals("MSG_REQUIRED_ATTRIBUTE_NOT_SPECIFIED") || errorKey.equals("cvc-complex-type.4")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - { - selectionStrategy = "START_TAG"; //$NON-NLS-1$ - } - else if (errorKey.equals("cvc-type.3.1.3")) //$NON-NLS-1$ - { - selectionStrategy = "TEXT"; //$NON-NLS-1$ - } - else if (errorKey.equals("cvc-complex-type.2.3")) //$NON-NLS-1$ - { - selectionStrategy = "FIRST_NON_WHITESPACE_TEXT"; //$NON-NLS-1$ - } - else if (errorKey.equals("cvc-type.3.1.1")) //$NON-NLS-1$ - { - selectionStrategy = "ALL_ATTRIBUTES"; //$NON-NLS-1$ - } - else if (errorKey.equals("cvc-complex-type.3.2.2") || errorKey.equals("MSG_ATTRIBUTE_NOT_DECLARED")) //$NON-NLS-1$ //$NON-NLS-2$ - { - selectionStrategy = "ATTRIBUTE_NAME"; //$NON-NLS-1$ - //in this case we need nameOrValue to be the name of the attribute to underline - nameOrValue = (String)messageArguments[1]; - } - else if (errorKey.equals("cvc-attribute.3") || errorKey.equals("MSG_ATTRIBUTE_VALUE_NOT_IN_LIST") || errorKey.equals("cvc-complex-type.3.1")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - { - selectionStrategy = "ATTRIBUTE_VALUE"; //$NON-NLS-1$ - //in this case we need nameOrValue to be the name of the Attribute - if (errorKey.equals("cvc-attribute.3") || errorKey.equals("cvc-complex-type.3.1")) //$NON-NLS-1$ //$NON-NLS-2$ - { - nameOrValue = (String)messageArguments[1]; - } - else if (errorKey.equals("MSG_ATTRIBUTE_VALUE_NOT_IN_LIST")) //$NON-NLS-1$ - { - nameOrValue = (String)messageArguments[0]; - } - } - else if (errorKey.equals("cvc-elt.4.2")) //$NON-NLS-1$ - { - selectionStrategy="VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE"; //$NON-NLS-1$ - //in this case we need nameOrValue to be the value of the attribute we want to unerline - nameOrValue = (String)messageArguments[1]; - } - else if (errorKey.equals("EntityNotDeclared")) //$NON-NLS-1$ - { - selectionStrategy="TEXT_ENTITY_REFERENCE"; //$NON-NLS-1$ - nameOrValue = (String)messageArguments[0]; - } - else if (errorKey.equals("ElementUnterminated")) //$NON-NLS-1$ - { - selectionStrategy = "ENTIRE_ELEMENT"; //$NON-NLS-1$ - } - } - String messageInfo[] = new String[2]; - messageInfo[0] = selectionStrategy != null? selectionStrategy: ""; //$NON-NLS-1$ - messageInfo[1] = nameOrValue; - return messageInfo; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLValidator.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLValidator.java deleted file mode 100644 index fc9712820b..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLValidator.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.xml.core.internal.validation.eclipse; - -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; - -/** - * An XML validator specific to Eclipse. This validator will wrap the internal - * XML validator and provide automatic URI resolution support. This class also - * reads from the plug-in registry and registers all error customizers with the - * registry. - */ -public class XMLValidator extends org.eclipse.wst.xml.core.internal.validation.XMLValidator -{ - private static XMLValidator instance = null; - - /** - * Return the one and only instance of the XML validator. The validator - * can be reused and cannot be customized so there should only be one instance of it. - * - * @return The one and only instance of the XML validator. - */ - public static XMLValidator getInstance() - { - if(instance == null) - { - instance = new XMLValidator(); - } - return instance; - } - /** - * Constructor. Create the XML validator, set the URI resolver and - * get the extension error customizers from the registry. - */ - protected XMLValidator() - { - setURIResolver(URIResolverPlugin.createResolver()); - new ErrorCustomizationPluginRegistryReader().readRegistry(); - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ElementInformation.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ElementInformation.java deleted file mode 100644 index 649c99e553..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ElementInformation.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation.errorcustomization; - -import java.util.ArrayList; -import java.util.List; - -/** - * A simple class to store information about an XML element. - */ -public class ElementInformation -{ - protected String localName; - protected String namespace; - protected List children = new ArrayList(); - - /** - * Constructor. - * - * @param uri - * The namespace URI of the element. - * @param localName - * The local name of the element. - */ - public ElementInformation(String uri, String localName) - { - this.localName = localName; - this.namespace = uri; - } - - /** - * Get the namespace of this element. - * - * @return - * The namespace of this element. - */ - public String getNamespace() - { - return namespace; - } - - /** - * Get the local name of this element. - * - * @return - * The local name of this element. - */ - public String getLocalname() - { - return localName; - } - - /** - * Get the list of children of this element. The list contains - * ElementInformation objects representing the children of this element. - * - * @return - * The list of children of this element. - */ - public List getChildren() - { - return children; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ErrorCustomizationManager.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ErrorCustomizationManager.java deleted file mode 100644 index 745acc045a..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ErrorCustomizationManager.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation.errorcustomization; - -import java.util.Stack; - -import org.eclipse.wst.xml.core.internal.validation.core.ValidationInfo; -import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; - -/** - * This class tracks the context of the parsed document to help identify error - * conditions - */ -public class ErrorCustomizationManager -{ - protected Stack elementInformationStack = new Stack(); - protected ErrorMessageInformation messageForConsideration; - - /** - * This method should be called in the start element method of the XML validator's - * content handler. - * - * @param uri - * The namespace of the element. - * @param localName - * The local name of the element. - */ - public void startElement(String uri, String localName) - { - ElementInformation elementInformation = new ElementInformation(uri, localName); - if (elementInformationStack.size() > 0) - { - ElementInformation parent = (ElementInformation) elementInformationStack.peek(); - parent.children.add(elementInformation); - } - elementInformationStack.push(elementInformation); - } - - /** - * This method should be called in the end element method of the XML validator's - * content handler. - * - * @param uri - * The namespace of the element. - * @param localName - * The local name of the element. - */ - public void endElement(String uri, String localName) - { - if (elementInformationStack.size() > 0) - { - ElementInformation elementInformation = (ElementInformation)elementInformationStack.pop(); - if (messageForConsideration != null) - { - IErrorMessageCustomizer[] customizers = ErrorCustomizationRegistry.getInstance().getCustomizers(elementInformation.getNamespace()); - int numCustomizers = customizers.length; - for(int i = 0; i < numCustomizers; i++) - { - String message = customizers[i].customizeMessage(elementInformation, messageForConsideration.key, messageForConsideration.arguments); - if(message != null) - { - messageForConsideration.message.setMessage(message); - break; - } - } - } - } - } - - /** - * Consider the reported error for customization. - * - * @param valInfo - * The current ValidationInfo object containing validation specific information. - * @param key - * The key related to the message. - * @param arguments - * Any message arguments. - */ - public void considerReportedError(ValidationInfo valInfo, String key, Object[] arguments) - { - messageForConsideration = null; - ValidationMessage[] messages = valInfo.getValidationMessages(); - if (messages.length > 0) - { - messageForConsideration = new ErrorMessageInformation(); - messageForConsideration.key = key; - messageForConsideration.arguments = arguments; - messageForConsideration.message = messages[messages.length - 1]; - } - } - - /** - * A simple class to hold error message information. - */ - public class ErrorMessageInformation - { - public String key = null; - public Object[] arguments = null; - public ValidationMessage message = null; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ErrorCustomizationRegistry.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ErrorCustomizationRegistry.java deleted file mode 100644 index 20948794fa..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ErrorCustomizationRegistry.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation.errorcustomization; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * The error customization regsitry manages all registered - * IErrorMessageCustomizers by namespace. - */ -public class ErrorCustomizationRegistry -{ - protected static ErrorCustomizationRegistry registry = null; - protected Map customizers = new HashMap(); - - /** - * Restricted constructor in keeping with the singleton pattern. - */ - protected ErrorCustomizationRegistry() - { - } - - /** - * Get the one and only instance of the registry. - * - * @return - * The one and only instance of the registry. - */ - public static ErrorCustomizationRegistry getInstance() - { - if(registry == null) - { - registry = new ErrorCustomizationRegistry(); - } - return registry; - } - - /** - * Add a customizer to the registry. - * - * @param namespace - * The namespace the customizer will act on. - * @param customizer - * The error customizer to register. - */ - public void addErrorMessageCustomizer(String namespace, IErrorMessageCustomizer customizer) - { - // To register a customizer for the no namespace use an empty string. - if(namespace == null) - { - namespace = ""; //$NON-NLS-1$ - } - List customizersForNS = (List)customizers.get(namespace); - if(customizersForNS == null) - { - customizersForNS = new ArrayList(); - customizers.put(namespace, customizersForNS); - } - if(customizer != null) - { - customizersForNS.add(customizer); - } - } - - /** - * Get the error customizers for a given namespace. - * - * @param namespace - * The namespace for which to retrieve the customizers. - * @return - * An array of customizers registered for this namespace. - */ - public IErrorMessageCustomizer[] getCustomizers(String namespace) - { - if(namespace == null) - { - namespace = ""; //$NON-NLS-1$ - } - List customizersForNS = (List)customizers.get(namespace); - if(customizersForNS == null) - { - customizersForNS = new ArrayList(); - } - return (IErrorMessageCustomizer[])customizersForNS.toArray(new IErrorMessageCustomizer[customizersForNS.size()]); - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ErrorMessageCustomizerDelegate.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ErrorMessageCustomizerDelegate.java deleted file mode 100644 index 07147c1455..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/ErrorMessageCustomizerDelegate.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation.errorcustomization; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.osgi.framework.Bundle; - -/** - * An error message customizer delegate is used to allow for - * lazy loading of error customizers. - * - */ -public class ErrorMessageCustomizerDelegate implements IErrorMessageCustomizer -{ - protected Bundle bundle = null; - protected String classname = null; - protected IErrorMessageCustomizer customizer = null; - - public ErrorMessageCustomizerDelegate(Bundle bundle, String classname) - { - this.bundle = bundle; - this.classname = classname; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.xml.core.internal.validation.errorcustomization.IErrorMessageCustomizer#customizeMessage(org.eclipse.wst.xml.core.internal.validation.errorcustomization.ElementInformation, java.lang.String, java.lang.Object[]) - */ - public String customizeMessage(ElementInformation elementInfo, String errorKey, Object[] arguments) - { - if(customizer == null) - { - loadCustomizer(); - } - if(customizer == null) - { - return null; - } - return customizer.customizeMessage(elementInfo, errorKey, arguments); - } - - /** - * Load the customizer class. - */ - protected void loadCustomizer() - { - try - { - Class customizerClass = bundle.loadClass(classname); - customizer = (IErrorMessageCustomizer)customizerClass.newInstance(); - } - catch(Exception e) - { - XMLCorePlugin.getDefault().getLog().log( - new Status(IStatus.WARNING, - XMLCorePlugin.getDefault().getBundle().getSymbolicName(), - IStatus.OK, - "The XML validator error customizer was unable to load class " + classname, e)); //$NON-NLS-1$ - } - } - - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/IErrorMessageCustomizer.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/IErrorMessageCustomizer.java deleted file mode 100644 index ac6d1e0d89..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/errorcustomization/IErrorMessageCustomizer.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.validation.errorcustomization; - -/** - * An error message customizer will be called by the XML validator to customize - * XML validation errors for a given namespace. The customizer can be used to - * create clearer errors for specific application domains. - */ -public interface IErrorMessageCustomizer -{ - /** - * Return a customized error message for the given element. Null should be returned - * if the message should not be customized. - * - * @param elementInformation - * The information about the element for which to customize the error. - * @param errorKey - * The key for the error for which to replace the message. - * @param arguments - * Arguments related the the error message. - * @return - * A customized error message or null if this customizer will not customize the message. - */ - public String customizeMessage(ElementInformation elementInfo, String errorKey, Object[] arguments); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/xmlvalidation.properties b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/xmlvalidation.properties deleted file mode 100644 index c0f2111cb7..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/xmlvalidation.properties +++ /dev/null @@ -1,35 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2005 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -!-- Constants for strings - -# validation strings -Message_XML_validation_message_ui=XML Validator validating {0} - -! Usage: -! {0} replaced with the host name -! -_UI_PROBLEMS_VALIDATING_UNKNOWN_HOST = The file cannot be validated as the host "{0}" is currently unreachable. - -! Usage: -! {0} replaced with the file name -! -_UI_PROBLEMS_VALIDATING_FILE_NOT_FOUND = The file cannot be validated as the XML Schema "{0}" that is specified as describing the syntax of the file cannot be located. - -_UI_PROBLEMS_CONNECTION_REFUSED = The file cannot be validated as there was a connection problem. - -! -! Referenced File Dialog Related Message -! -_UI_REF_FILE_ERROR_MESSAGE = Referenced file contains errors ({0}). For more information, right click on the message and select "Show Details..." - -# Warning when no grammar is located. -_WARN_NO_GRAMMAR = No grammar constraints (DTD or XML schema) detected for the document. -
\ No newline at end of file |