COSMOS ${releaseVersion} resource-modeling Project
Internal API Specification

org.eclipse.cosmos.rm.validation.internal.common
Class SMLValidatorUtil

java.lang.Object
  extended by org.eclipse.cosmos.rm.validation.internal.common.SMLValidatorUtil

public class SMLValidatorUtil
extends java.lang.Object

Provides common utility method used by multiple classes under different pacakges


Nested Class Summary
static class SMLValidatorUtil.RemoteRetrievalException
          Thrown when there is an error while retrieving a remote document
 
Field Summary
static javax.xml.xpath.XPath xpath
          A static XPath instance used to compile XPath expressions
 
Constructor Summary
SMLValidatorUtil()
           
 
Method Summary
static void addAttribute(java.lang.StringBuffer stringBuffer, org.w3c.dom.NamedNodeMap attributes, boolean close, boolean end)
          Adds XML attributes to the string buffer passed in.
static void addElement(java.lang.StringBuffer stringBuffer, int indent, java.lang.String elementName, boolean close, boolean end)
          Adds an XML element to the string buffer passed in.
static void addIndent(java.lang.StringBuffer stringBuffer, int indent)
           
static java.lang.String beginTagFor(java.lang.String elementName)
          Return an XML begin tag for the elementName.
static java.lang.String beginTagFor(java.lang.String namespace, java.lang.String elementName)
          Return an XML begin tag for the namespace and element name.
static boolean checkWorkspaceDirName(java.lang.String dirName)
          Answer whether the destination directory entered is a valid project or folder name.
static boolean checkWorkspaceResourceName(java.lang.String resourceName)
           
static java.lang.String createElementTag(java.lang.String elementName, java.lang.String elementData)
          Return a full XML element with begin and end tags, and data in between.
static java.lang.String createElementTag(java.lang.String namespace, java.lang.String elementName, java.lang.String elementData)
          Return a full XML element with begin and end tags, and data in between.
static javax.xml.parsers.SAXParser createSAXParser(java.lang.Object schemaSource, boolean validating, org.xml.sax.ext.LexicalHandler lexicalHandler, IValidationOutput validationLogger)
          Answer a new SAXParser instance with the specified attributes.
static IValidationMessage createValidationMessage(DocumentDOMBuilder builder, org.w3c.dom.Node node, java.lang.String error)
           
static boolean deleteFileTree(java.io.File root)
          This method attempts to delete the specified root file.
static org.w3c.dom.Document domParseDocument(java.io.InputStream resource)
           
static org.w3c.dom.Document domParseDocument(java.io.InputStream resource, boolean ignoreComments, boolean ignoreWhitespace)
          Uses a DOM parser to parse the XML file passed in
static java.lang.String endTagFor(java.lang.String elementName)
          Return an XML end tag for the elementName.
static java.lang.String endTagFor(java.lang.String namespace, java.lang.String elementName)
          Return an XML end tag for the namespace and element name.
protected static java.lang.Throwable findCause(java.lang.Throwable t)
           
protected static java.lang.String getExceptionStackTrace(java.lang.Throwable t)
           
static int identifyDocumentType(ResourceWrapper resource)
          Returns ISMLConstants.TYPE_DEFINITION if the document type is determined to be definition, ISMLConstants.TYPE_INSTANCE if instance, ISMLConstants.TYPE_SMLIF if SML-IF, and ISMLConstants.TYPE_UNKNOWN if content type is unknown
static int identifyDocumentTypeShowError(org.eclipse.core.resources.IFile file)
           
static boolean isWhitespace(org.w3c.dom.Node node)
           
static void openErrorWithDetail(org.eclipse.swt.widgets.Shell parent, java.lang.String title, java.lang.String message, java.lang.String cause)
           
static void openErrorWithDetail(java.lang.String title, java.lang.String message, java.lang.Throwable t)
           
static void openErrorWithDetail(java.lang.String title, java.lang.String message, java.lang.Throwable t, boolean defaultParent)
           
static java.lang.String removeLineBreaks(java.lang.String str)
          Removes line breaks and any spaces that follow a line break
static java.lang.String retrieveAbsolutePath(java.lang.String path)
           
