use of javax.servlet.ServletContext in project sonarqube by SonarSource.
the class Resources method getActionMessage.
/**
* Gets the <code>ActionMessage</code> based on the
* <code>ValidatorAction</code> message and the <code>Field</code>'s arg
* objects.
*
* @param validator the Validator
* @param request the servlet request
* @param va Validator action
* @param field the validator Field
*/
public static ActionMessage getActionMessage(Validator validator, HttpServletRequest request, ValidatorAction va, Field field) {
Msg msg = field.getMessage(va.getName());
if ((msg != null) && !msg.isResource()) {
return new ActionMessage(msg.getKey(), false);
}
String msgKey = null;
String msgBundle = null;
if (msg == null) {
msgKey = va.getMsg();
} else {
msgKey = msg.getKey();
msgBundle = msg.getBundle();
}
if ((msgKey == null) || (msgKey.length() == 0)) {
return new ActionMessage("??? " + va.getName() + "." + field.getProperty() + " ???", false);
}
ServletContext application = (ServletContext) validator.getParameterValue(SERVLET_CONTEXT_PARAM);
MessageResources messages = getMessageResources(application, request, msgBundle);
Locale locale = RequestUtils.getUserLocale(request, null);
Arg[] args = field.getArgs(va.getName());
String[] argValues = getArgValues(application, request, messages, locale, args);
ActionMessage actionMessage = null;
if (msgBundle == null) {
actionMessage = new ActionMessage(msgKey, argValues);
} else {
String message = messages.getMessage(locale, msgKey, argValues);
actionMessage = new ActionMessage(message, false);
}
return actionMessage;
}
use of javax.servlet.ServletContext in project sonarqube by SonarSource.
the class JavascriptValidatorTag method createDynamicJavascript.
/**
* Generates the dynamic JavaScript for the form.
*
* @param config
* @param resources
* @param locale
* @param form
*/
private String createDynamicJavascript(ModuleConfig config, ValidatorResources resources, Locale locale, Form form) throws JspException {
StringBuffer results = new StringBuffer();
MessageResources messages = TagUtils.getInstance().retrieveMessageResources(pageContext, bundle, true);
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
ServletContext application = pageContext.getServletContext();
List actions = this.createActionList(resources, form);
final String methods = this.createMethods(actions, this.stopOnError(config));
String formName = form.getName();
jsFormName = formName;
if (jsFormName.charAt(0) == '/') {
String mappingName = TagUtils.getInstance().getActionMappingName(jsFormName);
ActionMapping mapping = (ActionMapping) config.findActionConfig(mappingName);
if (mapping == null) {
JspException e = new JspException(messages.getMessage("formTag.mapping", mappingName));
pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
throw e;
}
jsFormName = mapping.getAttribute();
}
results.append(this.getJavascriptBegin(methods));
for (Iterator i = actions.iterator(); i.hasNext(); ) {
ValidatorAction va = (ValidatorAction) i.next();
int jscriptVar = 0;
String functionName = null;
if ((va.getJsFunctionName() != null) && (va.getJsFunctionName().length() > 0)) {
functionName = va.getJsFunctionName();
} else {
functionName = va.getName();
}
results.append(" function " + jsFormName + "_" + functionName + " () { \n");
for (Iterator x = form.getFields().iterator(); x.hasNext(); ) {
Field field = (Field) x.next();
// retrieve from scope?))
if (field.isIndexed() || (field.getPage() != page) || !field.isDependency(va.getName())) {
continue;
}
String message = Resources.getMessage(application, request, messages, locale, va, field);
message = (message != null) ? message : "";
// prefix variable with 'a' to make it a legal identifier
results.append(" this.a" + jscriptVar++ + " = new Array(\"" + field.getKey() + "\", \"" + escapeQuotes(message) + "\", ");
results.append("new Function (\"varName\", \"");
Map vars = field.getVars();
// Loop through the field's variables.
Iterator varsIterator = vars.keySet().iterator();
while (varsIterator.hasNext()) {
String varName = (String) varsIterator.next();
Var var = (Var) vars.get(varName);
String varValue = Resources.getVarValue(var, application, request, false);
String jsType = var.getJsType();
// fieldValue
if (varName.startsWith("field")) {
continue;
}
String varValueEscaped = escapeJavascript(varValue);
if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) {
results.append("this." + varName + "=" + varValueEscaped + "; ");
} else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) {
results.append("this." + varName + "=/" + varValueEscaped + "/; ");
} else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) {
results.append("this." + varName + "='" + varValueEscaped + "'; ");
// So everyone using the latest format doesn't need to
// change their xml files immediately.
} else if ("mask".equalsIgnoreCase(varName)) {
results.append("this." + varName + "=/" + varValueEscaped + "/; ");
} else {
results.append("this." + varName + "='" + varValueEscaped + "'; ");
}
}
results.append(" return this[varName];\"));\n");
}
results.append(" } \n\n");
}
return results.toString();
}
use of javax.servlet.ServletContext in project che by eclipse.
the class CheBootstrapTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
systemPropertiesHelper = overrideSystemProperties();
cheBootstrap = new CheBootstrap();
servletContext = mock(ServletContext.class);
URL classesDirUrl = Thread.currentThread().getContextClassLoader().getResource(".");
File classesDir = new File(classesDirUrl.toURI());
che = new File(classesDir, "che");
che.mkdir();
userCongDir = new File(System.getenv(CHE_LOCAL_CONF_DIR));
userCongDir.mkdirs();
mockServletContext();
}
use of javax.servlet.ServletContext in project jodd by oblac.
the class ApplicationScopeInjector method outject.
public void outject(ActionRequest actionRequest) {
ScopeData[] outjectData = lookupScopeData(actionRequest);
if (outjectData == null) {
return;
}
Target[] targets = actionRequest.getTargets();
ServletContext context = actionRequest.getHttpServletRequest().getSession().getServletContext();
for (int i = 0; i < targets.length; i++) {
Target target = targets[i];
if (outjectData[i] == null) {
continue;
}
ScopeData.Out[] scopes = outjectData[i].out;
if (scopes == null) {
continue;
}
for (ScopeData.Out out : scopes) {
Object value = getTargetProperty(target, out);
context.setAttribute(out.name, value);
}
}
}
use of javax.servlet.ServletContext in project OpenAM by OpenRock.
the class XUIFilterTest method setUp.
@BeforeMethod
public void setUp() {
XUIState xuiState = mock(XUIState.class);
when(xuiState.isXUIEnabled()).thenReturn(true);
filter = new XUIFilter(xuiState);
FilterConfig filterConfig = mock(FilterConfig.class);
ServletContext servletContext = mock(ServletContext.class);
when(filterConfig.getServletContext()).thenReturn(servletContext);
when(servletContext.getContextPath()).thenReturn(CONTEXT);
filter.init(filterConfig);
}
Aggregations