List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:net.unicon.academus.civisselector.SearchShareeAction.java
License:Open Source License
public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); }// w ww . j a va2 s . com if (!e.getName().equals("action")) { String msg = "Argument 'e [Element]' must be an <action> element."; throw new IllegalArgumentException(msg); } if (owner == null) { String msg = "Argument 'owner+' cannot be null."; throw new IllegalArgumentException(msg); } // Handle. Attribute h = e.attribute("handle"); if (h == null) { String msg = "Element <action> is missing required attribute " + "'handle'."; throw new XmlFormatException(msg); } Handle handle = Handle.create(h.getValue()); // Choices. String[] choices = new String[0]; Attribute p = e.attribute("inpt"); if (p != null) { StringTokenizer tokens = new StringTokenizer(p.getValue(), ","); choices = new String[tokens.countTokens()]; for (int i = 0; tokens.hasMoreTokens(); i++) { choices[i] = tokens.nextToken(); } } return new SearchShareeAction(owner, handle, choices); }
From source file:net.unicon.academus.civisselector.SelectBasketAction.java
License:Open Source License
public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); }// w w w. ja v a 2 s . c om if (!e.getName().equals("action")) { String msg = "Argument 'e [Element]' must be an <action> element."; throw new IllegalArgumentException(msg); } if (owner == null) { String msg = "Argument 'owner+' cannot be null."; throw new IllegalArgumentException(msg); } // Handle. Attribute h = e.attribute("handle"); if (h == null) { String msg = "Element <action> is missing required attribute " + "'handle'."; throw new XmlFormatException(msg); } Handle handle = Handle.create(h.getValue()); // Choices. String[] choices = new String[0]; Attribute p = e.attribute("inpt"); if (p != null) { StringTokenizer tokens = new StringTokenizer(p.getValue(), ","); choices = new String[tokens.countTokens()]; for (int i = 0; tokens.hasMoreTokens(); i++) { choices[i] = tokens.nextToken(); } } return new SelectBasketAction(owner, handle, choices); }
From source file:net.unicon.academus.civisselector.SetShowMemberAction.java
License:Open Source License
public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); }//from w ww.jav a 2s. c o m if (!e.getName().equals("action")) { String msg = "Argument 'e [Element]' must be an <action> element."; throw new IllegalArgumentException(msg); } if (owner == null) { String msg = "Argument 'owner+' cannot be null."; throw new IllegalArgumentException(msg); } // Handle. Attribute h = e.attribute("handle"); if (h == null) { String msg = "Element <action> is missing required attribute " + "'handle'."; throw new XmlFormatException(msg); } Handle handle = Handle.create(h.getValue()); // Choices. String[] choices = new String[0]; Attribute p = e.attribute("inpt"); if (p != null) { StringTokenizer tokens = new StringTokenizer(p.getValue(), ","); choices = new String[tokens.countTokens()]; for (int i = 0; tokens.hasMoreTokens(); i++) { choices[i] = tokens.nextToken(); } } return new SetShowMemberAction(owner, handle, choices); }
From source file:net.unicon.academus.civisselector.ShowGroupAction.java
License:Open Source License
public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); }// w w w . jav a 2 s . com if (!e.getName().equals("action")) { String msg = "Argument 'e [Element]' must be an <action> element."; throw new IllegalArgumentException(msg); } if (owner == null) { String msg = "Argument 'owner+' cannot be null."; throw new IllegalArgumentException(msg); } // Handle. Attribute h = e.attribute("handle"); if (h == null) { String msg = "Element <action> is missing required attribute " + "'handle'."; throw new XmlFormatException(msg); } Handle handle = Handle.create(h.getValue()); // Choices. String[] choices = new String[0]; Attribute p = e.attribute("inpt"); if (p != null) { StringTokenizer tokens = new StringTokenizer(p.getValue(), ","); choices = new String[tokens.countTokens()]; for (int i = 0; tokens.hasMoreTokens(); i++) { choices[i] = tokens.nextToken(); } } return new ShowGroupAction(owner, handle, choices); }
From source file:net.unicon.academus.civisselector.ShowMemberAction.java
License:Open Source License
public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); }/* www . ja va2 s. c o m*/ if (!e.getName().equals("action")) { String msg = "Argument 'e [Element]' must be an <action> element."; throw new IllegalArgumentException(msg); } if (owner == null) { String msg = "Argument 'owner+' cannot be null."; throw new IllegalArgumentException(msg); } // Handle. Attribute h = e.attribute("handle"); if (h == null) { String msg = "Element <action> is missing required attribute " + "'handle'."; throw new XmlFormatException(msg); } Handle handle = Handle.create(h.getValue()); // Choices. String[] choices = new String[0]; Attribute p = e.attribute("inpt"); if (p != null) { StringTokenizer tokens = new StringTokenizer(p.getValue(), ","); choices = new String[tokens.countTokens()]; for (int i = 0; tokens.hasMoreTokens(); i++) { choices[i] = tokens.nextToken(); } } return new ShowMemberAction(owner, handle, choices); }
From source file:net.unicon.academus.civisselector.SubmitBasketAction.java
License:Open Source License
public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); }//ww w . j a v a 2 s .c om if (!e.getName().equals("action")) { String msg = "Argument 'e [Element]' must be an <action> element."; throw new IllegalArgumentException(msg); } if (owner == null) { String msg = "Argument 'owner+' cannot be null."; throw new IllegalArgumentException(msg); } // Handle. Attribute h = e.attribute("handle"); if (h == null) { String msg = "Element <action> is missing required attribute " + "'handle'."; throw new XmlFormatException(msg); } Handle handle = Handle.create(h.getValue()); // Choices. String[] choices = new String[0]; Attribute p = e.attribute("inpt"); if (p != null) { StringTokenizer tokens = new StringTokenizer(p.getValue(), ","); choices = new String[tokens.countTokens()]; for (int i = 0; tokens.hasMoreTokens(); i++) { choices[i] = tokens.nextToken(); } } return new SubmitBasketAction(owner, handle, choices); }
From source file:net.unicon.alchemist.access.AccessBroker.java
License:Open Source License
/** * Provides the broker defined by the specified <code>Element</code>. * First, this method checks the in-memory cache of brokers for one with the * handle indicated within the XML. If an instance is not found, this * method attempts to create a new broker instance based on the * specifications within the XML. If successful, this method stores the new * instance within the in-memory cache.// w w w . j av a 2s. c om * * @param e XML that defines the desired broker. * @return A broker with the characteristics specified in the XML. */ public static AccessBroker parse(Element e) { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); } if (!e.getName().equals("access-broker")) { String msg = "Argument 'e [Element]' must be an <access-broker> " + "element."; throw new IllegalArgumentException(msg); } AccessBroker rslt = null; // Call parse() in the specified implementation. Attribute impl = e.attribute("impl"); if (impl == null) { String msg = "Element <access-broker> is missing required " + "attribute 'impl'."; throw new IllegalArgumentException(msg); } try { Class c = Class.forName(impl.getValue()); Method m = c.getDeclaredMethod("parse", new Class[] { Element.class }); rslt = (AccessBroker) m.invoke(null, new Object[] { e }); } catch (Throwable t) { String msg = "Unable to create the specified broker: " + impl.getValue(); throw new RuntimeException(msg, t); } return rslt; }
From source file:net.unicon.alchemist.access.AccessBroker.java
License:Open Source License
/** * Constructs a new <code>AccessBroker</code> using information from the * specified XML./*from ww w . ja va 2 s . co m*/ * * @param e XML that defines the desired broker. * @return A broker with the characteristics specified in the XML. */ protected AccessBroker(Element e) { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); } if (!e.getName().equals("access-broker")) { String msg = "Argument 'e [Element]' must be an <access-broker> " + "element."; throw new IllegalArgumentException(msg); } // Handle. Attribute h = e.attribute("handle"); if (h == null) { String msg = "Element <access-broker> is missing required " + "attribute 'handle'."; throw new IllegalArgumentException(msg); } String val = h.getValue().trim(); if (val.length() == 0) { String msg = "Attribute 'handle' cannot be zero-length or contain " + "only whitespace."; throw new IllegalArgumentException(msg); } this.handle = val; // Add to collection. instances.put(val, this); }
From source file:net.unicon.alchemist.access.AccessRule.java
License:Open Source License
/** * Returns an array of AccessRules from parsing the given XML. * /*from w w w. j a va2 s . c om*/ * @param e * Format of the xml * <access impl="net.unicon.academus.apps.briefcase.BriefcaseAccessType"> * <type handle="READ" value="GRANT"/> * <type handle="EDIT" value="GRANT"/> * </access> * @return An array of AccessRule objects. */ public static AccessRule[] parse(Element e) { // assertions if (e == null) { throw new IllegalArgumentException("Argument 'e' cannot be null."); } if (!e.getName().equalsIgnoreCase("access")) { throw new IllegalArgumentException("Argument 'e' should be ab element with name 'access'."); } Attribute impl = e.attribute("impl"); if (impl == null) { String msg = "Element <access> must contain the attribute " + " 'impl'."; throw new IllegalArgumentException(msg); } Class c; Method m; AccessType[] access; List yList = e.selectNodes("type"); AccessRule[] rules = new AccessRule[yList.size()]; try { c = Class.forName(impl.getValue()); m = c.getDeclaredMethod("getAccessType", new Class[] { String.class }); for (int i = 0; i < yList.size(); i++) { Element a = (Element) yList.get(i); Attribute v = a.attribute("value"); Attribute h = a.attribute("handle"); if (v == null) { String msg = "Element <type> is missing required attribute " + "'value'."; throw new IllegalArgumentException(msg); } if (h == null) { String msg = "Element <type> is missing required attribute " + "'handle'."; throw new IllegalArgumentException(msg); } rules[i] = new AccessRule((AccessType) m.invoke(null, new Object[] { h.getValue() }), v.getValue().equalsIgnoreCase("GRANT") ? true : false); } } catch (Exception ex) { throw new RuntimeException("There was an error in parsing the Access Rule.", ex); } return rules; }
From source file:net.unicon.alchemist.access.permissions.PermissionsAccessBroker.java
License:Open Source License
public static AccessBroker parse(Element ce) { // Targets Access Broker -- Can be null. Element e = (Element) ce.selectSingleNode("targets/access-broker"); AccessBroker targets = null;//w ww . ja va 2 s. c o m if (e != null) targets = AccessBroker.parse(e); // Permissions Access Broker e = (Element) ce.selectSingleNode("permissions/access-broker"); if (e == null) throw new IllegalArgumentException("PermissionsAccessBroker requires an <access-broker> element " + "under element <permissions>."); AccessBroker permissions = AccessBroker.parse(e); // AccessType[] declaration e = (Element) ce.selectSingleNode("access"); if (e == null) throw new IllegalArgumentException("PermissionsAccessBroker requires an <access> element."); Attribute impl = e.attribute("impl"); if (impl == null) throw new IllegalArgumentException("The element <access> must contain an 'impl' attribute."); AccessType[] accessTypes = null; try { accessTypes = (AccessType[]) Class.forName(impl.getValue()).getMethod("getInstances", null).invoke(null, null); } catch (ClassNotFoundException ex1) { throw new RuntimeException("Could not find the class " + impl.getValue(), ex1); } catch (NoSuchMethodException ex2) { throw new RuntimeException("Could not find the Method 'getInstances' on class " + impl.getValue(), ex2); } catch (Exception ex3) { throw new RuntimeException("Unable to execute Method 'getInstances' on class " + impl.getValue(), ex3); } if (accessTypes == null || accessTypes.length == 0) throw new IllegalArgumentException("No AccessTypes found from <access> element declaration."); return new PermissionsAccessBroker(ce, targets, permissions, accessTypes); }