下面列出了怎么用javax.servlet.jsp.JspTagException的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public int doEndTag() throws JspException {
JspWriter out = pageContext.getOut();
try {
if (!"-1".equals(objectValue)) {
out.print(objectValue);
} else if (!"-1".equals(stringValue)) {
out.print(stringValue);
} else if (longValue != -1) {
out.print(longValue);
} else if (doubleValue != -1) {
out.print(doubleValue);
} else {
out.print("-1");
}
} catch (IOException ex) {
throw new JspTagException("IOException: " + ex.toString(), ex);
}
return super.doEndTag();
}
public int doEndTag() throws JspException {
// Rewrite and encode the url.
String result = formatUrl();
// Store or print the output
if (var != null)
pageContext.setAttribute(var, result, PageContext.PAGE_SCOPE);
else {
try {
pageContext.getOut().print(result);
} catch (IOException x) {
throw new JspTagException(x);
}
}
return EVAL_PAGE;
}
/**
* permission control
*/
@Override
public int doStartTag() throws JspTagException {
ComAdmin aAdmin = AgnUtils.getAdmin(pageContext);
if (aAdmin == null) {
throw new JspTagException("PermissionDenied$" + permissionToken);
} else {
boolean permissionGranted = false;
try {
permissionGranted = aAdmin.permissionAllowed(Permission.getPermissionsByToken(permissionToken));
} catch (Exception e) {
releaseException(e, permissionToken);
}
if (!permissionGranted) {
throw new JspTagException("PermissionDenied$" + permissionToken);
}
return SKIP_BODY;
}
}
/**
* 为搜书功能中添加下拉框
*/
public void doTag() throws JspException, IOException {
try {
JspWriter out = jspContext.getOut();
String outPrint = "";
String[] color = { "Book Name", "Author", "Publisher", "ISBN" };
outPrint += "<select id=\"input\" name=\"searchBy\"> ";
for (int i = 0; i < color.length; i++) {
outPrint += "<option>";
outPrint += color[i];
outPrint += "</option>";
}
outPrint += "</select>";
out.print(outPrint);
} catch (java.io.IOException e) {
throw new JspTagException(e.getMessage());
}
}
/**
* 为添加书本中的location添加下拉框
*/
public void doTag() throws JspException, IOException {
try {
JspWriter out = jspContext.getOut();
String outPrint = "";
String[] color = { "四层-科技图书阅览区", "四层-科技图书典藏区", "三层-社科类图书阅览区", "三层-社科类图书典藏区", "二层-杂志期刊" };
outPrint += "<select name='Location' size='1' class=\"form-control\"> ";
for (int i = 0; i < color.length; i++) {
outPrint += "<option>";
outPrint += color[i];
outPrint += "</option>";
}
outPrint += "</select>";
out.print(outPrint);
} catch (java.io.IOException e) {
throw new JspTagException(e.getMessage());
}
}
public int doEndTag() throws JspException {
if (getParent()!=null && getParent() instanceof SectionHeader) {
((SectionHeader)getParent()).setTitle(getBodyContent().getString());
} else {
try {
String body = (getBodyContent()==null?null:getBodyContent().getString());
if (body==null || body.trim().length()==0) {
pageContext.getOut().println("<DIV class='WelcomeRowHeadBlank'> </DIV>");
} else {
pageContext.getOut().println("<DIV class='WelcomeRowHead'>");
pageContext.getOut().println(body);
pageContext.getOut().println("</DIV>");
}
} catch (Exception e) {
e.printStackTrace();
throw new JspTagException(e.getMessage());
}
}
return EVAL_PAGE;
}
/**
* Actions after some body has been evaluated.
*/
@Override
public int doAfterBody() throws JspTagException {
ElementTag elementTag = (ElementTag)
findAncestorWithClass(this, ElementTag.class);
if (elementTag != null) {
// get body content
BodyContent body = getBodyContent();
if (body != null) {
String content = body.getString();
// add this attribute to parent element tag
elementTag.addAttribute(attrName, content);
body.clearBody();
} else {
log.warn("AttributeTag: body content is null!");
}
} else {
log.warn("AttributeTag: no parent element tag found!");
}
// only evaluate body once
return SKIP_BODY;
}
public int doEndTag() throws JspException {
// Rewrite and encode the url.
String result = formatUrl();
// Store or print the output
if (var != null)
pageContext.setAttribute(var, result, PageContext.PAGE_SCOPE);
else {
try {
pageContext.getOut().print(result);
} catch (IOException x) {
throw new JspTagException(x);
}
}
return EVAL_PAGE;
}
@Override
public int doEndTag() throws JspException {
JspWriter out = pageContext.getOut();
try {
if (!"-1".equals(objectValue)) {
out.print(objectValue);
} else if (!"-1".equals(stringValue)) {
out.print(stringValue);
} else if (longValue != -1) {
out.print(longValue);
} else if (doubleValue != -1) {
out.print(doubleValue);
} else {
out.print("-1");
}
} catch (IOException ex) {
throw new JspTagException("IOException: " + ex.toString(), ex);
}
return super.doEndTag();
}
/**
* Process the start tag for this instance.
*/
@Override
public int doStartTag() throws JspTagException {
// retrieve parent tag which accepts the produced collection by this tag
ValueAcceptingTagIF acceptingTag = (ValueAcceptingTagIF)
findAncestorWithClass(this, ValueAcceptingTagIF.class);
// try to retrieve root ContextTag
ContextTag contextTag = FrameworkUtils.getContextTag(pageContext);
// get collection of TM Reference entries from Configuration
Collection refs =
contextTag.getNavigatorApplication().getTopicMapRepository().getReferences();
// kick it up to the accepting tag
acceptingTag.accept( refs );
// ignore body, because this is an empty tag
return SKIP_BODY;
}
/**
* Process the start tag for this instance.
*/
@Override
public int doStartTag() throws JspTagException {
parentChooser = (ChooseTag) findAncestorWithClass(this, ChooseTag.class);
if (parentChooser == null)
throw new JspTagException(
"tolog:otherwise tag is not inside tolog:choose tag.");
ContextTag contextTag = FrameworkUtils.getContextTag(pageContext);
if (contextTag == null)
throw new JspTagException("<tolog:otherwise> must be nested directly or"
+ " indirectly within a <tolog:context> tag, but no"
+ " <tolog:context> tag was found.");
contextTag.getContextManager().pushScope();
// If a matching when was already found within the parentChooser
if (parentChooser.foundMatchingWhen())
// No more WhenTags need to be executed (tested in each WhenTag).
return SKIP_BODY;
return EVAL_BODY_BUFFERED;
}
@Override
public int doEndTag() throws JspException {
JspWriter out = pageContext.getOut();
try {
if (!"-1".equals(objectValue)) {
out.print(objectValue);
} else if (!"-1".equals(stringValue)) {
out.print(stringValue);
} else if (longValue != -1) {
out.print(longValue);
} else if (doubleValue != -1) {
out.print(doubleValue);
} else {
out.print("-1");
}
} catch (IOException ex) {
throw new JspTagException("IOException: " + ex.toString(), ex);
}
return super.doEndTag();
}
public int doEndTag() throws JspException {
// Rewrite and encode the url.
String result = formatUrl();
// Store or print the output
if (var != null)
pageContext.setAttribute(var, result, PageContext.PAGE_SCOPE);
else {
try {
pageContext.getOut().print(result);
} catch (IOException x) {
throw new JspTagException(x);
}
}
return EVAL_PAGE;
}
@Override
public Collection process(Collection tmObjects) throws JspTagException {
// Find all reifying topics of all topic map objects in collection
if (tmObjects == null || tmObjects.isEmpty())
return Collections.EMPTY_SET;
else {
ArrayList reifyingTopics = new ArrayList();
Iterator iter = tmObjects.iterator();
TopicIF reifyingTopic;
// Loop over the topic map objects
while (iter.hasNext()) {
// Get the topic that reifies the given topic map object
reifyingTopic = ((ReifiableIF)iter.next()).getReifier();
// If a topic was found add it to the result list.
if (reifyingTopic != null)
reifyingTopics.add(reifyingTopic);
}
// Return all reifiying topics found.
return reifyingTopics;
}
}
/**
* Process the start tag for this instance.
*/
@Override
public int doStartTag() throws JspTagException {
this.ifTagParent = (IfTag) findAncestorWithClass(this, IfTag.class);
if (ifTagParent == null) {
throw new JspTagException("logic:else is not inside logic:if.");
}
if (ifTagParent.matchCondition())
return SKIP_BODY;
else
return EVAL_BODY_BUFFERED;
}
/**
* Bind (some of) the names of the columns of the result to the current row.
* Only bind those columns corresponding to a true entry in groupColumns.
* e.g. column 3 is bound if groupColumns[3] is true.
*/
protected void bindVariables(boolean groupColumns[]) throws JspTagException {
String columnNames[] = queryResult.getColumnNames();
for (int i = 0; i < groupColumns.length; i++) {
if (groupColumns[i]) {
contextManager.setValue(columnNames[i]
, currentRow[i] == null
? Collections.EMPTY_LIST
: currentRow[i]);
}
}
}
/**
* Utility methods
* taken from org.apache.taglibs.standard.tag.common.core.UrlSupport
* @param url The URL
* @param context The context
* @param pageContext The page context
* @return the absolute URL
* @throws JspException If the URL doesn't start with '/'
*/
public static String resolveUrl(
String url, String context, PageContext pageContext)
throws JspException {
// don't touch absolute URLs
if (isAbsoluteUrl(url))
return url;
// normalize relative URLs against a context root
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
if (context == null) {
if (url.startsWith("/"))
return (request.getContextPath() + url);
else
return url;
} else {
if (!context.startsWith("/") || !url.startsWith("/")) {
throw new JspTagException(
"In URL tags, when the \"context\" attribute is specified, values of both \"context\" and \"url\" must start with \"/\".");
}
if (context.equals("/")) {
// Don't produce string starting with '//', many
// browsers interpret this as host name, not as
// path on same host.
return url;
} else {
return (context + url);
}
}
}
public int doStartTag() throws JspException {
try {
pageContext.getOut().print(
BackTracker.getBackTree((HttpServletRequest)pageContext.getRequest())
);
} catch (Exception e) {
throw new JspTagException(e.getMessage());
}
return SKIP_BODY;
}
@Override
public int doStartTag() throws JspTagException {
pageContext.setAttribute(
"sessionContext",
WebApplicationContextUtils.getWebApplicationContext(this.pageContext.getServletContext()).getBean("sessionContext")
);
return EVAL_BODY_INCLUDE;
}
public int doEndTag() throws JspTagException {
// Add parameter name and value to surrounding 'url' tag.
UrlTag tag = (UrlTag) findAncestorWithClass(this, UrlTag.class);
if (tag == null) {
throw new JspTagException("'sub:param' tag used outside 'sub:url'");
}
tag.addParameter(name, value);
return EVAL_PAGE;
}
@Override
public Collection process(Collection topics) throws JspTagException {
// find all subclasses of all topics in collection
if (topics == null || topics.isEmpty())
return Collections.EMPTY_SET;
else {
HashSet subclasses = new HashSet();
Iterator iter = topics.iterator();
TopicIF topic = null;
Object obj = null;
while (iter.hasNext()) {
obj = iter.next();
try {
topic = (TopicIF) obj;
} catch (ClassCastException e) {
throw new NavigatorRuntimeException("SubclassesTag expected to get a input collection of " +
"topic instances, but got instance of class " + obj.getClass().getName());
}
// the topic casting succeeded, now find the subclasses
if (levelNumber == null)
subclasses.addAll( hierUtils.getSubclasses(topic) );
else
subclasses.addAll( hierUtils.getSubclasses(topic,
levelNumber.intValue()));
} // while
return subclasses;
}
}
@Override
public Collection process(Collection tmObjects) throws JspTagException {
// Get topic map
ContextTag contextTag = FrameworkUtils.getContextTag(pageContext);
// Get topic map from context
TopicMapIF topicmap = contextTag.getTopicMap();
String tmid = contextTag.getTopicMapId();
if (topicmap == null)
throw new NavigatorRuntimeException("FulltextTag found no topic map.");
try {
// Output debugging information
if (log.isDebugEnabled()) {
log.debug("Query: '" + query + "'");
}
// Create search engine
SearcherIF sengine = (SearcherIF) topicmap.getIndex(SearcherIF.class.getName());
if (sengine == null) {
throw new NavigatorRuntimeException("Topicmap " + tmid + " has no SearcherIF index");
}
// Perform search
TopicMapSearchResult result = new TopicMapSearchResult(topicmap, sengine.search(query));
// Set object id field
if (idfield != null) result.setObjectIdField(idfield);
// Return search result
return result;
} catch (java.io.IOException e) {
throw new OntopiaRuntimeException(e);
}
}
/**
* Actions after some body has been evaluated.
*/
@Override
public int doAfterBody() throws JspTagException {
parentChooser.setFoundMatchingWhen();
return super.doAfterBody();
}
/**
* Shows column information.
*/
@Override
public int doStartTag() throws JspTagException {
try {
if (iteratorID == null) {
iteratorID = "";
}
if (table == 0) {
table = AgnUtils.getAdmin(pageContext).getCompany().getId();
}
List<ComProfileField> comProfileFieldMap = getColumnInfoService().getComColumnInfos(table, AgnUtils.getAdmin(pageContext).getAdminID(), useCustomSorting);
if (comProfileFieldMap.size() <= 0) {
return SKIP_BODY;
} else {
pageContext.setAttribute("__" + iteratorID + "_data", comProfileFieldMap.iterator());
pageContext.setAttribute("__" + iteratorID + "_map", comProfileFieldMap);
pageContext.setAttribute("__" + iteratorID + "_colmap", comProfileFieldMap);
return doAfterBody();
}
} catch (Exception e) {
logger.error("Error in ComShowColumnInfoTag.doStartTag", e);
throw new JspTagException("Error: " + e);
}
}
@Override
public Collection process(Collection tmObjects) throws JspTagException {
// find all the classes of all tmObjects in collection
// avoid duplicate type entries therefore use a 'Set'
if (tmObjects == null)
return Collections.EMPTY_SET;
else{
Set types = new HashSet();
Iterator iter = tmObjects.iterator();
Object obj = null;
while (iter.hasNext()) {
obj = iter.next();
// --- for occurrence, association, or association role objects
if (obj instanceof TypedIF) {
TypedIF singleTypedObj = (TypedIF) obj;
TopicIF type = singleTypedObj.getType();
if (type != null)
types.add( type );
}
// --- for topic objects
else if (obj instanceof TopicIF) {
TopicIF topic = (TopicIF) obj;
Collection _types = topic.getTypes();
if (!_types.isEmpty())
types.addAll( _types );
}
} // while
return new ArrayList(types);
}
}
/**
* Resolve the specified message into a concrete message String.
* The returned message String should be unescaped.
*/
protected String resolveMessage() throws JspException, NoSuchMessageException {
MessageSource messageSource = getMessageSource();
// Evaluate the specified MessageSourceResolvable, if any.
if (this.message != null) {
// We have a given MessageSourceResolvable.
return messageSource.getMessage(this.message, getRequestContext().getLocale());
}
if (this.code != null || this.text != null) {
// We have a code or default text that we need to resolve.
Object[] argumentsArray = resolveArguments(this.arguments);
if (!this.nestedArguments.isEmpty()) {
argumentsArray = appendArguments(argumentsArray, this.nestedArguments.toArray());
}
if (this.text != null) {
// We have a fallback text to consider.
String msg = messageSource.getMessage(
this.code, argumentsArray, this.text, getRequestContext().getLocale());
return (msg != null ? msg : "");
}
else {
// We have no fallback text to consider.
return messageSource.getMessage(
this.code, argumentsArray, getRequestContext().getLocale());
}
}
throw new JspTagException("No resolvable message");
}
@Override
public Collection process(Collection topics) throws JspTagException {
// find all superclasses of all topics in collection
if (topics == null || topics.isEmpty())
return Collections.EMPTY_SET;
else {
HashSet superclasses = new HashSet();
Iterator iter = topics.iterator();
TopicIF topic = null;
Object obj = null;
while (iter.hasNext()) {
obj = iter.next();
try {
topic = (TopicIF)obj;
} catch (ClassCastException e) {
String msg = "SubclassesTag expected to get a input collection of " +
"topic instances, " +
"but got instance of class " + obj.getClass().getName();
throw new NavigatorRuntimeException(msg);
}
// ok, the topic cast succeeded, now continue
if (levelNumber == null)
// if no level is specified get all of them.
superclasses.addAll(hierUtils.getSuperclasses(topic));
else
superclasses.addAll(hierUtils.getSuperclasses(topic, levelNumber.intValue()));
} // while
return superclasses;
}
}
@SuppressWarnings("unchecked")
public int doStartTag() throws JspException {
StringBuilder buffer = new StringBuilder();
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
HttpSession session = request.getSession();
Map<String, String> map = null;
if (session.getAttribute(EgovDoubleSubmitHelper.SESSION_TOKEN_KEY) == null) {
map = new HashMap<String, String>();
session.setAttribute(EgovDoubleSubmitHelper.SESSION_TOKEN_KEY, map);
} else {
map = (Map<String, String>) session.getAttribute(EgovDoubleSubmitHelper.SESSION_TOKEN_KEY);
}
// First call (check session)
if (map.get(tokenKey) == null) {
map.put(tokenKey, EgovDoubleSubmitHelper.getNewUUID());
LOGGER.debug("[Double Submit] session token created({}) : {}", tokenKey, map.get(tokenKey));
}
buffer.append("<input type='hidden' name='").append(EgovDoubleSubmitHelper.PARAMETER_NAME).append("' value='").append(map.get(tokenKey)).append("'/>");
try {
pageContext.getOut().print(buffer.toString());
} catch (IOException e) {
throw new JspTagException("Error: IOException while writing to the user");
}
return SKIP_BODY;
}
public int doEndTag() throws JspException {
try {
pageContext.getOut().print(StringEscapeUtils.escapeJavaScript(string));
} catch (IOException x) {
throw new JspTagException(x);
}
return EVAL_PAGE;
}
public int doEndTag() throws JspException {
Locale locale = RequestContextUtils.getLocale((HttpServletRequest) pageContext.getRequest());
String result = StringUtil.formatBytes(bytes, locale);
try {
pageContext.getOut().print(result);
} catch (IOException x) {
throw new JspTagException(x);
}
return EVAL_PAGE;
}