static org.w3c.dom.Node[] retrieveChildElements(org.w3c.dom.Node node)
          Retrieves and returns the child elements of node (i.e. nodes of type Node.ELEMENT_NODE)
static java.lang.Object retrieveDataStructure(java.lang.String databuilderId)
          A helper method provided to retrieve the data structure for a databuilder with the given id.
static java.util.Map retrieveNestedMap(java.util.Map map, java.lang.String key, boolean create)
           
static org.w3c.dom.Node retrieveRemoteDocument(java.lang.String uri)
          This method is used to retrieve an XML document referenced by a URI.
static void saxParseDocument(java.io.InputStream resource, org.xml.sax.helpers.DefaultHandler contentHandler)
          Parses the document passed in
static void serializeNode(java.lang.StringBuffer buffer, org.w3c.dom.Node node)
          Equivalent to serializeNode(buffer, node, -1, false)
static void serializeNode(java.lang.StringBuffer buffer, org.w3c.dom.Node node, int indent, boolean autoFormat)
          Equivalent to serializeNode(buffer, node, indent, null, null)
static void serializeNode(java.lang.StringBuffer buffer, org.w3c.dom.Node node, int indent, java.lang.String currentIndex, java.util.Map indices, boolean autoFormat)
          Used to serialize a node into string
static java.lang.String stringReplace(java.lang.String originalString, java.lang.String oldSubstring, java.lang.String newSubstring)
          Replace all occurrences of oldString in originalString with newString.
static java.lang.String tagFor(boolean end, java.lang.String namespace, java.lang.String elementName)
          Utility method to return a begin or end tag for the namespace and elementName input.
static java.lang.String tagNameFor(java.lang.String namespace, java.lang.String elementName)
          Return a string that forms a tag name for the namespace and elementName in namespace:elementName format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xpath

public static javax.xml.xpath.XPath xpath
A static XPath instance used to compile XPath expressions

Constructor Detail

SMLValidatorUtil

public SMLValidatorUtil()
Method Detail

retrieveDataStructure

public static java.lang.Object retrieveDataStructure(java.lang.String databuilderId)
A helper method provided to retrieve the data structure for a databuilder with the given id.

Parameters:
id - The data builder id

removeLineBreaks

public static java.lang.String removeLineBreaks(java.lang.String str)
Removes line breaks and any spaces that follow a line break

Parameters:
str - The string
Returns:
str with line break and white spaces that follow line breaks removed.

retrieveNestedMap

public static java.util.Map retrieveNestedMap(java.util.Map map,
                                              java.lang.String key,
                                              boolean create)

retrieveRemoteDocument

public static org.w3c.dom.Node retrieveRemoteDocument(java.lang.String uri)
                                               throws SMLValidatorUtil.RemoteRetrievalException
This method is used to retrieve an XML document referenced by a URI.

Parameters:
uri - The uri where the document resides
Returns:
The root node of the XML document
Throws:
SMLValidatorUtil.RemoteRetrievalException

domParseDocument

public static org.w3c.dom.Document domParseDocument(java.io.InputStream resource,
                                                    boolean ignoreComments,
                                                    boolean ignoreWhitespace)
                                             throws javax.xml.parsers.ParserConfigurationException,
                                                    org.xml.sax.SAXException,
                                                    java.io.IOException
Uses a DOM parser to parse the XML file passed in

Parameters:
resource - The resource to be parsed
Returns:
The document representing the parsed resource
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException

domParseDocument

public static org.w3c.dom.Document domParseDocument(java.io.InputStream resource)
                                             throws javax.xml.parsers.ParserConfigurationException,
                                                    org.xml.sax.SAXException,
                                                    java.io.IOException
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException

saxParseDocument

public static void saxParseDocument(java.io.InputStream resource,
                                    org.xml.sax.helpers.DefaultHandler contentHandler)
                             throws javax.xml.parsers.ParserConfigurationException,
                                    org.xml.sax.SAXException,
                                    java.io.IOException
Parses the document passed in

Parameters:
resource - The resource to read from
contentHandler - The content handler
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException

identifyDocumentType

