Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.nan21.dnet.core.web.controller.ui.extjs;
  
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  import  javax.servlet.http.Cookie;
  import  javax.servlet.http.HttpServletRequest;
  import  javax.servlet.http.HttpServletResponse;
 
 
 import  org.springframework.security.core.GrantedAuthority;
 import  org.springframework.security.core.context.SecurityContextHolder;
 
 public abstract class AbstractUiExtjsController extends AbstractDnetController {
 
List of extension file providers.
 
List of js content providers.
 
JSP page name which renders the html
 
 	protected String jspName;

Various settings to be propagated to client.
 
 
 	final static Logger logger = LoggerFactory
 
 	protected void _prepare(Map<StringObjectmodel,
 			HttpServletRequest request, HttpServletResponse response)
 			throws Exception {
 
 		request.setCharacterEncoding("UTF-8");
 		response.setCharacterEncoding("UTF-8");
 
 		if (.isDebugEnabled()) {
 			.debug("Handling request for ui.extjs: ",
 					request.getPathInfo());
 		}
 
 		String server = request.getServerName();
 		int port = request.getServerPort();
 		String contextPath = request.getContextPath();
 		String path = request.getServletPath();
 
 		String userRolesStr = null;
 
 		try {
 			SessionUser su = (SessionUser) SecurityContextHolder.getContext()
 					.getAuthentication().getPrincipal();
 			User user = (Usersu.getUser();
 			Params params = (Paramssu.getParams();
 			UserProfile profile = new UserProfile(su.isAdministrator(),
 					su.getRoles());
 			UserPreferences prefs = user.getPreferences();
 
 			..set(user);
 			..set(profile);
 			..set(params);
 
 			model.put("constantsJsFragment"this.getConstantsJsFragment());
 
 			model.put("userUsername"user.getUsername());
 			model.put("userDisplayName"user.getDisplayName());
 			model.put("userClientCode"user.getClientCode());
 			model.put("userClientId"user.getClientId().toString());
 			model.put("userSystemClient"params.isSystemClient());
 
 			model.put("extjsDateFormat"prefs.getExtjsDateFormat());
 			model.put("extjsTimeFormat"prefs.getExtjsTimeFormat());
			model.put("extjsDateTimeFormat"prefs.getExtjsDateTimeFormat());
			model.put("extjsAltFormats"prefs.getExtjsAltFormats());
			model.put("decimalSeparator"prefs.getDecimalSeparator());
			model.put("thousandSeparator"prefs.getThousandSeparator());
			Set<GrantedAuthority> roles = su.getAuthorities();
			StringBuffer sb = new StringBuffer();
			int i = 0;
			for (GrantedAuthority role : roles) {
				if (i > 0) {
					sb.append(",");
				}
				sb.append("\"" + role.getAuthority() + "\"");
				i++;
			}
			userRolesStr = sb.toString();
catch (ClassCastException e) {
			// not authenticated
		}
		String deploymentUrl = ((request.isSecure()) ? "https" : "http")
"://" + server + ((port != 80) ? (":" + port) : "")
contextPath;
		String uiUrl = deploymentUrl + path;
		model.put("deploymentUrl"deploymentUrl);
		model.put("uiUrl"uiUrl);
		model.put("product"this.getProductInfo());
		// extjs library and themes
		model.put("urlUiExtjsLib"getUiExtjsSettings().getUrlLib());
		model.put("urlUiExtjsThemes"getUiExtjsSettings().getUrlThemes());
		// DNet extjs components in core and modules
		model.put("urlUiExtjsCore"getUiExtjsSettings().getUrlCore());
		model.put("urlUiExtjsModules"getUiExtjsSettings().getUrlModules());
		model.put("urlUiExtjsModuleSubpath"getUiExtjsSettings()
		// translations for core and modules
		model.put("urlUiExtjsCoreI18n"getUiExtjsSettings().getUrlCoreI18n());
		model.put("urlUiExtjsModulesI18n"getUiExtjsSettings()
		model.put("shortLanguage"this.resolveLang(requestresponse));
		model.put("theme"this.resolveTheme(requestresponse));
		model.put("sysCfg_workingMode"this.getSystemConfig().getWorkingMode());
		model.put("userRolesStr"userRolesStr);
	}
	private void addConstant(StringBuffer sbString nameString value) {
		this.addConstant(sbnamevaluefalse);
	}
	private void addConstant(StringBuffer sbString nameString value,
			boolean isLast) {
		sb.append(name + ":\"" + value + "\"");
		if (!isLast) {
			sb.append(",\n");
		}
	}
	private synchronized String getConstantsJsFragment() {
		if (this. == null) {
			StringBuffer sb = new StringBuffer("Constants={");
			addConstant(sb"DATA_FORMAT_CSV".);
			addConstant(sb"DATA_FORMAT_HTML".);
			addConstant(sb"DATA_FORMAT_JSON".);
			addConstant(sb"DATA_FORMAT_XML".);
			addConstant(sb"DATA_FORMAT_PDF".);
			addConstant(sb"REQUEST_PARAM_THEME",
			addConstant(sb"REQUEST_PARAM_LANG".);
			addConstant(sb"REQUEST_PARAM_ACTION",
			addConstant(sb"REQUEST_PARAM_DATA".);
			addConstant(sb"REQUEST_PARAM_FILTER",
			addConstant(sb"REQUEST_PARAM_ADVANCED_FILTER",
			addConstant(sb"REQUEST_PARAM_PARAMS",
			addConstant(sb"REQUEST_PARAM_SORT".);
			addConstant(sb"REQUEST_PARAM_SENSE",
			addConstant(sb"REQUEST_PARAM_START",
			addConstant(sb"REQUEST_PARAM_SIZE".);
			addConstant(sb"REQUEST_PARAM_ORDERBY",
			addConstant(sb"REQUEST_PARAM_EXPORT_TITLE",
			addConstant(sb"REQUEST_PARAM_EXPORT_LAYOUT",
			addConstant(sb"REQUEST_PARAM_EXPORT_COL_NAMES",
			addConstant(sb"REQUEST_PARAM_EXPORT_COL_TITLES",
			addConstant(sb"REQUEST_PARAM_EXPORT_COL_WIDTHS",
			addConstant(sb"REQUEST_PARAM_SERVICE_NAME_PARAM",
			addConstant(sb"REQUEST_PARAM_EXPORT_FILTER_NAMES",
			addConstant(sb"REQUEST_PARAM_EXPORT_FILTER_TITLES",
			addConstant(sb"EXTJS_DATE_FORMAT".);
			addConstant(sb"EXTJS_TIME_FORMAT".);
			addConstant(sb"EXTJS_DATETIME_FORMAT",
			addConstant(sb"EXTJS_DATETIMESEC_FORMAT",
			addConstant(sb"EXTJS_MONTH_FORMAT".);
			addConstant(sb"EXTJS_MODEL_DATE_FORMAT",
			addConstant(sb"EXTJS_ALT_FORMATS".);
			addConstant(sb"DECIMAL_SEPARATOR".);
			addConstant(sb"THOUSAND_SEPARATOR".);
			addConstant(sb"DS_INFO".);
			addConstant(sb"DS_QUERY".);
			addConstant(sb"DS_INSERT".);
			addConstant(sb"DS_UPDATE".);
			addConstant(sb"DS_DELETE".);
			addConstant(sb"DS_SAVE".);
			addConstant(sb"DS_IMPORT".);
			addConstant(sb"DS_EXPORT".);
			addConstant(sb"DS_PRINT".);
			addConstant(sb"DS_RPC".true);
			sb.append("}");
		}
		return this.;
	}

Get files to be included provided by extensions for the given target. Target can be a frame's FQN or one of the IExtensions constants value.

Parameters:
targetName
baseUrl
Returns:
Throws:
Exception
	protected String getExtensionFiles(String targetNameString baseUrl)
			throws Exception {
		StringBuffer sb = new StringBuffer();
		for (IExtensionProvider provider : this.) {
			List<ExtensionFilefiles = provider.getFiles(targetName);
			for (ExtensionFile file : files) {
				String location = null;
				if (file.isRelativePath()) {
					location = baseUrl + "/" + file.getLocation();
else {
					location = file.getLocation();
				}
				if (file.isCss()) {
					sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\""
location + "\" />\n");
else if (file.isJs()) {
					sb.append("<script type=\"text/javascript\" src=\""
location + "\"></script>\n");
else {
					throw new Exception("Extension provider file `"
file.getLocation()
"` should be of type .js or .css");
				}
			}
		}
		return sb.toString();
	}

Get content provided by extensions for the given target. Target can be a frame's FQN or one of the IExtensions constants value.

Parameters:
targetName
Returns:
Throws:
Exception
	protected String getExtensionContent(String targetNamethrows Exception {
				"/* BEGIN EXTENSION CONTENT PROVIDER */");
			sb.append(provider.getContent(targetName));
		}
		sb.append("/* END EXTENSION CONTENT PROVIDER */");
		return sb.toString();
	}

Resolve the user's current theme from the cookie.

Parameters:
request
response
Returns:
Throws:
Exception
	private String resolveTheme(HttpServletRequest request,
			HttpServletResponse responsethrows Exception {
		Cookie[] cookies = request.getCookies();
		Cookie c = this.getCookie(cookies.);
		if (c == null) {
			String defaultValue = this.getSystemConfig().getSysParamValue(
			if (defaultValue == null || defaultValue.equals("")) {
			}
			c = this.createCookie(.defaultValue,
					60 * 60 * 24 * 365);
			response.addCookie(c);
		}
		String theme = request.getParameter(.);
		if (theme == null || theme.equals("")) {
			theme = c.getValue();
else {
			c.setMaxAge(0);
					60 * 60 * 24 * 365);
			response.addCookie(c);
		}
		return theme;
	}

Resolve the user's current language from the cookie.

Parameters:
request
response
Returns:
Throws:
Exception
	private String resolveLang(HttpServletRequest request,
			HttpServletResponse responsethrows Exception {
		Cookie[] cookies = request.getCookies();
		Cookie c = this.getCookie(cookies.);
		if (c == null) {
			String defaultValue = this.getSystemConfig().getSysParamValue(
			if (defaultValue == null || defaultValue.equals("")) {
				defaultValue = .;
			}
			c = this.createCookie(.defaultValue,
					60 * 60 * 24 * 365);
			response.addCookie(c);
		}
		String lang = request.getParameter(.);
		if (lang == null || lang.equals("")) {
			lang = c.getValue();
else {
			c.setMaxAge(0);
					60 * 60 * 24 * 365);
			response.addCookie(c);
		}
		return lang;
	}
	private Cookie getCookie(Cookie[] cookiesString name) {
		if (cookies != null) {
			for (int i = 0; i < cookies.length; i++) {
				Cookie cookie = cookies[i];
				if (name.equals(cookie.getName())) {
					return cookie;
				}
			}
		}
		return null;
	}
	private Cookie createCookie(String nameString valueint age) {
		Cookie c = new Cookie(namevalue);
		c.setMaxAge(age);
		return c;
	}

Get Extjs user interface specific a settings object. If it is null attempts to retrieve it from Spring context.

Returns:
		if (this. == null) {
		}
	}
	public void setUiExtjsSettings(UiExtjsSettings uiExtjsSettings) {
		this. = uiExtjsSettings;
	}
	public String getJspName() {
		return ;
	}
	public void setJspName(String jspName) {
		this. = jspName;
	}
	}
	public void setExtensionProviders(
			List<IExtensionProviderextensionProviders) {
		this. = extensionProviders;
	}
	}
			List<IExtensionContentProviderextensionContentProviders) {
		this. = extensionContentProviders;
	}
New to GrepCode? Check out our FAQ X