List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:net.unicon.academus.apps.briefcase.engine.UpdateFileAction.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 .j av a 2s . co 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 UpdateFileAction(owner, handle, choices); }
From source file:net.unicon.academus.apps.briefcase.engine.UploadAction.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. j a va 2 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 UploadAction(owner, handle, choices); }
From source file:net.unicon.academus.apps.briefcase.engine.WelcomePageAction.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 . j ava 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 WelcomePageAction(owner, handle, choices); }
From source file:net.unicon.academus.apps.ConfigHelper.java
License:Open Source License
public static Method getParser(Element e, Class defaultClass) { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); }/* ww w . ja v a 2s . c o m*/ if (defaultClass == null) { String msg = "Argument 'defaultClass' cannot be null."; throw new IllegalArgumentException(msg); } Class implClass = defaultClass; // duh... Attribute impl = e.attribute("impl"); if (impl != null) { String implementationClassName = "unknown class"; try { implementationClassName = impl.getValue(); // exception for backwards compatibility of SsoEntry impl declaration // in configuration files. String ssoEntryClassName = SsoEntry.class.getName(); String ssoEntrySimpleClassName = SsoEntrySimple.class.getName(); if (ssoEntryClassName.equals(implementationClassName)) { LOG.warn("impl=\"" + ssoEntryClassName + "\" appeared in Gateway configuration. " + "This declaration is deprecated and instead should be impl=\"" + ssoEntrySimpleClassName + "\""); implementationClassName = ssoEntrySimpleClassName; } implClass = Class.forName(implementationClassName); } catch (Throwable t) { String msg = "Unable to create a parser for the specified implementation: " + impl.getValue(); throw new RuntimeException(msg, t); } } Method rslt = null; try { rslt = implClass.getDeclaredMethod("parse", new Class[] { Element.class }); } catch (Throwable t) { String msg = "Unable to create a parser for the specified implementation: " + implClass.getName(); throw new RuntimeException(msg, t); } return rslt; }
From source file:net.unicon.academus.apps.ConfigHelper.java
License:Open Source License
public static Element handle(Element configElement, boolean handleDataSource) { // Resolve imports List elist = configElement.selectNodes("//import"); if (!elist.isEmpty()) { for (Iterator it = elist.iterator(); it.hasNext();) { Element e = (Element) it.next(); String fname = null;/*w ww.j a v a 2 s . c o m*/ Attribute t = e.attribute("src"); if (t == null) { throw new IllegalArgumentException("Element <import> must contain an attribute 'src'."); } fname = t.getValue(); String xpath = null; t = e.attribute("select"); if (t == null) { throw new IllegalArgumentException("Element <import> must contain an attribute 'select'."); } xpath = t.getValue(); Element e2 = null; try { // first try the classloader URL url = ConfigHelper.class.getResource(fname); // next try an url if (url == null) { try { url = new URL(fname); } catch (MalformedURLException mue) { // try a file File f = new File(fname); if (!f.exists()) { throw new Exception(); // will get caught below } url = new URL("file", null, fname); } } e2 = (Element) ConfigHelper.handle((new SAXReader()).read(url.toString()).getRootElement()) .selectSingleNode(xpath); } catch (Exception ex) { throw new RuntimeException( "Unable to import requested document (" + fname + ") and xpath (" + xpath + ")", ex); } if (e2 == null) throw new IllegalArgumentException( "XPath expression [" + xpath + "] failed to resolve into an element."); // Replace the import with the selected node definition e.getParent().add(e2.detach()); e.detach(); } } elist = configElement.selectNodes("//copy-of"); if (!elist.isEmpty()) { for (Iterator it = elist.iterator(); it.hasNext();) { Element e = (Element) it.next(); String xpath = null; Attribute t = e.attribute("select"); if (t == null) { throw new IllegalArgumentException("Element <copy-of> must contain an attribute 'select'."); } xpath = t.getValue(); Element e2 = (Element) configElement.selectSingleNode(xpath); if (e2 == null) throw new IllegalArgumentException( "The given xpath expression did not resolve into a node: " + xpath); // Replace the copy-of with the selected node definition e.getParent().add(e2.createCopy()); e.detach(); } } elist = configElement.selectNodes("//value-of"); if (!elist.isEmpty()) { for (Iterator it = elist.iterator(); it.hasNext();) { Element e = (Element) it.next(); String xpath = null; Attribute t = e.attribute("select"); if (t == null) { throw new IllegalArgumentException("Element <value-of> must contain an attribute 'select'."); } xpath = t.getValue(); Element e2 = (Element) configElement.selectSingleNode(xpath); if (e2 == null) throw new IllegalArgumentException( "The given xpath expression did not resolve into a node: " + xpath); // Replace the value-of with the text of the selected node definition e.getParent().setText(e2.getText()); e.detach(); } } if (handleDataSource) { String jndiName = null; Element el = (Element) configElement.selectSingleNode("jndi-ref"); if (el != null) jndiName = el.getText(); // Bootstrap datasources... elist = configElement.selectNodes("//*[@needsDataSource='true']"); if (jndiName != null && !elist.isEmpty()) { try { DataSource ds = new AcademusDataSource(); for (Iterator it = elist.iterator(); it.hasNext();) { Element e = (Element) it.next(); Attribute impl = e.attribute("impl"); if (impl == null) throw new IllegalArgumentException("Elements with the 'needsDataSource' attribute " + " must have an 'impl' attribute."); Class.forName(impl.getValue()) .getDeclaredMethod("bootstrap", new Class[] { DataSource.class }) .invoke(null, new Object[] { ds }); } } catch (Throwable e) { throw new RuntimeException("Failed the DataSource bootstrapping", e); } } } return configElement; }
From source file:net.unicon.academus.apps.content.NavigateAction.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.java 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 NavigateAction(owner, handle, choices); }
From source file:net.unicon.academus.apps.content.WebContentPortlet.java
License:Open Source License
public void init(PortletConfig config) { // Instance Id. this.id = config.getInitParameter("Id"); // Initialize. IScreen peephole = null;/*from w w w. j ava 2 s . com*/ StateMachine m = null; try { int timer = Integer.parseInt(config.getInitParameter("userContextTimer")); userContextMap = TimedCache.getCache("ssoAuthentication", timer); PortletContext ctx = config.getPortletContext(); // Parse the config file. String configPath = (String) config.getInitParameter("configPath"); SAXReader reader = new SAXReader(); URL configUrl = ctx.getResource(configPath); Element configElement = (Element) reader.read(configUrl.toString()).selectSingleNode("web-content"); boolean useXsltc = Boolean.valueOf(configElement.attributeValue("useXsltc")); boolean cacheTemplates = true; if (configElement.attributeValue("cacheTemplates") != null) { cacheTemplates = Boolean.valueOf(configElement.attributeValue("cacheTemplates")); } // AJAX form population String ajaxCallbackUrl = null; Element ajaxElement = (Element) configElement.selectSingleNode("wcms-sso/ajax-callback-url"); if (ajaxElement != null) { ajaxCallbackUrl = ajaxElement.getText(); } // Obtain the sso broker. Element brkrElement = (Element) configElement.selectSingleNode("wcms-sso/access-broker"); AccessBroker ssoBroker = AccessBroker.parse(brkrElement); // Obtain the content broker. brkrElement = (Element) configElement.selectSingleNode("access-broker"); AccessBroker contentBroker = AccessBroker.parse(brkrElement); // Obtain the BodyXpath. Attribute x = configElement.attribute("body-xpath"); if (x == null) { String msg = "Element <web-content> is missing required " + "attribute 'body-xpath'."; throw new RuntimeException(msg); } String bodyXpath = x.getValue(); // Obtain the input tags for PageGuid and ProjectGuid. Attribute t = configElement.attribute("input-tags"); if (t == null) { String msg = "Element <web-content> is missing required " + "attribute 'input-tags'."; throw new RuntimeException(msg); } String inputTags = t.getValue(); // Parse the rewriting rules. List list = configElement.selectNodes("url-rewriting/pattern"); UrlRewritingRule[] rules = new UrlRewritingRule[list.size()]; for (int i = 0; i < rules.length; i++) { Element e = (Element) list.get(i); rules[i] = UrlRewritingRule.parse(e); } x = configElement.attribute("filter-config"); XHTMLFilterConfig filterConfig = null; if (x != null && x.getValue().length() > 0) { filterConfig = XHTMLFilter.getConfiguration(x.getValue()); } // Construct the application context. context = new WebContentApplicationContext(ssoBroker, contentBroker, bodyXpath, inputTags, filterConfig, rules, new SsoHandlerXML(), ajaxCallbackUrl); // Construct the rendering engine. URL xslUrl = ctx.getResource("/rendering/templates/layout.xsl"); Source trans = new StreamSource(xslUrl.toString()); IWarlockFactory fac = null; if (useXsltc) { fac = new XmlWarlockFactory(trans, TransletsConstants.xsltcTransformerFactoryImplementation, TransletsConstants.xsltcDebug, TransletsConstants.xsltcPackage, TransletsConstants.xsltcGenerateTranslet, TransletsConstants.xsltcAutoTranslet, TransletsConstants.xsltcUseClasspath, cacheTemplates); } else { fac = new XmlWarlockFactory(trans, cacheTemplates); } // Choose a peephole. Attribute p = configElement.attribute("peephole"); if (p != null) { String path = p.getValue(); if (path.trim().length() != 0) { URL screenUrl = ctx.getResource(path); Element e = (Element) reader.read(screenUrl.toString()).selectSingleNode("screen"); peephole = fac.parseScreen(e); } } // Construct the screens. list = new ArrayList(); Iterator it = ctx.getResourcePaths("/rendering/screens/content/").iterator(); while (it.hasNext()) { String path = (String) it.next(); URL screenUrl = ctx.getResource(path); Element e = (Element) reader.read(screenUrl.toString()).selectSingleNode("screen"); IScreen s = fac.parseScreen(e); list.add(s); } // Build the state machine. IScreen[] screens = (IScreen[]) list.toArray(new IScreen[0]); m = new StateMachine(context, screens, peephole); } catch (Throwable t) { String msg = "WebContentPortlet failed to initialize. See stack " + "trace below."; throw new RuntimeException(msg, t); } // Construct the user attributes collection. try { IEntityStore store = new JvmEntityStore(); IOption oName = store.createOption(net.unicon.penelope.Handle.create("id"), null, TypeText1024.INSTANCE); IOption oPswd = store.createOption(net.unicon.penelope.Handle.create("password"), null, TypeText1024.INSTANCE); IChoice choice = store.createChoice(net.unicon.penelope.Handle.create("user.login"), null, new IOption[] { oName, oPswd }, 2, 2); userAttributes = store.createChoiceCollection(net.unicon.penelope.Handle.create("userAttributes"), null, new IChoice[] { choice }); } catch (Throwable t) { String msg = "WebContentPortlet failed to initialize user " + "attributes. See stack trace below."; throw new RuntimeException(msg, t); } if (peephole != null) { initialQuery = new StateQueryImpl("<state />"); initialScreen = peephole; } else { initialQuery = null; initialScreen = m.getScreen(Handle.create("index")); } super.init(id, m); }
From source file:net.unicon.academus.apps.gateway.engine.ChangeCredentialsAction.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 w w . j av 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) { choices = p.getValue().split(","); } return new ChangeCredentialsAction(owner, handle, choices); }
From source file:net.unicon.academus.apps.gateway.engine.MainViewAction.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 . j a v a2 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) { choices = p.getValue().split(","); } return new MainViewAction(owner, handle, choices); }
From source file:net.unicon.academus.apps.gateway.engine.SingleIframeAction.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 w w . ja v a2s . co 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) { choices = p.getValue().split(","); } return new SingleIframeAction(owner, handle, choices); }