use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.
the class ResourceTag method doStartTag.
// --------------------------------------------------------- Public Methods
/**
* Retrieve the required property and expose it as a scripting variable.
*
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
// Acquire an input stream to the specified resource
InputStream stream = pageContext.getServletContext().getResourceAsStream(name);
if (stream == null) {
JspException e = new JspException(messages.getMessage("resource.get", name));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
// If we are returning an InputStream, do so and return
if (input != null) {
pageContext.setAttribute(id, stream);
return (SKIP_BODY);
}
// Accumulate the contents of this resource into a StringBuffer
try {
StringBuffer sb = new StringBuffer();
InputStreamReader reader = new InputStreamReader(stream);
char[] buffer = new char[BUFFER_SIZE];
int n = 0;
while (true) {
n = reader.read(buffer);
if (n < 1) {
break;
}
sb.append(buffer, 0, n);
}
reader.close();
pageContext.setAttribute(id, sb.toString());
} catch (IOException e) {
TagUtils.getInstance().saveException(pageContext, e);
throw new JspException(messages.getMessage("resource.get", name));
}
return (SKIP_BODY);
}
use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.
the class SizeTag method doStartTag.
// --------------------------------------------------------- Public Methods
/**
* Retrieve the required property and expose it as a scripting variable.
*
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
// Retrieve the required property value
Object value = this.collection;
if (value == null) {
if (name == null) {
// Must specify either a collection attribute or a name
// attribute.
JspException e = new JspException(messages.getMessage("size.noCollectionOrName"));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
value = TagUtils.getInstance().lookup(pageContext, name, property, scope);
}
// Identify the number of elements, based on the collection type
int size = 0;
if (value == null) {
JspException e = new JspException(messages.getMessage("size.collection"));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
} else if (value.getClass().isArray()) {
size = Array.getLength(value);
} else if (value instanceof Collection) {
size = ((Collection) value).size();
} else if (value instanceof Map) {
size = ((Map) value).size();
} else {
JspException e = new JspException(messages.getMessage("size.collection"));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
// Expose this size as a scripting variable
pageContext.setAttribute(this.id, new Integer(size), PageContext.PAGE_SCOPE);
return (SKIP_BODY);
}
use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.
the class TestTagUtils method skiptestComputeParametersParamIdAsStringArray.
public void skiptestComputeParametersParamIdAsStringArray() {
Map params = new HashMap();
// String[] vals = new String[]{"test0, test1"};
params.put("fooParamId", "fooParamValue");
request.getSession().setAttribute("SomeBean", params);
Map map = null;
try {
map = tagutils.computeParameters(pageContext, "fooParamId", "SomeBean", null, null, "SomeBean", null, null, false);
// map = tagutils.computeParameters(
// page, "paramId", "SomeBean", "stringArray", null,
// null, null, null, false);
assertNotNull("map is null", map);
String val = (String) map.get("key0");
assertTrue("paramId should be \"test\"", "1.0".equals(val));
} catch (JspException e) {
fail("JspException not thrown");
}
}
use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.
the class TestTagUtils method testComputeParameters2d.
// Provided map -- name with one key and two values
public void testComputeParameters2d() {
Map map = new HashMap();
map.put("foo", new String[] { "bar1", "bar2" });
request.getSession().setAttribute("attr", map);
try {
map = tagutils.computeParameters(pageContext, null, null, null, null, "attr", null, null, false);
} catch (JspException e) {
fail("JspException: " + e);
}
assertNotNull("Map is not null", map);
assertEquals("One parameter in the returned map", 1, map.size());
assertTrue("Parameter foo present", map.containsKey("foo"));
assertTrue("Parameter foo value type", map.get("foo") instanceof String[]);
String[] values = (String[]) map.get("foo");
assertEquals("Values count", 2, values.length);
}
use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.
the class TestTagUtils method testComputeParameters1b.
// Single parameter -- scope + name
public void testComputeParameters1b() {
request.setAttribute("attr", "bar");
Map map = null;
try {
map = tagutils.computeParameters(pageContext, "foo", "attr", null, "request", null, null, null, false);
} catch (JspException e) {
fail("JspException: " + e);
}
assertNotNull("Map is not null", map);
assertEquals("One parameter in the returned map", 1, map.size());
assertTrue("Parameter present", map.containsKey("foo"));
assertEquals("Parameter value", "bar", (String) map.get("foo"));
}
Aggregations