if(name.length() < 1) {
name = defaultName;
}
IDiagramStencilSet stencilset = _pluginService.findStencilSet(req, name);
if (stencilset == null) {
throw new IllegalArgumentException("No stencilset by the name of " + name);
}
String applicationContext = ConfigurationProvider.getInstance().getDesignerContext().replaceAll("/", "");
InputStream input = null;
if (segments.length > 4) {
//looking for a resource under the stencilset.
String path = requestURI.substring(requestURI.indexOf(segments[2]) + segments[2].length() + 1);
if(path.indexOf(applicationContext + "/stencilset/org.jbpm.designer.jBPMDesigner/stencilsets/bpmn2.0jbpm/bpmn2.0jbpm.json") >= 0) {
path = applicationContext + "/stencilsets/bpmn2.0jbpm/bpmn2.0jbpm.json";
}
if(path.indexOf(applicationContext + "/stencilset/bpmn2.0jbpm/stencilset/org.jbpm.designer.jBPMDesigner/stencilsets/bpmn2.0jbpm/bpmn2.0jbpm.json") >= 0) {
path = applicationContext + "/stencilsets/bpmn2.0jbpm/bpmn2.0jbpm.json";
}
if(path.indexOf(applicationContext + "/stencilset/" + applicationContext + "/stencilsets/bpmn2.0/") >= 0) {
path = path.substring((applicationContext + "/stencilset/" + applicationContext + "/stencilsets/bpmn2.0/").length(), path.length());
}
if(path.indexOf("stencilset//" + applicationContext + "/stencilsets/bpmn2.0jbpm/") >= 0) {
path = path.substring(("stencilset//" + applicationContext + "/stencilsets/bpmn2.0jbpm/").length(), path.length());
}
if(path.indexOf(applicationContext + "/stencilset/" + applicationContext + "/stencilsets/bpmn2.0jbpm/") >= 0) {
path = path.substring((applicationContext + "/stencilset/" +applicationContext + "/stencilsets/bpmn2.0jbpm/").length(), path.length());
}
if(path.indexOf("bpmn2.0.json/") >= 0) {
path = path.substring("bpmn2.0.json".length(), path.length());
}
if(path.indexOf("bpmn2.0jbpm.json/") >= 0) {
path = path.substring("bpmn2.0jbpm.json".length(), path.length());
}
if(path.startsWith("/bpmn2.0jbpm/")) {
path = path.substring("/bpmn2.0jbpm/".length(), path.length());
}
if(path.startsWith("stencilsets/bpmn2.0jbpm/")) {
path = path.substring("stencilsets/bpmn2.0jbpm/".length(), path.length());
}
if(path.startsWith("2.0jbpm/bpmn2.0jbpm.json/")) {
path = path.substring("2.0jbpm/bpmn2.0jbpm.json/".length(), path.length());
}
input = stencilset.getResourceContents(path);
if(requestURI.endsWith(".svg")) {
resp.setContentType("text/xml");
} else if(requestURI.endsWith(".png")) {
resp.setContentType("image/png");
} else {
//default to not setting
}
} else {
input = stencilset.getContents();
resp.setContentType("application/json");
}
try {
byte[] buffer = new byte[4096];