SysInfo/User ACL Info Custom Control & Java bean

// Java bean
package org.openntf.bstemplate.tools;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.openntf.domino.utils.XSPUtil;

public class SysInfo implements Serializable {

	private static final long serialVersionUID = -6709687405993515378L;

	private final int aclLevel;
	private final int aclOptions;
	private final String userName;

	public SysInfo() {
		this.userName = XSPUtil.getCurrentSession().getEffectiveUserName();
		this.aclLevel = XSPUtil.getCurrentDatabase().queryAccess(this.userName);
		this.aclOptions = XSPUtil.getCurrentDatabase().queryAccessPrivileges(this.userName);
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public String getAclLevel() {
		switch (this.aclLevel) {
		case 0:
			return "No access";
		case 1:
			return "Depositor";
		case 2:
			return "Reader";
		case 3:
			return "Author";
		case 4:
			return "Editor";
		case 5:
			return "Designer";
		case 6:
			return "Manager";
		default:
			return "don't know...";
		}

	}

	@SuppressWarnings("static-access")
	public List<String> getAclOptions() {
		/**
		 * •Database.DBACL_CREATE_DOCS (1) •Database.DBACL_DELETE_DOCS (2)
		 * •Database.DBACL_CREATE_PRIV_AGENTS (4)
		 * •Database.DBACL_CREATE_PRIV_FOLDERS_VIEWS (8)
		 * •Database.DBACL_CREATE_SHARED_FOLDERS_VIEWS (16)
		 * •Database.DBACL_CREATE_SCRIPT_AGENTS (32)
		 * •Database.DBACL_READ_PUBLIC_DOCS (64)
		 * •Database.DBACL_WRITE_PUBLIC_DOCS (128)
		 * •Database.DBACL_REPLICATE_COPY_DOCS (256)
		 */
		List<String> options = new ArrayList<String>();
		if ((this.aclOptions & XSPUtil.getCurrentDatabase().DBACL_CREATE_DOCS) > 0)
			options.add("DBACL_CREATE_DOCS");
		if ((this.aclOptions & XSPUtil.getCurrentDatabase().DBACL_DELETE_DOCS) > 0)
			options.add("DBACL_DELETE_DOCS");
		if ((this.aclOptions & XSPUtil.getCurrentDatabase().DBACL_CREATE_PRIV_AGENTS) > 0)
			options.add("DBACL_CREATE_PRIV_AGENTS");
		if ((this.aclOptions & XSPUtil.getCurrentDatabase().DBACL_CREATE_PRIV_FOLDERS_VIEWS) > 0)
			options.add("DBACL_CREATE_PRIV_FOLDERS_VIEWS");
		if ((this.aclOptions & XSPUtil.getCurrentDatabase().DBACL_CREATE_SCRIPT_AGENTS) > 0)
			options.add("DBACL_CREATE_SCRIPT_AGENTS");
		if ((this.aclOptions & XSPUtil.getCurrentDatabase().DBACL_CREATE_SHARED_FOLDERS_VIEWS) > 0)
			options.add("DBACL_CREATE_SHARED_FOLDERS_VIEWS");
		if ((this.aclOptions & XSPUtil.getCurrentDatabase().DBACL_READ_PUBLIC_DOCS) > 0)
			options.add("DBACL_READ_PUBLIC_DOCS");
		if ((this.aclOptions & XSPUtil.getCurrentDatabase().DBACL_WRITE_PUBLIC_DOCS) > 0)
			options.add("DBACL_WRITE_PUBLIC_DOCS");
		if ((this.aclOptions & XSPUtil.getCurrentDatabase().DBACL_REPLICATE_COPY_DOCS) > 0)
			options.add("DBACL_REPLICATE_COPY_DOCS");
		return options;
	}

	public String getUserName() {
		return userName;
	}

}

<!-- faces-config.xml -->
<managed-bean>
		<managed-bean-name>sysinfo</managed-bean-name>
		<managed-bean-class>org.openntf.bstemplate.tools.SysInfo
		</managed-bean-class>
		<managed-bean-scope>
			view</managed-bean-scope>
</managed-bean>

<!-- XSP -->
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
	<h3>System Information</h3>
	<div class="form-group">
		<label>Username</label>
		<xp:label value="#{javascript:sysinfo.userName}" id="label1"></xp:label>
	</div>
	<div class="form-group">
		<label>ACL Level</label>
		<xp:label value="#{javascript:sysinfo.aclLevel}" id="label2"></xp:label>
	</div>
	<div class="form-group">
		<label>Options</label>
		<xp:repeat id="repeat1" rows="30"
			value="#{javascript:sysinfo.aclOptions}" var="option">
			<xp:label value="#{javascript:option}" id="label3"></xp:label>
			<br />
		</xp:repeat>
	</div>
</xp:view>





I wanted this in every of my applications but always forgot about it. Now here it is. Create the Java resource, modify the faces-config.xml and create your Custom Control with the code. Place the CC wherever you want. You may notiice the Bootstrap CSS classes used here, so you guess in which environment this will look nice ;-)

XPages
Oliver Busse
June 13, 2014 1:15 PM
Rating
69

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...