Author: Alex.Kolonitsky
Date: 2010-03-12 07:09:36 -0500 (Fri, 12 Mar 2010)
New Revision: 16566
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/XmlTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/AbstractTestComponent.java
Log:
fix xml tests resources loading
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java 2010-03-12
06:34:41 UTC (rev 16565)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java 2010-03-12
12:09:36 UTC (rev 16566)
@@ -29,6 +29,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+import java.net.URL;
import org.richfaces.cdk.CdkClassLoader;
import org.richfaces.cdk.FileManager;
@@ -78,17 +79,12 @@
.put(
"http://java.sun.com/xml/ns/javaee/javaee_web_services_1_2.xsd",
URN_SYSTEM + "/javaee_web_services_1_2.xsd")
- .put(
-
"http://java.sun.com/xml/ns/javaee/javaee_web_services_client_1_2.xsd",
- URN_SYSTEM + "/javaee_web_services_client_1_2.xsd").put(
- "http://www.w3.org/2001/03/XMLSchema.dtd",
- URN_SYSTEM + "/XMLSchema.dtd").put(
- "http://www.w3.org/2001/03/xml.xsd",
- URN_SYSTEM + "/xml.xsd").put(
- "http://richfaces.org/cdk/cdk-template.xsd",
- URN_SYSTEM + "/cdk-template.xsd").put(
- "http://richfaces.org/cdk/xhtml-el.xsd",
- URN_SYSTEM + "/xhtml-el.xsd").build();
+
.put("http://java.sun.com/xml/ns/javaee/javaee_web_services_client_1_2.xsd",
URN_SYSTEM + "/javaee_web_services_client_1_2.xsd")
+ .put("http://www.w3.org/2001/03/XMLSchema.dtd", URN_SYSTEM +
"/XMLSchema.dtd")
+ .put("http://www.w3.org/2001/03/xml.xsd", URN_SYSTEM +
"/xml.xsd")
+ .put("http://www.w3.org/2001/xml.xsd", URN_SYSTEM +
"/xml.xsd")
+ .put("http://richfaces.org/cdk/cdk-template.xsd", URN_SYSTEM +
"/cdk-template.xsd")
+ .put("http://richfaces.org/cdk/xhtml-el.xsd", URN_SYSTEM +
"/xhtml-el.xsd").build();
@Inject
@@ -174,19 +170,41 @@
// Cdk resources
String path = systemIdInternal.substring(URN_SYSTEM.length());
- InputStream inputStream =
CdkEntityResolver.class.getResourceAsStream(SYSTEM_PREFIX + path);
+ URL url;
+ url = CdkEntityResolver.class.getResource(SYSTEM_PREFIX + path);
- if (null != inputStream) {
- entity = new InputSource(inputStream);
+ InputStream inputStream;
+ if (null != url) {
+ try {
+ inputStream = url.openStream();
+ } catch (IOException e) {
+ inputStream =
CdkEntityResolver.class.getResourceAsStream(SYSTEM_PREFIX + path);
+ }
+
+ if (inputStream != null) {
+ entity = new InputSource(inputStream);
+ entity.setSystemId(url.toString());
+ }
}
} else if (systemIdInternal.startsWith(URN_RESOURCE)) {
// Project resources
String path = systemIdInternal.substring(URN_RESOURCE.length());
- InputStream inputStream = loader.getResourceAsStream(RESOURCE_PREFIX +
path);
+ URL url;
+ url = loader.getResource(RESOURCE_PREFIX + path);
- if (null != inputStream) {
- entity = new InputSource(inputStream);
+ InputStream inputStream;
+ if (null != url) {
+ try {
+ inputStream = url.openStream();
+ } catch (IOException e) {
+ inputStream = loader.getResourceAsStream(RESOURCE_PREFIX + path);
+ }
+
+ if (inputStream != null) {
+ entity = new InputSource(inputStream);
+ entity.setSystemId(url.toString());
+ }
}
} else if (systemIdInternal.startsWith(URN_ATTRIBUTES)) {
@@ -215,7 +233,7 @@
entity = getProjectInputSource(rendererTemplatesFolders, path);
}
- if (null != entity) {
+ if (null != entity && entity.getSystemId() == null) {
entity.setSystemId(systemId);
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java 2010-03-12
06:34:41 UTC (rev 16565)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java 2010-03-12
12:09:36 UTC (rev 16566)
@@ -13,6 +13,8 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.net.URL;
+import java.net.MalformedURLException;
@RunWith(CdkTestRunner.class)
public class CdkResolverTest extends CdkTestBase {
@@ -46,6 +48,19 @@
}
}
+ public URL getResource(String name) {
+ if ("foo/bar.xml".equals(name)) {
+ try {
+ return new URL("file", "localhost",
"/foo/bar.xml");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ return null;
+ }
+ } else {
+ return super.getResource(name);
+ }
+ }
+
};
binder.bind(CdkClassLoader.class).toInstance(classLoader);
} catch (Exception e) {
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/XmlTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/XmlTest.java 2010-03-12
06:34:41 UTC (rev 16565)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/XmlTest.java 2010-03-12
12:09:36 UTC (rev 16566)
@@ -38,6 +38,9 @@
* @since Jan 13, 2010
*/
public abstract class XmlTest extends JaxbTestBase {
+ static {
+ XMLUnit.setControlEntityResolver(new CdkEntityResolver());
+ }
protected void validateXml(StringWriter facesConfig, String schemaLocation) throws
SAXException, IOException {
InputSource is = new InputSource(new StringReader(facesConfig.toString()));
@@ -66,10 +69,10 @@
}
XMLUnit.setNormalizeWhitespace(true);
Diff xmlDiff = new Diff(
- new StringReader(writer.toString()),
- new InputStreamReader(expectedFacesConfigFile));
+ new StringReader(writer.toString()),
+ new InputStreamReader(expectedFacesConfigFile));
- Assert.assertTrue("XML was not similar:"+xmlDiff.toString(),
xmlDiff.similar());
+ Assert.assertTrue("XML was not similar:" + xmlDiff.toString(),
xmlDiff.similar());
}
protected StringWriter generateFacesConfig(ComponentLibrary library) throws Exception
{
@@ -78,7 +81,7 @@
JAXBBinding jaxbBinding = new JAXBBinding();
jaxbBinding.marshal(result, FacesConfigGenerator.FACES_SCHEMA_LOCATION,
- new FacesConfigAdapter().marshal(library));
+ new FacesConfigAdapter().marshal(library));
return writer;
}
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java 2010-03-12
06:34:41 UTC (rev 16565)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java 2010-03-12
12:09:36 UTC (rev 16566)
@@ -49,6 +49,6 @@
// Checks
checkXmlStructure(facesConfig);
-// validateXml(facesConfig); TODO: Why fail?
+ validateXml(facesConfig);
}
}
\ No newline at end of file
Modified:
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/AbstractTestComponent.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/AbstractTestComponent.java 2010-03-12
06:34:41 UTC (rev 16565)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/AbstractTestComponent.java 2010-03-12
12:09:36 UTC (rev 16566)
@@ -37,7 +37,7 @@
* @author asmirnov(a)exadel.com
*
*/
-(a)JsfComponent("org.richfaces.cdk.test.TestComponent")
+@JsfComponent(type = "org.richfaces.cdk.test.TestComponent")
public abstract class AbstractTestComponent extends UIComponent implements ValueHolder {
private static final String COMPONENT_FAMILY = "org.richfaces.Test";
@Attribute