New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JBRULES-3633 resource encoding #38
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ public class DroolsResourceAdapter | |
private Resource resource; | ||
private ResourceType resourceType; | ||
private ResourceConfiguration resourceConfiguration; | ||
private String resourceName; | ||
private String encoding; | ||
|
||
public DroolsResourceAdapter() { | ||
|
||
|
@@ -45,14 +47,24 @@ public DroolsResourceAdapter(String resource, | |
} | ||
|
||
public void setResource(String resource) { | ||
this.resourceName = resource; | ||
if ( resource.trim().startsWith( "classpath:" ) ) { | ||
this.resource = new ClassPathResource( resource.substring( resource.indexOf( ':' ) + 1 ), | ||
encoding, | ||
ClassPathResource.class.getClassLoader() ); | ||
} else { | ||
this.resource = new UrlResource( resource ); | ||
} | ||
} | ||
|
||
public void setEncoding(String encoding) { | ||
if ( !(resource instanceof ClassPathResource) ) { | ||
throw new IllegalArgumentException( "Encoding attribute is only valid for classpath Resources" ); | ||
} | ||
this.encoding = encoding; | ||
setResource(resourceName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is setEncoding() is called before or after setResource() or arbitrary? After: setEncoding() should assert that resource is a ClassPathResource and do this.resource.setEncoding() |
||
} | ||
|
||
public void setBasicAuthenticationEnabled(Boolean enabled) { | ||
if ( enabled && !(this.resource instanceof UrlResource) ) { | ||
throw new IllegalArgumentException( "Authentication Attributes are only valid for URL Resources" ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:drools="http://drools.org/schema/drools-spring" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd | ||
http://drools.org/schema/drools-spring org/drools/container/spring/drools-spring.xsd"> | ||
|
||
<drools:kbase id="kbase"> | ||
<drools:resources> | ||
<drools:resource type="DRL" source="classpath:org/drools/container/spring/sampleUTF8.drl" encoding="UTF-8" /> | ||
<drools:resource type="DRL" source="classpath:org/drools/container/spring/sampleISO88591.drl" encoding="ISO-8859-1" /> | ||
</drools:resources> | ||
</drools:kbase> | ||
|
||
|
||
<drools:ksession id="ksession" type="stateless" name="stateless" kbase="kbase"/> | ||
|
||
</beans> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.drools.container.spring.i | ||
|
||
rule "sample ac��nt�d rule" | ||
@output("\"Hello world!\"") | ||
when | ||
then | ||
System.out.println("\"Hello world!\""); | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.drools.container.spring.u | ||
|
||
rule "sample acçéntèd rule" | ||
@output("\"Hello world!\"") | ||
when | ||
then | ||
System.out.println("\"Hello world!\""); | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the resourceName variable pls (unless there's a good reason to keep it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resourceName needs to be stored as there is I see way to change the encoding after creation. So I need to re-create the resource with the correct resource name and encoding.