public static int identifyDocumentType(ResourceWrapper resource)
                                throws java.io.IOException,
                                       org.eclipse.core.runtime.CoreException
Returns ISMLConstants.TYPE_DEFINITION if the document type is determined to be definition, ISMLConstants.TYPE_INSTANCE if instance, ISMLConstants.TYPE_SMLIF if SML-IF, and ISMLConstants.TYPE_UNKNOWN if content type is unknown

Parameters:
resource - The file to be checked
Returns:
The content type of the file passed in
Throws:
org.eclipse.core.runtime.CoreException
java.io.IOException

identifyDocumentTypeShowError

public static int identifyDocumentTypeShowError(org.eclipse.core.resources.IFile file)

addElement

public static void addElement(java.lang.StringBuffer stringBuffer,
                              int indent,
                              java.lang.String elementName,
                              boolean close,
                              boolean end)
Adds an XML element to the string buffer passed in.

Parameters:
stringBuffer - The string buffer that the element will be written to
indent - The number of indents that should be prefixed to the element written
elementName - The element name
close - Indicates whether this element should be closed or not. If set, a forward slash is added before theelement is ended.
end - Indicates if the element should be ended with a closed angle bracket. For example elements requring attributes are not ended.

addAttribute

public static void addAttribute(java.lang.StringBuffer stringBuffer,
                                org.w3c.dom.NamedNodeMap attributes,
                                boolean close,
                                boolean end)
Adds XML attributes to the string buffer passed in. Attributes with a null value will not be written. Pre-condition:

Parameters:
stringBuffer - The string buffer that the attributes will be written to
attributes - attributes
close - If set, a forward slash is added after the attributes.
end - If set, a closed angle bracket is added after the attributes

addIndent

public static void addIndent(java.lang.StringBuffer stringBuffer,
                             int indent)

deleteFileTree

public static boolean deleteFileTree(java.io.File root)
This method attempts to delete the specified root file. If root is a directory with children, this method attempts to first recursively delete all children of root. If this method returns true, then root has been deleted. If this method returns false, root has not been deleted; however, if root is a directory, it is possible that some of its children were successfully deleted.

Parameters:
root -
Returns:
true if root has been deleted, false otherwise.

retrieveChildElements

public static org.w3c.dom.Node[] retrieveChildElements(org.w3c.dom.Node node)
Retrieves and returns the child elements of node (i.e. nodes of type Node.ELEMENT_NODE)

Parameters:
node - The node
Returns:
Returns the child elements of node

tagNameFor

public static java.lang.String tagNameFor(java.lang.String namespace,
                                          java.lang.String elementName)
Return a string that forms a tag name for the namespace and elementName in namespace:elementName format.

Parameters:
namespace -
elementName -
Returns:

beginTagFor

public static java.lang.String beginTagFor(java.lang.String elementName)
Return an XML begin tag for the elementName. For example, with an argument of "foo", "" will be returned.

Parameters:
elementName -
Returns:

beginTagFor

public static java.lang.String beginTagFor(java.lang.String namespace,
                                           java.lang.String elementName)
Return an XML begin tag for the namespace and element name. For example, with a namespace of "foo" and an element name of "bar", "" will be returned.

Parameters:
namespace -
elementName -
Returns:

endTagFor

public static java.lang.String endTagFor(java.lang.String elementName)
Return an XML end tag for the elementName. For example, with an argument of "foo", "" will be returned.

Parameters:
elementName -
Returns:

endTagFor

public static java.lang.String endTagFor(java.lang.String namespace,
                                         java.lang.String elementName)
Return an XML end tag for the namespace and element name. For example, with a namespace of "foo" and an element name of "bar", "" will be returned.

Parameters:
namespace -
elementName -
Returns:

tagFor

public static java.lang.String tagFor(boolean end,
                                      java.lang.String namespace,
                                      java.lang.String elementName)
Utility method to return a begin or end tag for the namespace and elementName input.

Parameters:
end -
namespace -
elementName -
Returns:

createElementTag

public static java.lang.String createElementTag(java.lang.String elementName,
                                                java.lang.String elementData)
