Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   This is free and unencumbered software released into the public domain.
  
   Anyone is free to copy, modify, publish, use, compile, sell, or
   distribute this software, either in source code form or as a compiled
   binary, for any purpose, commercial or non-commercial, and by any
   means.
  
   In jurisdictions that recognize copyright laws, the author or authors
  of this software dedicate any and all copyright interest in the
  software to the public domain. We make this dedication for the benefit
  of the public at large and to the detriment of our heirs and
  successors. We intend this dedication to be an overt act of
  relinquishment in perpetuity of all present and future rights to this
  software under copyright law.
 
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
  */
 package base.jee;
 
 import java.net.URL;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 
 import base.Command;
 import base.Query;
 import base.task.Task;
Initialise and cache all objects associated with the base.jee package. This includes initialisation of:
  • database tables, configuration setting items,
  • user roles,
  • the global shortcut/menu bar,
  • a cache of the currently selected web page template package, and
  • default leading breadcrumb bar items.
 
 public class JeeBase {
 
 	public String cookieName = "base";
 
 	private Settings settings;
 	private RoleManager roles;
 	private List<BreadcrumbbaseBreadcrumbs = null;
 	private List<Shortcutshortcuts = new LinkedList<>();

In memory cache of all of the available templates
 
 	private TemplateManager templateManager = null;
 	private boolean debug = false;

Queries available to the public JSON API
 
 	private List<Queryqueries = new ArrayList<>();
Commands available to the public JSON API
 
 	private List<Commandcommands = new ArrayList<>();
 
 	private Task mailTask;
 	private Task expireTokensTask;
 	private Task logCleanupTask;
 
 	private API api;

Initialise all objects required before any part of the base.jee. package may be used. There should only ever be one instance in memory per application.

Parameters:
api
baseTemplateAmmendments
Throws:
java.io.IOException
	public JeeBase(API apiList<ResourcebaseTemplateAmmendmentsthrows IOException {
		this(apibaseTemplateAmmendments"base");
	}
	public JeeBase(API apiList<ResourcebaseTemplateAmmendmentsString cookiethrows IOException {
		 = cookie;
		this. = api;
		this. = api.getSettingsCache();
		this. = new LinkedList<>();
		this. = new RoleManager();
		.registerRole(new Role(."Audit Trail""Viewing system activity in the audit log."nulltrue));
		.registerRole(new Role(."People manage""Create, and manage people, inluding managing a persons role."nulltrue));
		.registerRole(new Role(."Group manage""Create, and manage who belongs to a groups."nulltrue));
		.registerRole(new Role(."System configuration""Update system configuration settings."nulltrue));
		.registerRole(new Role(."Template Manage""View and update the HTML and CSS for this site."nulltrue));
		 = new SendMailTask(api);
		TaskManager.registerRegularTask("mail", 10, );
		TaskManager.registerRegularTask("token.expiry", 300, );
		TaskManager.registerRegularTask("log.cleanup", 60*60, );
		// Setup some defaults for the required configuration settings
		if(.get("setting.cache.timeout"null) == null) {
			.set("setting.cache.timeout""10");
		}
		if(.get("smtp.hostname"null) == null) {
			.set("smtp.hostname""smtp.example.com");
		}
		if(.get("ldap.enabled"null) == null) {
			.set("ldap.enabled""false");
		}
		if(.get("ldap.url"null) == null) {
			.set("ldap.url""ldaps://ldap.example.com:636/");
		}
		if(.get("ldap.userdn"null) == null) {
			.set("ldap.userdn""uid={1},ou=People,dc=example,dc=com");
		}
		if(.get("stacktrace.show"null) == null) {
			.set("stacktrace.show""true");
		}
		if(.get("cookies.secure"null) == null) {
			.set("cookies.secure""false");
		}
		if(.get("session.expiry"null) == null) {
			.set("session.expiry"""+(60*60*4)); // Default to four hour expiry time limit
		}
		if(.get("frame.protection"null) == null) {
			.set("frame.protection""false");
		}
		if(.get("base.url"null) == null) {
			.set("base.url""");
		}
		if(.get("support_team.name"null) == null) {
			.set("support_team.name""Support Team");
		}
		if(.get("support_team.email"null) == null) {
			.set("support_team.email""support@example.com");
		}
		if(.get("support_team.url"null) == null) {
			.set("support_team.url""");
		}
		if(.get("terms_and_conditions"null) == null) {
			.set("terms_and_conditions""false");
		}
		// Define and/or refresh the contents of the default template.
		Map<StringResourceresources = new Hashtable<>();
		resources.put("account_activation_email_html.txt"new Resource("account_activation_email_html.txt"loadFromClasspath("/base/jee/resources/account_activation_email_html.txt"), false));
		resources.put("account_activation_email_text.txt"new Resource("account_activation_email_text.txt"loadFromClasspath("/base/jee/resources/account_activation_email_text.txt"), false));
		resources.put("activate_account.html"new Resource("activate_account.html"loadFromClasspath("/base/jee/resources/activate_account.html"), false));
		resources.put("audit.html"new Resource("audit.html"loadFromClasspath("/base/jee/resources/audit.html"), false));
		resources.put("authorisation_error.html"new Resource("authorisation_error.html"loadFromClasspath("/base/jee/resources/authorisation_error.html"), false));
		resources.put("exception.html"new Resource("exception.html"loadFromClasspath("/base/jee/resources/exception.html"), false));
		resources.put("favicon.ico"new Resource("favicon.ico"loadFromClasspath("/base/jee/resources/favicon.ico"), true));
		resources.put("fontawesome-webfont.eot"new Resource("fontawesome-webfont.eot"loadFromClasspath("/base/jee/resources/fontawesome-webfont.eot"), true));
		resources.put("fontawesome-webfont.ttf"new Resource("fontawesome-webfont.ttf"loadFromClasspath("/base/jee/resources/fontawesome-webfont.ttf"), true));
		resources.put("fontawesome-webfont.woff"new Resource("fontawesome-webfont.woff"loadFromClasspath("/base/jee/resources/fontawesome-webfont.woff"), true));
		resources.put("footer.html"new Resource("footer.html"loadFromClasspath("/base/jee/resources/footer.html"), false));
		resources.put("group_edit.html"new Resource("group_edit.html"loadFromClasspath("/base/jee/resources/group_edit.html"), false));
		resources.put("group_members.html"new Resource("group_members.html"loadFromClasspath("/base/jee/resources/group_members.html"), false));
		resources.put("group_roles.html"new Resource("group_roles.html"loadFromClasspath("/base/jee/resources/group_roles.html"), false));
		resources.put("groups.html"new Resource("groups.html"loadFromClasspath("/base/jee/resources/groups.html"), false));
		resources.put("header.html"new Resource("header.html"loadFromClasspath("/base/jee/resources/header.html"), false));
		resources.put("jquery-1.10.2.min.js"new Resource("jquery-1.10.2.min.js"loadFromClasspath("/base/jee/resources/jquery-1.10.2.min.js"), true));
		resources.put("jquery.qtip.min.js"new Resource("jquery.qtip.min.js"loadFromClasspath("/base/jee/resources/jquery.qtip.min.js"), true));
		resources.put("jquery.autosize.min.js"new Resource("jquery.autosize.min.js"loadFromClasspath("/base/jee/resources/jquery.autosize.min.js"), true));
		resources.put("password.js"new Resource("password.js"loadFromClasspath("/base/jee/resources/password.js"), true));
		resources.put("password_reset.html"new Resource("password_reset.html"loadFromClasspath("/base/jee/resources/password_reset.html"), false));
		resources.put("password_reset_complete.html"new Resource("password_reset_complete.html"loadFromClasspath("/base/jee/resources/password_reset_complete.html"), false));
		resources.put("password_reset_email_html.txt"new Resource("password_reset_email_html.txt"loadFromClasspath("/base/jee/resources/password_reset_email_html.txt"), false));
		resources.put("password_reset_email_text.txt"new Resource("password_reset_email_text.txt"loadFromClasspath("/base/jee/resources/password_reset_email_text.txt"), false));
		resources.put("people.html"new Resource("people.html"loadFromClasspath("/base/jee/resources/people.html"), false));
		resources.put("permission_denied.html"new Resource("permission_denied.html"loadFromClasspath("/base/jee/resources/permission_denied.html"), false));
		resources.put("person_edit.html"new Resource("person_edit.html"loadFromClasspath("/base/jee/resources/person_edit.html"), false));
		resources.put("person_new.html"new Resource("person_new.html"loadFromClasspath("/base/jee/resources/person_new.html"), false));
		resources.put("resource.html"new Resource("resource.html"loadFromClasspath("/base/jee/resources/resource.html"), false));
		resources.put("settings.html"new Resource("settings.html"loadFromClasspath("/base/jee/resources/settings.html"), false));
		resources.put("setup.html"new Resource("setup.html"loadFromClasspath("/base/jee/resources/setup.html"), false));
		resources.put("signup_confirmation_email_html.txt"new Resource("signup_confirmation_email_html.txt"loadFromClasspath("/base/jee/resources/signup_confirmation_email_html.txt"), false));
		resources.put("signup_confirmation_email_text.txt"new Resource("signup_confirmation_email_text.txt"loadFromClasspath("/base/jee/resources/signup_confirmation_email_text.txt"), false));
		resources.put("signup_confirmation_fail.html"new Resource("signup_confirmation_fail.html"loadFromClasspath("/base/jee/resources/signup_confirmation_fail.html"), false));
		resources.put("signup_details.html"new Resource("signup_details.html"loadFromClasspath("/base/jee/resources/signup_details.html"), false));
		resources.put("suspended_accounts.html"new Resource("suspended_accounts.html"loadFromClasspath("/base/jee/resources/suspended_accounts.html"), false));
		resources.put("throttled.html"new Resource("throttled.html"loadFromClasspath("/base/jee/resources/throttled.html"), false));
		resources.put("signin.html"new Resource("signin.html"loadFromClasspath("/base/jee/resources/signin.html"), false));
		resources.put("style.css"new Resource("style.css"loadFromClasspath("/base/jee/resources/style.css"), false));
		resources.put("template.html"new Resource("template.html"loadFromClasspath("/base/jee/resources/template.html"), false));
		resources.put("templates.html"new Resource("templates.html"loadFromClasspath("/base/jee/resources/templates.html"), false));
		resources.put("terms_and_conditions.html"new Resource("terms_and_conditions.html"loadFromClasspath("/base/jee/resources/terms_and_conditions.html"), false));
		if(baseTemplateAmmendments != null) {
			for(Resource resource : baseTemplateAmmendments) {
				resources.put(resource.getName(), resource);
			}
		}
		 = new TemplateManager(apiresources.values());
	}
	public API getAPI() {
		return ;
	}
	public void cleanup() throws InterruptedException {
		TaskManager.unregisterRegularTask("mail");
		TaskManager.unregisterRegularTask("token.expiry");
		TaskManager.unregisterRegularTask("log.cleanup");
		TaskManager.shutdown();
	}
	}
	public void setBaseBreadcrumbs(List<BreadcrumbbaseBreadcrumbs) {
		this. = baseBreadcrumbs;
	}
	public Settings getSettings() {
		return ;
	}

List of available system roles that were registered on application startup. This list includes all roles required by the base.jee package plus any other roles that are registered by the developer using the jee.getRoles().registerRole()

	public RoleManager getRoles() {
		return ;
	}
	private byte[] loadFromClasspath(String namethrows IOException {
		URL url = JeeBase.class.getResource(name);
		byte[] buffer = new byte[1024*25];
		int length;
		InputStream in = url.openStream();
		while ((length = bin.read(buffer)) > 0) {
			bout.write(buffer, 0, length);
		}
		return bout.toByteArray();
	}
	public ST getPage(User uString namethrows IOException {
		String site = (u == null?null:u.getSite());
		// TODO: Support user override of site default template
		if(page == null) {
			log("SEVERE""JeeBase.getPage() invoked with missing or invalid template file named '" + name + "'");
			return null;
		}
		page.add("formurl".get("base.url"""));
		page.add("user"u);
		for(Shortcut s : ) {
			if(s.getRequiredRole() == null || (u != null && u.hasRole(s.getRequiredRole()))) {
				page.add("shortcuts"s);
			}
		}
		if(u != null && u.hasRole(...)) {
			page.add("shortcuts"new Shortcut("People""/people"));
		}
		if(u != null && u.hasRole(...)) {
			page.add("shortcuts"new Shortcut("Audit""/audit"));
		}
		if(u != null && u.hasRole(...)) {
			page.add("shortcuts"new Shortcut("Settings""/settings"));
		}
		if(u != null && u.hasRole(...)) {
			page.add("shortcuts"new Shortcut("Template""/templates"));
		}
		if(u == null || !u.isAuthenticated()) {
			page.add("shortcuts"new Shortcut("Sign in""/signin"));
else {
			page.add("shortcuts"new Shortcut("Sign out""/signout"));
		}
			page.add("breadcrumbs"b);
		}
		page.add("headers"true);
		return page;
	}
	public void log(String levelString messageResourceUid... resourcesthrows IOException {
		log(levelmessagenullresources);
	}
	public void log(String levelString messageUser userResourceUid... resourcesthrows IOException {
		if(! && level.equalsIgnoreCase("debug")) {
			return;
		}
		try {
			.log(levelusermessageresources);
catch(Exception e) {
			Date date = new Date();
			..println("[" + date + "] " + (user == null || user.getIp() == null?"-":user.getIp()) + " " + level + " " + message);
		}
	}
	public void setDebug(boolean debug) {
		this. = debug;
	}
	public void add(Shortcut shortcut) {
		.add(shortcut);
	}

Make a Command available to the API servlet.

Parameters:
command
	public void add(Command command) {
		.add(command);
	}

Make a Command available to the API servlet.

Deprecated:
Use the simpler add() method instead.
Parameters:
command
	public void registerApiCommand(Command command) {
		.add(command);
	}

Make a Query available to the API servlet.

Parameters:
query
	public void add(Query query) {
		.add(query);
	}

Make a Query available to the API servlet.

Deprecated:
Use the simpler add() method instead.
Parameters:
query
	public void registerApiQuery(Query query) {
		.add(query);
	}
	public List<QuerygetApiQueries() {
		return ;
	}
		return ;
	}
New to GrepCode? Check out our FAQ X