| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.kuali.rice.kew.plugin; |
| 18 |
|
|
| 19 |
|
import org.apache.commons.lang.StringUtils; |
| 20 |
|
import org.jdom.Document; |
| 21 |
|
import org.jdom.Element; |
| 22 |
|
import org.jdom.JDOMException; |
| 23 |
|
import org.jdom.input.SAXBuilder; |
| 24 |
|
import org.kuali.rice.core.api.config.property.Config; |
| 25 |
|
import org.kuali.rice.core.xml.XmlException; |
| 26 |
|
|
| 27 |
|
import java.io.File; |
| 28 |
|
import java.io.IOException; |
| 29 |
|
import java.net.URL; |
| 30 |
|
import java.util.HashMap; |
| 31 |
|
import java.util.Iterator; |
| 32 |
|
import java.util.List; |
| 33 |
|
import java.util.Map; |
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@link |
| 38 |
|
|
| 39 |
|
@author |
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 62 (62) |
Complexity: 16 |
Complexity Density: 0.41 |
|
| 41 |
|
public class PluginConfigParser { |
| 42 |
|
|
| 43 |
|
private static final String PARAMETER_TAG = "parameter"; |
| 44 |
|
private static final String LISTENER_TAG = "listener"; |
| 45 |
|
private static final String LISTENER_CLASS_TAG = "listener-class"; |
| 46 |
|
private static final String RESOURCE_LOADER_TAG = "resourceLoader"; |
| 47 |
|
|
| 48 |
|
private static final String NAME_ATTRIBUTE = "name"; |
| 49 |
|
private static final String VALUE_ATTRIBUTE = "value"; |
| 50 |
|
private static final String CLASS_ATTRIBUTE = "class"; |
| 51 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
0
|
public PluginConfig parse(File configFile, Config parentConfig) throws IOException, XmlException {... |
| 53 |
0
|
return parse(configFile.toURI().toURL(), parentConfig); |
| 54 |
|
} |
| 55 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 56 |
0
|
public PluginConfig parse(URL url, Config parentConfig) throws IOException, XmlException {... |
| 57 |
0
|
SAXBuilder builder = new SAXBuilder(false); |
| 58 |
0
|
try { |
| 59 |
|
|
| 60 |
|
|
| 61 |
0
|
Document doc = builder.build(url); |
| 62 |
0
|
Element root = doc.getRootElement(); |
| 63 |
0
|
PluginConfig pluginConfig = new PluginConfig(url, parentConfig); |
| 64 |
0
|
parseResourceLoader(root, pluginConfig); |
| 65 |
0
|
parseListeners(root, pluginConfig); |
| 66 |
0
|
return pluginConfig; |
| 67 |
|
} catch (JDOMException e) { |
| 68 |
0
|
throw new PluginException("Error when parsing the plugin config file.", e); |
| 69 |
|
} |
| 70 |
|
} |
| 71 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 72 |
0
|
public void parseResourceLoader(Element element, PluginConfig pluginConfig) throws XmlException {... |
| 73 |
0
|
List loaderElements = element.getChildren(RESOURCE_LOADER_TAG); |
| 74 |
0
|
if (loaderElements.size() > 1) { |
| 75 |
0
|
throw new XmlException("Only one <resourceLoader> tag may be defined."); |
| 76 |
0
|
} else if (!loaderElements.isEmpty()) { |
| 77 |
0
|
Element loaderElement = (Element)loaderElements.get(0); |
| 78 |
0
|
String attributeClass = loaderElement.getAttributeValue(CLASS_ATTRIBUTE); |
| 79 |
0
|
if (StringUtils.isEmpty(attributeClass)) { |
| 80 |
0
|
throw new XmlException("<resourceLoader> element must define a 'class' attribute."); |
| 81 |
|
} |
| 82 |
0
|
pluginConfig.setResourceLoaderClassname(attributeClass); |
| 83 |
|
} |
| 84 |
|
} |
| 85 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 86 |
0
|
public void parseListeners(Element element, PluginConfig pluginConfig) throws XmlException {... |
| 87 |
0
|
List listeners = element.getChildren(LISTENER_TAG); |
| 88 |
0
|
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { |
| 89 |
0
|
pluginConfig.addListener(parseListenerProperties((Element)iterator.next())); |
| 90 |
|
} |
| 91 |
|
} |
| 92 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 93 |
0
|
private String parseListenerProperties(Element element) throws XmlException {... |
| 94 |
0
|
String listenerClass = element.getChildText(LISTENER_CLASS_TAG); |
| 95 |
0
|
if (org.apache.commons.lang.StringUtils.isEmpty(listenerClass)) { |
| 96 |
0
|
throw new XmlException("Listener Class tag must have a class property defined"); |
| 97 |
|
} |
| 98 |
0
|
return listenerClass; |
| 99 |
|
} |
| 100 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 101 |
0
|
public Map parseParameters(Element element) throws XmlException {... |
| 102 |
0
|
Map parsedParms = new HashMap(); |
| 103 |
0
|
List parameters = element.getChildren(PARAMETER_TAG); |
| 104 |
0
|
for (Iterator iterator = parameters.iterator(); iterator.hasNext();) { |
| 105 |
0
|
String [] parm = parseParameter((Element)iterator.next()); |
| 106 |
0
|
parsedParms.put(parm[0], parm[1]); |
| 107 |
|
} |
| 108 |
0
|
return parsedParms; |
| 109 |
|
} |
| 110 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 111 |
0
|
private String [] parseParameter(Element element) throws XmlException {... |
| 112 |
0
|
String name = element.getAttributeValue(NAME_ATTRIBUTE); |
| 113 |
0
|
String value = element.getAttributeValue(VALUE_ATTRIBUTE); |
| 114 |
0
|
if (org.apache.commons.lang.StringUtils.isEmpty(name)) { |
| 115 |
0
|
throw new XmlException("Parameter tag must have a name attribute defined"); |
| 116 |
|
} |
| 117 |
0
|
if (org.apache.commons.lang.StringUtils.isEmpty(value)) { |
| 118 |
0
|
throw new XmlException("Parameter tag must have a value attribute defined"); |
| 119 |
|
} |
| 120 |
0
|
return new String [] {name, value}; |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
|
} |