Skip to content

Commit

Permalink
changed to DOM4J
Browse files Browse the repository at this point in the history
  • Loading branch information
chanwit authored and graemerocher committed Apr 15, 2009
1 parent 875fcf0 commit 2a8e0cd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 54 deletions.
Binary file added grails/lib/jaxen-1.1.1.jar
Binary file not shown.
Expand Up @@ -21,17 +21,17 @@
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.grails.compiler.injection.GrailsInjectionOperation;
import org.codehaus.groovy.grails.compiler.support.GrailsResourceLoader;

import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.XPath;
import org.dom4j.io.SAXReader;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -41,6 +41,7 @@
*
* @author Steven Devijver
* @author Graeme Rocher
* @author Chanwit Kaewkasi
*
* @since 0.1
*
Expand All @@ -64,7 +65,7 @@ public void setInjectionOperation(GrailsInjectionOperation injectionOperation) {
}

public GrailsApplicationFactoryBean() {
super();
super();
}


Expand All @@ -81,20 +82,18 @@ public void afterPropertiesSet() throws Exception {
inputStream = descriptor.getInputStream();

// Get all the resource nodes in the descriptor.
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList grailsClasses = (NodeList) xpath.evaluate(
"/grails/resources/resource",
new InputSource(inputStream),
XPathConstants.NODESET);
SAXReader reader = new SAXReader();
XPath xpath = DocumentHelper.createXPath("/grails/resources/resource");
List grailsClasses = xpath.selectNodes(reader.read(inputStream));

// Each resource node should contain a full class name,
// so we attempt to load them as classes.
for (int i = 0; i < grailsClasses.getLength(); i++) {
Node node = grailsClasses.item(i);
for (int i = 0; i < grailsClasses.size(); i++) {
Element node = (Element) grailsClasses.get(i);
try {
classes.add(classLoader.loadClass(node.getTextContent()));
classes.add(classLoader.loadClass(node.getText()));
} catch (ClassNotFoundException e) {
LOG.warn("Class with name ["+node.getTextContent()+"] was not found, and hence not loaded. Possible empty class or script definition?");
LOG.warn("Class with name ["+node.getText()+"] was not found, and hence not loaded. Possible empty class or script definition?");
}
}
} finally {
Expand Down
Expand Up @@ -23,22 +23,19 @@
import org.codehaus.groovy.grails.commons.GrailsResourceUtils;
import org.codehaus.groovy.grails.exceptions.GrailsConfigurationException;
import org.codehaus.groovy.grails.plugins.support.aware.GrailsApplicationAware;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.XPath;
import org.dom4j.DocumentHelper;
import org.dom4j.io.SAXReader;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -52,6 +49,7 @@
* set of resources
*
* @author Graeme Rocher
* @author Chanwit Kaewkasi
* @since 0.6
*
* <p/>
Expand Down Expand Up @@ -117,25 +115,22 @@ private void configureMetaManager(Resource[] pluginDescriptors) {

try {
inputStream = pluginDescriptor.getInputStream();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(inputStream);
Element pluginElement = doc.getDocumentElement();
SAXReader reader = new SAXReader();
Document doc = reader.read(inputStream);
Element pluginElement = doc.getRootElement();

String pluginName = pluginElement.getAttribute("name");
String pluginVersion = pluginElement.getAttribute("version");
String pluginName = pluginElement.attribute("name").getText();
String pluginVersion = pluginElement.attribute("version").getText();

if(StringUtils.isBlank(pluginName)) throw new GrailsConfigurationException("Plug-in descriptor ["+pluginDescriptor+"] doesn't specify a plug-in name. It must be corrupted, try re-install the plug-in");
if(StringUtils.isBlank(pluginVersion)) throw new GrailsConfigurationException("Plug-in descriptor ["+pluginDescriptor+"] with name ["+pluginName+"] doesn't specify a plug-in version. It must be corrupted, try re-install the plug-in");

XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList) xpath.evaluate(
"/plugin/resources/resource",
doc,
XPathConstants.NODESET);
XPath xpath = DocumentHelper.createXPath("/plugin/resources/resource");
List nodes = xpath.selectNodes(doc);
List pluginResources = new ArrayList();
for (int j = 0; j < nodes.getLength(); j++) {
Node node = nodes.item(j);
pluginResources.add(node.getTextContent());
for (int j = 0; j < nodes.size(); j++) {
Element node = (Element) nodes.get(j);
pluginResources.add(node.getText());
}

PluginMeta pluginMeta = new PluginMeta(pluginName, pluginVersion);
Expand Down
Expand Up @@ -19,20 +19,18 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.XPath;
import org.dom4j.io.SAXReader;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -41,6 +39,7 @@
* A factory bean for loading the GrailsPluginManager instance
*
* @author Graeme Rocher
* @author Chanwit Kaewkasi
* @since 0.4
*
*/
Expand Down Expand Up @@ -87,14 +86,13 @@ public void afterPropertiesSet() throws Exception {

try {
inputStream = descriptor.getInputStream();
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList) xpath.evaluate(
"/grails/plugins/plugin",
new InputSource(inputStream),
XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
final String pluginName = node.getTextContent();
SAXReader reader = new SAXReader();
XPath xpath = DocumentHelper.createXPath("/grails/plugins/plugin");
List nodes = xpath.selectNodes(reader.read(inputStream));

for (int i = 0; i < nodes.size(); i++) {
Element node = (Element) nodes.get(i);
final String pluginName = node.getText();
classes.add(classLoader.loadClass(pluginName));
}
} finally {
Expand Down

0 comments on commit 2a8e0cd

Please sign in to comment.