Author: vitold
Date: 2009-03-23 10:25:23 -0400 (Mon, 23 Mar 2009)
New Revision: 2146
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java
Log:
add validation if 'schema.xsd' file present
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-23
12:59:18 UTC (rev 2145)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-23
14:25:23 UTC (rev 2146)
@@ -307,15 +307,24 @@
String attrPrefix = attribute.getNamespacePrefix();
String attrData = attribute.getStringValue();
+ String urn = "";
for(String attrVal : attrData.split(" "))
{
if(attrVal.startsWith(XmlConstants.URN_PREFIX))
{
- URL namespaceFile = loadNamespaceFile(attrVal);
+ urn = attrVal;
+ URL namespaceFile = loadFile(urn, XmlConstants.NAMESPACE_FILE_NAME);
if(namespaceFile == null)
- throw new DefinitionException("Could not find 'namespace'
file according to specified URN '" + attrVal + "'");
+ throw new DefinitionException("Could not find '" +
XmlConstants.NAMESPACE_FILE_NAME + "' file according to specified URN '"
+ urn + "'");
packagesSet.addAll(parseNamespaceFile(namespaceFile));
}
+ if(attribute.getName().equalsIgnoreCase(XmlConstants.SCHEMA_LOCATION)
&&
+ attrVal.startsWith(XmlConstants.HTTP_PREFIX) &&
urn.trim().length() > 0)
+ {
+ URL schemaFile = loadFile(urn, XmlConstants.SCHEMA_FILE_NAME);
+ if(schemaFile == null)
+ throw new DefinitionException("Could not find '" +
XmlConstants.SCHEMA_FILE_NAME + "' file according to specified URN '" +
urn + "'");
+ }
}
addElementToPackagesMap(packagesMap, attrPrefix, packagesSet);
@@ -334,7 +343,7 @@
{
Set<String> packagesSet = new HashSet<String>();
- URL namespaceFile = loadNamespaceFile(uri);
+ URL namespaceFile = loadFile(uri, XmlConstants.NAMESPACE_FILE_NAME);
if(namespaceFile != null)
{
packagesSet.addAll(parseNamespaceFile(namespaceFile));
@@ -350,12 +359,12 @@
}
}
- private static URL loadNamespaceFile(String urn)
+ private static URL loadFile(String urn, String fileName)
{
char separator = '/';
String packageName = urn.replaceFirst(XmlConstants.URN_PREFIX, "");
String path = packageName.replace('.', separator);
- String filePath = separator + path + separator + XmlConstants.NAMESPACE_FILE_NAME;
+ String filePath = separator + path + separator + fileName;
URL namespaceFile = ParseXmlHelper.class.getResource(filePath);
return namespaceFile;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java 2009-03-23
12:59:18 UTC (rev 2145)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java 2009-03-23
14:25:23 UTC (rev 2146)
@@ -33,6 +33,10 @@
public static final String QUEUE = "Queue";
public static final String URN_PREFIX = "urn:java:";
+
+ public static final String HTTP_PREFIX = "http://";
+
+ public static final String SCHEMA_LOCATION = "schemaLocation";
public static final String NAME = "name";
@@ -42,5 +46,7 @@
public static final String NAMESPACE_FILE_NAME = "namespace";
+ public static final String SCHEMA_FILE_NAME = "schema.xsd";
+
public static final String NAMESPACE_FILE_DELIMETER = " ";
}