Return a full XML element with begin and end tags, and data in between. With an elementName of "foo" and elementData of "bar", the String "bar" will be returned.

Parameters:
elementName -
elementData -
Returns:

createElementTag

public static java.lang.String createElementTag(java.lang.String namespace,
                                                java.lang.String elementName,
                                                java.lang.String elementData)
Return a full XML element with begin and end tags, and data in between. With a namespace of "sml", an elementName of "foo", and elementData of "bar", the String "bar" will be returned.

Parameters:
namespace -
elementName -
elementData -
Returns:

openErrorWithDetail

public static void openErrorWithDetail(org.eclipse.swt.widgets.Shell parent,
                                       java.lang.String title,
                                       java.lang.String message,
                                       java.lang.String cause)

openErrorWithDetail

public static void openErrorWithDetail(java.lang.String title,
                                       java.lang.String message,
                                       java.lang.Throwable t)

openErrorWithDetail

public static void openErrorWithDetail(java.lang.String title,
                                       java.lang.String message,
                                       java.lang.Throwable t,
                                       boolean defaultParent)

getExceptionStackTrace

protected static java.lang.String getExceptionStackTrace(java.lang.Throwable t)

findCause

protected static java.lang.Throwable findCause(java.lang.Throwable t)

stringReplace

public static java.lang.String stringReplace(java.lang.String originalString,
                                             java.lang.String oldSubstring,
                                             java.lang.String newSubstring)
Replace all occurrences of oldString in originalString with newString. Example: stringReplace("sofa", "of", "ant") evaluates to: "santa" This offers comparable functionality to String.replace(String, String) found in Java 1.5.

Parameters:
originalString - original source string
oldSubstring - substring to be replaced
newSubstring - new text to be substituted for oldSubstring
Returns:
new string with substitutions made
Throws:
java.lang.NullPointerException - if any argument is null

createValidationMessage

public static IValidationMessage createValidationMessage(DocumentDOMBuilder builder,
                                                         org.w3c.dom.Node node,
                                                         java.lang.String error)

serializeNode

public static void serializeNode(java.lang.StringBuffer buffer,
                                 org.w3c.dom.Node node,
                                 int indent,
                                 boolean autoFormat)
Equivalent to serializeNode(buffer, node, indent, null, null)


serializeNode

public static void serializeNode(java.lang.StringBuffer buffer,
                                 org.w3c.dom.Node node)
Equivalent to serializeNode(buffer, node, -1, false)


serializeNode

public static void serializeNode(java.lang.StringBuffer buffer,
                                 org.w3c.dom.Node node,
                                 int indent,
                                 java.lang.String currentIndex,
                                 java.util.Map indices,
                                 boolean autoFormat)
Used to serialize a node into string

Parameters:
buffer - The buffer that the string will be written to
node - The starting node
indent - The starting indent level (use 0 if starting at root)
currentIndex - The current index of the node (use null if not interested to store indices)
indices - The indices map (currentIndex must not be null if indices is used)
autoFormat - Indicates whether the XML content should be formatted

isWhitespace

public static boolean isWhitespace(org.w3c.dom.Node node)

createSAXParser

public static javax.xml.parsers.SAXParser createSAXParser(java.lang.Object schemaSource,
                                                          boolean validating,
                                                          org.xml.sax.ext.LexicalHandler lexicalHandler,
                                                          IValidationOutput validationLogger)
                                                   throws javax.xml.parsers.ParserConfigurationException,
                                                          org.xml.sax.SAXException,
                                                          org.xml.sax.SAXNotRecognizedException,
                                                          org.xml.sax.SAXNotSupportedException
Answer a new SAXParser instance with the specified attributes.

Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException

retrieveAbsolutePath

public static java.lang.String retrieveAbsolutePath(java.lang.String path)

checkWorkspaceDirName

public static boolean checkWorkspaceDirName(java.lang.String dirName)
Answer whether the destination directory entered is a valid project or folder name. The directory does not need to exist.

Parameters:
dirName -
Returns:

checkWorkspaceResourceName

public static boolean checkWorkspaceResourceName(java.lang.String resourceName)

COSMOS ${releaseVersion} resource-modeling Project
Internal API Specification