Get agents schedule information using DXL


package com.consili;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import com.ibm.xsp.extlib.util.ExtLibUtil;
import lotus.domino.*;

// DXL require that the user has Maximum internet name and password access set to Manager
// Uses XML.java

public class DXLService implements Serializable {
	
	private static final long serialVersionUID = 1L;
	Session session;
	
	public DXLService() throws NotesException {
		session = ExtLibUtil.getCurrentSessionAsSignerWithFullAccess();
	}
	
	// Get all agents as XML
	public String getAgentDxl() throws NotesException {

		Database db = session.getCurrentDatabase();
		
		NoteCollection nc = db.createNoteCollection(false);
		nc.setSelectAgents(true);
		nc.buildCollection();
		DxlExporter dxl = session.createDxlExporter();
		return dxl.exportDxl(nc);
	}
	

	// Get all agent triggers from the XML
	public String getAgentData() throws NotesException, UnsupportedEncodingException{
		
		String ret = "";
		String result = getAgentDxl();
		XML database = new XML(result, "database");

		for(XML agent:database.children("agent")){
			XML trigger = agent.child("trigger");
			if(trigger!=null){
				XML schedule = trigger.child("schedule");
				if(schedule!=null){
					ret+= agent.string("name") + " / trigger: " + schedule.string("type") + " / " + schedule.string("hours")   + " hours / " + schedule.string("minutes") + " minutes<br>";
				}else{
					ret+= agent.string("name") + " / trigger: " + trigger.string("type") + "<br>";
				}
			}else{
				ret+= agent.string("name");
			}
		}
		return ret + "<br><br>";
	}
	
}


Also include this class XML.java

package com.consili;

import java.io.ByteArrayInputStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/* @link http://argonrain.wordpress.com/2009/10/27/000/
 * Quote: "All you need is this class, which you can of course customise however you like."
 * Permissions given on the blog to include in OpenNTF projects, quote: "Yes, you are free to use the code in any way that you like. Credits would be very much appreciated."
 */
public class XML implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unused")
	//private final Logger log = LogManager.getLogger();

	private final String name;
	private String content;
	private final Map<String, String> nameAttributes = new HashMap<String, String>();
	private final Map<String, ArrayList<XML>> nameChildren = new HashMap<String, ArrayList<XML>>();

	public XML(InputStream inputStream, String rootName) {
		//		DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
		//		builderFactory.createXMLEventReader(
		this(rootElement(inputStream, rootName));
	}

	public XML(String xml, String rootName) throws UnsupportedEncodingException {
		this(rootElement(toStream(xml), rootName));
	}

	public XML(File file, String rootName) {
		this(fileInputStream(file), rootName);
	}

	public XML(String rootName) {
		this.name = rootName;
	}

	private XML(Element element) {
		this.name = element.getNodeName();
		this.content = element.getTextContent();
		NamedNodeMap namedNodeMap = element.getAttributes();
		int n = namedNodeMap.getLength();
		for (int i = 0; i < n; i++) {
			Node node = namedNodeMap.item(i);
			String name = node.getNodeName();
			addAttribute(name, node.getNodeValue());
		}
		NodeList nodes = element.getChildNodes();
		n = nodes.getLength();
		for (int i = 0; i < n; i++) {
			Node node = nodes.item(i);
			int type = node.getNodeType();
			if (type == Node.ELEMENT_NODE) {
				XML child = new XML((Element) node);
				addChild(node.getNodeName(), child);
			}
		}
	}

	private static InputStream toStream(String source) throws UnsupportedEncodingException {
		return new ByteArrayInputStream(source.getBytes("utf-8"));
	}

	public void addAttribute(String name, String value) {
		nameAttributes.put(name, value);
	}

	private void addChild(String name, XML child) {
		ArrayList<XML> children = nameChildren.get(name);
		if (children == null) {
			children = new ArrayList<XML>();
			nameChildren.put(name, children);
		}
		children.add(child);
	}

	public String name() {
		return name;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String content() {
		return content;
	}

	public boolean hasContent() {
		//return NotesStrings.isBlank(content);
		return false;
	}

	public void addChild(XML xml) {
		addChild(xml.name(), xml);
	}

	public void addChildren(XML... xmls) {
		for (XML xml : xmls)
			addChild(xml.name(), xml);
	}

	public XML child(String name) {
		XML child = optChild(name);
		return child;
	}

	public XML optChild(String name) {
		ArrayList<XML> children = children(name);
		int n = children.size();
		if (n > 1)
			throw new RuntimeException("Could not find individual child node: " + name);
		return n == 0 ? null : children.get(0);
	}

	public boolean option(String name) {
		return optChild(name) != null;
	}

	public ArrayList<XML> children(String name) {
		ArrayList<XML> children = nameChildren.get(name);
		return children == null ? new ArrayList<XML>() : children;
	}

	public boolean hasChild(String name) {
		return nameChildren.containsKey(name);
	}

	public String string(String name) {
		String value = optString(name);
		if (value == null) {
			return "";
		}
		return value;
	}

	public boolean hasAttribute(String name) {
		return nameAttributes.containsKey(name);
	}

	public String optString(String name) {
		return nameAttributes.get(name);
	}

	public int integer(String name) {
		return Integer.parseInt(string(name));
	}

	public Integer optInteger(String name) {
		String string = optString(name);
		return string == null ? null : integer(name);
	}

	public double doubleValue(String name) {
		return Double.parseDouble(optString(name));
	}

	public Double optDouble(String name) {
		String string = optString(name);
		return string == null ? null : doubleValue(name);
	}

	private static DocumentBuilder getBuilder() throws ParserConfigurationException {
		DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
		return builderFactory.newDocumentBuilder();
	}

	private static Element rootElement(InputStream inputStream, String rootName) {
		try {
			Document document = getBuilder().parse(inputStream);
			Element rootElement = document.getDocumentElement();
			if (!rootElement.getNodeName().equals(rootName))
				throw new RuntimeException("Could not find root node: " + rootName);
			return rootElement;
		} catch (IOException exception) {
			throw new RuntimeException(exception);
		} catch (ParserConfigurationException exception) {
			throw new RuntimeException(exception);
		} catch (SAXException exception) {
			throw new RuntimeException(exception);
		} finally {
			if (inputStream != null) {
				try {
					inputStream.close();
				} catch (Exception exception) {
					throw new RuntimeException(exception);
				}
			}
		}
	}

	private static FileInputStream fileInputStream(File file) {
		try {
			return new FileInputStream(file);
		} catch (IOException exception) {
			throw new RuntimeException(exception);
		}
	}

}


Add the code above to the database and paste the code below into an XPages, no need for facesconfig (unless you want a bean)

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
	<xp:text escape="false" id="computedField4" tagName="div" style="" styleClass="">
		<xp:this.value><![CDATA[#{javascript:var dxl = new com.consili.DXLService();
return dxl.getAgentData();
}]]></xp:this.value>
	</xp:text>
</xp:view>
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...