use of javax.servlet.jsp.JspException in project opennms by OpenNMS.
the class EvaluationTest method runTests.
// -------------------------------------
/**
* Runs the tests, reading expressions from pIn and writing the
* results to pOut.
*/
public static void runTests(DataInput pIn, PrintStream pOut) throws IOException {
PageContext context = createTestContext();
while (true) {
String str = pIn.readLine();
if (str == null)
break;
if (str.startsWith("#") || "".equals(str.trim())) {
pOut.println(str);
} else {
String typeStr = pIn.readLine();
pOut.println("Expression: " + str);
try {
Class cl = parseClassName(typeStr);
pOut.println("ExpectedType: " + cl);
Evaluator e = new Evaluator();
Object val = e.evaluate("test", str, cl, null, context);
pOut.println("Evaluates to: " + val);
if (val != null) {
pOut.println("With type: " + val.getClass().getName());
}
pOut.println();
} catch (JspException exc) {
pOut.println("Causes an error: " + exc);
} catch (ClassNotFoundException exc) {
pOut.println("Causes an error: " + exc);
}
}
}
}
use of javax.servlet.jsp.JspException in project Openfire by igniterealtime.
the class SidebarTag method doEndTag.
/**
* Gets the {@link AdminPageBean} instance from the request. If it doesn't exist then execution is stopped
* and nothing is printed. If it exists, retrieve values from it and render the sidebar items. The body content
* of the tag is assumed to have an A tag in it with tokens to replace (see class description) as well
* as having a subsidebar tag..
*
* @return {@link #EVAL_PAGE} after rendering the tabs.
* @throws JspException if an exception occurs while rendering the sidebar items.
*/
@Override
public int doEndTag() throws JspException {
// Start by getting the request from the page context
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
// Check for body of this tag and the child tag
if (getBodyContent().getString() == null) {
throw new JspException("Error, no template (body value) set for the sidebar tag.");
}
if (subsidebarTag.getBody() == null) {
throw new JspException("Error, no template (body value) set for the subsidebar tag");
}
// Get the initial subpage and page IDs
String subPageID = (String) request.getAttribute("subPageID");
String pageID = (String) request.getAttribute("pageID");
// subPageIDs are null, return because these are key to execution of the tag.
if (subPageID != null || pageID != null) {
if (pageID == null) {
Element subPage = AdminConsole.getElemnetByID(subPageID);
pageID = subPage.getParent().getParent().attributeValue("id");
}
// Top level menu items
if (AdminConsole.getModel().elements().size() > 0) {
JspWriter out = pageContext.getOut();
StringBuilder buf = new StringBuilder();
Element current = null;
Element subcurrent = null;
Element subnav = null;
if (subPageID != null) {
subcurrent = AdminConsole.getElemnetByID(subPageID);
}
current = AdminConsole.getElemnetByID(pageID);
if (current != null) {
subnav = current.getParent();
}
Element currentTab = (Element) AdminConsole.getModel().selectSingleNode("//*[@id='" + pageID + "']/ancestor::tab");
boolean isSubmenu = false;
if (subcurrent != null) {
isSubmenu = subcurrent.getParent().getParent().getName().equals("item");
}
// Loop through all items in the root, print them out
if (currentTab != null && subnav != null) {
Element sidebar = subnav.getParent().getParent();
//String header = sidebar.attributeValue("name");
String pluginName = sidebar.attributeValue("plugin");
// Print the header:
String hcss = getHeadercss();
if (hcss == null) {
hcss = "";
}
Collection items = subnav.elements();
if (items.size() > 0) {
buf.append("<ul>");
// Now print all items:
for (Object itemObj : items) {
Element item = (Element) itemObj;
String subitemID = item.attributeValue("id");
String subitemName = item.attributeValue("name");
String subitemURL = item.attributeValue("url");
String subitemDescr = item.attributeValue("description");
pluginName = item.attributeValue("plugin");
String value = getBodyContent().getString();
if (value != null) {
value = StringUtils.replace(value, "[id]", clean(subitemID));
value = StringUtils.replace(value, "[name]", clean(AdminConsole.getAdminText(subitemName, pluginName)));
value = StringUtils.replace(value, "[description]", clean(AdminConsole.getAdminText(subitemDescr, pluginName)));
value = StringUtils.replace(value, "[url]", request.getContextPath() + "/" + clean(subitemURL));
}
String css = getCss();
boolean isCurrent = item.equals(current);
boolean showSubmenu = subPageID != null;
if (isCurrent && !showSubmenu) {
css = getCurrentcss();
}
buf.append("<li class=\"").append(css).append("\">").append(value).append("</li>");
// Print out a submenu if one exists:
if (isSubmenu && isCurrent) {
// Get the parent of the current item so we can get its
// items - those will be siblings of the current item:
Iterator siblings = subcurrent.getParent().elementIterator();
boolean hadNext = siblings.hasNext();
if (hadNext) {
// Print out beginning UL
buf.append("<li class=\"\"><ul class=\"subitems\">\n");
// Print the header LI
String subheader = subcurrent.getParent().attributeValue("name");
pluginName = subcurrent.getParent().attributeValue("plugin");
buf.append("<li class=\"").append(hcss).append("\">").append(clean(AdminConsole.getAdminText(subheader, pluginName))).append("</li>");
}
String extraParams = (String) request.getAttribute("extraParams");
while (siblings.hasNext()) {
Element sibling = (Element) siblings.next();
String sibID = sibling.attributeValue("id");
String sibName = sibling.attributeValue("name");
String sibDescr = sibling.attributeValue("description");
String sibURL = sibling.attributeValue("url");
pluginName = sibling.attributeValue("plugin");
if (extraParams != null) {
sibURL += ((sibURL.indexOf('?') > -1 ? "&" : "?") + extraParams);
}
boolean isSubCurrent = sibling.equals(subcurrent);
String subcss = getCss();
if (isSubCurrent) {
subcss = getCurrentcss();
}
String svalue = getSubsidebarTag().getBody();
if (svalue != null) {
svalue = StringUtils.replace(svalue, "[id]", clean(sibID));
svalue = StringUtils.replace(svalue, "[name]", clean(AdminConsole.getAdminText(sibName, pluginName)));
svalue = StringUtils.replace(svalue, "[description]", clean(AdminConsole.getAdminText(sibDescr, pluginName)));
svalue = StringUtils.replace(svalue, "[url]", request.getContextPath() + "/" + clean(sibURL));
}
buf.append("<li class=\"").append(subcss).append("\">").append(svalue).append("</li>\n");
}
if (hadNext) {
// Print out ending UL
buf.append("</ul></li>\n");
}
}
}
buf.append("</ul>");
try {
out.write(buf.toString());
} catch (IOException e) {
throw new JspException(e);
}
}
}
}
}
return EVAL_PAGE;
}
use of javax.servlet.jsp.JspException in project Openfire by igniterealtime.
the class SubnavTag method doEndTag.
/**
* Gets the {@link AdminPageBean} instance from the request. If it doesn't exist then execution is stopped
* and nothing is printed. If it exists, retrieve values from it and render the sidebar items. The body content
* of the tag is assumed to have an A tag in it with tokens to replace (see class description) as well
* as having a subsidebar tag..
*
* @return {@link #EVAL_PAGE} after rendering the tabs.
* @throws JspException if an exception occurs while rendering the sidebar items.
*/
@Override
public int doEndTag() throws JspException {
// Start by getting the request from the page context
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
// Check for body of this tag and the child tag
if (getBodyContent().getString() == null) {
throw new JspException("Error, no template (body value) set for the sidebar tag.");
}
// Get the initial subpage and page IDs
String subPageID = (String) request.getAttribute("subPageID");
String pageID = (String) request.getAttribute("pageID");
// subPageIDs are null, return because these are key to execution of the tag.
if (subPageID != null || pageID != null) {
if (pageID == null) {
Element subPage = AdminConsole.getElemnetByID(subPageID);
pageID = subPage.getParent().getParent().attributeValue("id");
}
// Top level menu items
if (AdminConsole.getModel().elements().size() > 0) {
JspWriter out = pageContext.getOut();
StringBuilder buf = new StringBuilder();
Element current = null;
Element subcurrent = null;
Element subnav = null;
if (subPageID != null) {
subcurrent = AdminConsole.getElemnetByID(subPageID);
}
current = AdminConsole.getElemnetByID(pageID);
if (current != null) {
if (subcurrent != null) {
subnav = subcurrent.getParent().getParent().getParent();
} else {
subnav = current.getParent();
}
}
Element currentTab = (Element) AdminConsole.getModel().selectSingleNode("//*[@id='" + pageID + "']/ancestor::tab");
// Loop through all items in the root, print them out
if (currentTab != null) {
Collection items = currentTab.elements();
if (items.size() > 0) {
buf.append("<ul>");
for (Object itemObj : items) {
Element item = (Element) itemObj;
if (item.elements().size() > 0) {
Element firstSubItem = (Element) item.elements().get(0);
String pluginName = item.attributeValue("plugin");
String subitemID = item.attributeValue("id");
String subitemName = item.attributeValue("name");
String subitemURL = firstSubItem.attributeValue("url");
String subitemDescr = item.attributeValue("description");
String value = getBodyContent().getString();
if (value != null) {
value = StringUtils.replace(value, "[id]", clean(subitemID));
value = StringUtils.replace(value, "[name]", clean(AdminConsole.getAdminText(subitemName, pluginName)));
value = StringUtils.replace(value, "[description]", clean(AdminConsole.getAdminText(subitemDescr, pluginName)));
value = StringUtils.replace(value, "[url]", request.getContextPath() + "/" + clean(subitemURL));
}
String css = getCss();
boolean isCurrent = subnav != null && item.equals(subnav);
if (isCurrent) {
css = getCurrentcss();
}
buf.append("<li class=\"").append(css).append("\">").append(value).append("</li>");
}
}
buf.append("</ul>");
try {
out.write(buf.toString());
} catch (IOException e) {
throw new JspException(e);
}
}
}
}
}
return EVAL_PAGE;
}
use of javax.servlet.jsp.JspException in project Openfire by igniterealtime.
the class TabsTag method doEndTag.
/**
* Gets the {@link AdminPageBean} instance from the request. If it doesn't exist then execution is stopped
* and nothing is printed. If it exists, retrieve values from it and render the tabs. The body content
* of the tag is assumed to have an A tag in it with tokens to replace (see class description).
*
* @return {@link #EVAL_PAGE} after rendering the tabs.
* @throws JspException if an exception occurs while rendering the tabs.
*/
@Override
public int doEndTag() throws JspException {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
// Get the page data bean from the request:
// If the page info bean is not in the request then no tab will be selected - so, it'll fail gracefully
String pageID = (String) request.getAttribute("pageID");
String subPageID = (String) request.getAttribute("subPageID");
if (pageID == null) {
Element subPage = AdminConsole.getElemnetByID(subPageID);
if (subPage != null) {
pageID = subPage.getParent().getParent().attributeValue("id");
}
}
// Get tabs from the model:
List tabs = AdminConsole.getModel().selectNodes("//tab");
if (tabs.size() > 0) {
JspWriter out = pageContext.getOut();
// Build up the output in a buffer (is probably faster than a bunch of out.write's)
StringBuilder buf = new StringBuilder();
if (!justlinks) {
buf.append("<ul>");
}
String body = getBodyContent().getString();
// For each tab, print out an <LI>.
Element currentTab = null;
if (pageID != null) {
currentTab = (Element) AdminConsole.getModel().selectSingleNode("//*[@id='" + pageID + "']/ancestor::tab");
}
for (int i = 0; i < tabs.size(); i++) {
Element tab = (Element) tabs.get(i);
String value = body;
if (value != null) {
// The URL for the tab should be the URL of the first item in the tab.
String pluginName = tab.attributeValue("plugin");
value = StringUtils.replace(value, "[id]", clean(tab.attributeValue("id")));
value = StringUtils.replace(value, "[url]", request.getContextPath() + "/" + clean(tab.attributeValue("url")));
value = StringUtils.replace(value, "[name]", clean(AdminConsole.getAdminText(tab.attributeValue("name"), pluginName)));
value = StringUtils.replace(value, "[description]", clean(AdminConsole.getAdminText(tab.attributeValue("description"), pluginName)));
}
String css = getCss();
if (tab.equals(currentTab)) {
css = getCurrentcss();
}
if (!justlinks) {
buf.append("<li class=\"").append(css).append("\">");
}
if (justlinks && i > 0) {
buf.append(" | ");
}
buf.append(value);
if (!justlinks) {
buf.append("</li>");
}
}
if (!justlinks) {
buf.append("</ul>");
}
try {
out.write(buf.toString());
} catch (IOException ioe) {
throw new JspException(ioe.getMessage());
}
}
return EVAL_PAGE;
}
use of javax.servlet.jsp.JspException in project head by mifos.
the class CustomFieldCategoryListTag method doStartTag.
@Override
public int doStartTag() throws JspException {
try {
UserContext userContext = (UserContext) pageContext.getSession().getAttribute(Constants.USERCONTEXT);
TagUtils.getInstance().write(pageContext, getCustomFieldCategoryList(userContext));
} catch (Exception e) {
/**
* This turns into a (rather ugly) error 500. TODO: make it more
* reasonable.
*/
throw new JspException(e);
}
return EVAL_PAGE;
}
Aggregations