org.apache.struts.taglib.TagUtils Java Examples

The following examples show how to use org.apache.struts.taglib.TagUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AgnMessageTag.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public int doStartTag() throws JspException {
	String code = resolveCode();
	Locale locale = resolveLocale();
	String message = translate(code, locale, new Object[] {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9});

	if (message == null) {
		if (noExceptions) {
			message = "";
		} else {
			String strLocale = (locale == null) ? "default locale" : locale.toString();
			throw exception(messages.getMessage("message.message", "\"" + code + "\"", "\"" + ((bundle == null) ? "(default bundle)" : bundle) + "\"", strLocale));
		}
	}

	TagUtils.getInstance().write(pageContext, escape(message));

	return SKIP_BODY;
}
 
Example #2
Source File: AgnMessageTag.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private String resolveCode() throws JspException {
	if (key == null) {
		// Look up the requested property value
		Object code = TagUtils.getInstance().lookup(pageContext, name, property, scope);

		if (code instanceof String || code == null) {
			return (String) code;
		} else {
			throw exception(messages.getMessage("message.property", key));
		}
	}

	return key;
}
 
Example #3
Source File: AgnMessageTag.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private Locale resolveLocale() {
	// Use admin's configured language if available, otherwise use the client's browser language
	ComAdmin admin = AgnUtils.getAdmin(pageContext);

	if (admin != null) {
		Locale locale = admin.getLocale();
		if (locale != null) {
			return locale;
		}
	}

	// Use browser's locale as a fallback.
	return TagUtils.getInstance().getUserLocale(pageContext, Globals.LOCALE_KEY);
}
 
Example #4
Source File: AgnCheckboxTag.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected boolean isChecked() throws JspException {
    Object result = TagUtils.getInstance().lookup(this.pageContext, this.name, this.property, null);

    if (result instanceof String[]) {
        return ArrayUtils.contains((String[]) result, this.value);
    }

    if (result == null) {
        result = "";
    }

    String checked = result.toString();
    return checked.equalsIgnoreCase(this.value) || checked.equalsIgnoreCase("true") || checked.equalsIgnoreCase("yes") || checked.equalsIgnoreCase("on");
}
 
