use of org.drools.core.io.internal.InternalResource in project drools by kiegroup.
the class KieRepositoryImpl method getKieModule.
public KieModule getKieModule(Resource resource) {
InternalResource res = (InternalResource) resource;
try {
KieModule kModule;
// find kmodule.xml
if (res.hasURL()) {
String urlPath = res.getURL().toExternalForm();
if (res.isDirectory()) {
if (!urlPath.endsWith("/")) {
urlPath = urlPath + "/";
}
urlPath = urlPath + KieModuleModelImpl.KMODULE_JAR_PATH;
} else {
urlPath = "jar:" + urlPath + "!/" + KieModuleModelImpl.KMODULE_JAR_PATH;
}
kModule = ClasspathKieProject.fetchKModule(new URL(urlPath));
log.debug("Fetched KieModule from resource: " + resource);
} else {
// might be a byte[] resource
MemoryFileSystem mfs = MemoryFileSystem.readFromJar(res.getInputStream());
byte[] bytes = mfs.getBytes(KieModuleModelImpl.KMODULE_JAR_PATH);
KieModuleModel kieProject = KieModuleModelImpl.fromXML(new ByteArrayInputStream(bytes));
setDefaultsforEmptyKieModule(kieProject);
String pomProperties = mfs.findPomProperties();
ReleaseId releaseId = ReleaseIdImpl.fromPropertiesString(pomProperties);
kModule = new MemoryKieModule(releaseId, kieProject, mfs);
}
return kModule;
} catch (Exception e) {
throw new RuntimeException("Unable to fetch module from resource: " + res, e);
}
}
use of org.drools.core.io.internal.InternalResource in project drools by kiegroup.
the class DecisionTableConfigurationHandler method end.
public Object end(String uri, String localName, ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final InternalResource resource = (InternalResource) parser.getParent();
ResourceConfiguration dtConf = (ResourceConfiguration) parser.getCurrent();
resource.setConfiguration(dtConf);
return dtConf;
}
use of org.drools.core.io.internal.InternalResource in project drools by kiegroup.
the class ResourceHandler method start.
public Object start(String uri, String localName, Attributes attrs, ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
final Collection collection = (Collection) parser.getParent();
String src = attrs.getValue("source");
String type = attrs.getValue("type");
String basicAuthentication = attrs.getValue("basicAuthentication");
String username = attrs.getValue("username");
String password = attrs.getValue("password");
String name = attrs.getValue("name");
String description = attrs.getValue("description");
String categories = attrs.getValue("categories");
emptyAttributeCheck(localName, "source", src, parser);
emptyAttributeCheck(localName, "type", type, parser);
InternalResource resource = null;
if (src.trim().startsWith("classpath:")) {
resource = new ClassPathResource(src.substring(src.indexOf(':') + 1), parser.getClassLoader());
} else {
resource = new UrlResource(src);
((UrlResource) resource).setBasicAuthentication(basicAuthentication);
((UrlResource) resource).setUsername(username);
((UrlResource) resource).setPassword(password);
}
resource.setResourceType(ResourceType.getResourceType(type));
resource.setSourcePath(name);
resource.setDescription(description);
resource.setCategories(categories);
return resource;
}
Aggregations