Example #5
Source File: MPageTag.java    From jivejdon with Apache License 2.0 5 votes vote down vote up
public String calUrl() {
	StringBuilder url = new StringBuilder();
	try {
		// Generate the URL to be encoded
		Map params = TagUtils.getInstance().computeParameters(pageContext, paramId, paramName, paramProperty, paramScope, name, property, scope,
				transaction);

		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

		url.append(request.getContextPath());
		url.append(page);

		if (params == null || params.isEmpty())
			return url.toString();
		Iterator keys = params.keySet().iterator();
		while (keys.hasNext()) {
			String key = (String) keys.next();
			Object value = params.get(key);
			url.append('/');
			url.append((String) value);
		}
	} catch (JspException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return url.toString();

}
 
Example #6
Source File: CourseNumberSuggestBox.java    From unitime with Apache License 2.0 5 votes vote down vote up
public int doStartTag() throws JspException {
       ActionMessages errors = null;

       try {
           errors = TagUtils.getInstance().getActionMessages(pageContext, Globals.ERROR_KEY);
       } catch (JspException e) {
           TagUtils.getInstance().saveException(pageContext, e);
           throw e;
       }
       
       String hint = null;
       if (errors != null && !errors.isEmpty()) {
       	 String message = null;
            Iterator reports = (getProperty() == null ? errors.get() : errors.get(getProperty()));
            while (reports.hasNext()) {
           	 ActionMessage report = (ActionMessage) reports.next();
           	 if (report.isResource()) {
           		 message = TagUtils.getInstance().message(pageContext, null, Globals.LOCALE_KEY, report.getKey(), report.getValues());
           	 } else {
           		 message = report.getKey();
           	 }
           	 if (message != null && !message.isEmpty()) {
           		 hint = (hint == null ? "" : hint + "<br>") + message;
           	 }
            }
       }
       
	// setStyleClass("unitime-DateSelectionBox");
	String onchange = getOnchange(); setOnchange(null);
	TagUtils.getInstance().write(pageContext, "<span name='UniTimeGWT:CourseNumberSuggestBox' configuration=\"" + getConfiguration() + "\"" +
			(hint == null ? "" : " error=\"" + hint + "\"") +
			(onchange == null ? "" : " onchange=\"" + onchange + "\"") +
			(getOuterStyle() == null ? "" : " style=\"" + getOuterStyle() + "\"" ) +
			">");
	super.doStartTag();
	TagUtils.getInstance().write(pageContext, "</span>");
	return EVAL_BODY_BUFFERED;
}
 
Example #7
Source File: Calendar.java    From unitime with Apache License 2.0 5 votes vote down vote up
public int doStartTag() throws JspException {
       ActionMessages errors = null;

       try {
           errors = TagUtils.getInstance().getActionMessages(pageContext, Globals.ERROR_KEY);
       } catch (JspException e) {
           TagUtils.getInstance().saveException(pageContext, e);
           throw e;
       }
       
       String hint = null;
       if (errors != null && !errors.isEmpty()) {
       	 String message = null;
            Iterator reports = (getProperty() == null ? errors.get() : errors.get(getProperty()));
            while (reports.hasNext()) {
           	 ActionMessage report = (ActionMessage) reports.next();
           	 if (report.isResource()) {
           		 message = TagUtils.getInstance().message(pageContext, null, Globals.LOCALE_KEY, report.getKey(), report.getValues());
           	 } else {
           		 message = report.getKey();
           	 }
           	 if (message != null && !message.isEmpty()) {
           		 hint = (hint == null ? "" : hint + "<br>") + message;
           	 }
            }
       }
       
	setStyleClass("unitime-DateSelectionBox");
	String onchange = getOnchange(); setOnchange(null);
	TagUtils.getInstance().write(pageContext, "<span name='UniTimeGWT:Calendar' format=\"" + getFormat() + "\"" +
			(hint == null ? "" : " error=\"" + hint + "\"") +
			(onchange == null ? "" : " onchange=\"" + onchange + "\"") +
			(getOuterStyle() == null ? "" : " style=\"" + getOuterStyle() + "\"" ) +
			" disabled=\"" + getDisabled() + "\"" +
			">");
	super.doStartTag();
	TagUtils.getInstance().write(pageContext, "</span>");
	return EVAL_BODY_BUFFERED;
}
 
Example #8
Source File: FilterProcessesForEmailTag.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public int doEndTag() throws JspException {
    Object predicateContainerObject = TagUtils.getInstance().lookup(pageContext, getPredicateContainer(), getScope());
    if (predicateContainerObject == null) {
        throw new JspException("predicateContainer cannot be null");
    }
    if (!PredicateContainer.class.isAssignableFrom(predicateContainerObject.getClass())) {
        throw new JspException("Specified predicateContainer does not correspond to a "
                + PredicateContainer.class.getSimpleName());
    }
    Object beanObject = TagUtils.getInstance().lookup(pageContext, getBean(), getScope());
    if (!PhdProgramEmailBean.class.isAssignableFrom(beanObject.getClass())) {
        throw new JspException("Specified bean does not correspond to a " + PhdProgramEmailBean.class.getSimpleName());
    }
    PredicateContainer<PhdIndividualProgramProcess> predicateContainer =
            (PredicateContainer<PhdIndividualProgramProcess>) predicateContainerObject;
    PhdProgramEmailBean bean = (PhdProgramEmailBean) beanObject;
    AndPredicate<PhdIndividualProgramProcess> searchPredicate = new AndPredicate<PhdIndividualProgramProcess>();
    searchPredicate.add(bean.getManagedPhdProgramsPredicate());
    searchPredicate.add(predicateContainer.getPredicate());

    List<PhdIndividualProgramProcess> processList = PhdIndividualProgramProcess.search(searchPredicate);

    int scope = (getScope() == null) ? PageContext.REQUEST_SCOPE : ScopeIntsMap.get(getScope());
    pageContext.setAttribute(id, processList, scope);
    return super.doEndTag();
}
 
Example #9
Source File: FilterProcessesTag.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public int doEndTag() throws JspException {
    Object predicateContainerObject = TagUtils.getInstance().lookup(pageContext, getPredicateContainer(), getScope());
    if (predicateContainerObject == null) {
        throw new JspException("predicateContainer cannot be null");
    }
    if (!PredicateContainer.class.isAssignableFrom(predicateContainerObject.getClass())) {
        throw new JspException("Specified predicateContainer does not correspond to a "
                + PredicateContainer.class.getSimpleName());
    }
    Object beanObject = TagUtils.getInstance().lookup(pageContext, getBean(), getScope());
    if (!SearchPhdIndividualProgramProcessBean.class.isAssignableFrom(beanObject.getClass())) {
        throw new JspException("Specified bean does not correspond to a "
                + SearchPhdIndividualProgramProcessBean.class.getSimpleName());
    }
    PredicateContainer<PhdIndividualProgramProcess> predicateContainer =
            (PredicateContainer<PhdIndividualProgramProcess>) predicateContainerObject;
    SearchPhdIndividualProgramProcessBean bean = (SearchPhdIndividualProgramProcessBean) beanObject;
    AndPredicate<PhdIndividualProgramProcess> searchPredicate = new AndPredicate<PhdIndividualProgramProcess>();
    searchPredicate.add(bean.getAndPredicate());
    searchPredicate.add(predicateContainer.getPredicate());

    List<PhdIndividualProgramProcess> processList = PhdIndividualProgramProcess.search(searchPredicate);

    int scope = (getScope() == null) ? PageContext.REQUEST_SCOPE : ScopeIntsMap.get(getScope());
    pageContext.setAttribute(id, processList, scope);
    return super.doEndTag();
}
 
Example #10
Source File: ExtensionI18NTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
private Locale getUserLocale() {
	// This is (currently) MVC-framework specific code.
	return TagUtils.getInstance().getUserLocale(pageContext, Globals.LOCALE_KEY);
}
 
Example #11
Source File: AgnOptionTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Generate an HTML %lt;option&gt; element.
 *
 * @throws javax.servlet.jsp.JspException
 * @since Struts 1.1
 */
@Override
protected String renderOptionElement()
        throws JspException {
    StringBuffer results = new StringBuffer("<option value=\"");

    if (filter) {
        results.append(TagUtils.getInstance().filter(this.value));
    }
    else {
        results.append(this.value);
    }
    results.append("\"");

    if (disabled) {
        results.append(" disabled=\"disabled\"");
    }

    if (this.selectTag().isMatched(this.value)) {
        results.append(" selected=\"selected\"");
    }

    if (getStyleClass() != null) {
        results.append(" style=\"");
        results.append(getStyleClass());
        results.append("\"");
    }

    if (styleId != null) {
        results.append(" id=\"");
        results.append(styleId);
        results.append("\"");
    }

    if (getStyleClass() != null) {
        results.append(" class=\"");
        results.append(getStyleClass());
        results.append("\"");
    }

    if (getDir() != null) {
        results.append(" dir=\"");
        results.append(getDir());
        results.append("\"");
    }

    if (getLang() != null) {
        results.append(" lang=\"");
        results.append(getLang());
        results.append("\"");
    }

    prepareOtherAttributes(results);

    results.append(">");

    results.append(text());

    results.append("</option>");

    return results.toString();
}
 
Example #12
Source File: AgnMessageTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
private JspException exception(String errorMessage) {
	JspException e = new JspException(errorMessage);
	TagUtils.getInstance().saveException(pageContext, e);
	return e;
}
 
Example #13
Source File: CollectionPagerTag.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
private String getMessageFromBundle(String key) throws JspException {
    return (getBundle() != null) ? ((TagUtils.getInstance().present(this.pageContext, getBundle(), I18N.getLocale()
            .toString(), key)) ? TagUtils.getInstance().message(this.pageContext, getBundle(), I18N.getLocale().toString(),
            key) : null) : null;
}
 
Example #14
Source File: EnumTagLib.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
private String getMessageFromBundle(String key) throws JspException {
    return (TagUtils.getInstance().present(this.pageContext, this.bundle, this.locale, key)) ? TagUtils.getInstance()
            .message(this.pageContext, this.bundle, this.locale, key) : null;
}
 
Example #15
Source File: GanttDiagramTagLib.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
private String getMessageFromBundle(String key) throws JspException {
    return (getBundle() != null) ? ((TagUtils.getInstance().present(this.pageContext, getBundle(), getGanttDiagramObject()
            .getLocale().toString(), key)) ? TagUtils.getInstance().message(this.pageContext, getBundle(),
            getGanttDiagramObject().getLocale().toString(), key) : null) : null;
}