use of org.dom4j.Node in project pentaho-platform by pentaho.
the class PentahoOFC4JChartHelper method generateChartJson.
@SuppressWarnings("unchecked")
public static String generateChartJson(Node chartNode, IPentahoResultSet data, boolean byRow, Log log) {
String chartType = null;
String factoryClassString = null;
try {
Node temp = chartNode.selectSingleNode(CHART_TYPE_NODE_LOC);
if (AbstractChartFactory.getValue(temp) != null) {
chartType = AbstractChartFactory.getValue(temp);
} else {
// This should NEVER happen.
chartType = CHART_TYPE_DEFAULT;
}
factoryClassString = (String) getChartFactories().get(chartType);
if (factoryClassString == null) {
throw new RuntimeException(Messages.getInstance().getErrorString("PentahoOFC4JChartHelper.ERROR_0001_FACTORY_INIT", chartType, // $NON-NLS-1$
factoryClassString));
} else {
Class factoryClass = Class.forName(factoryClassString);
// throw exception if factoryClass not found
IChartFactory factory = (IChartFactory) factoryClass.getConstructor(new Class[0]).newInstance(new Object[0]);
factory.setChartNode(chartNode);
factory.setLog(log);
if (byRow) {
factory.setData(PentahoDataTransmuter.pivot(data));
} else {
factory.setData(data);
}
return factory.convertToJson();
}
} catch (Exception e) {
logger.error(Messages.getInstance().getErrorString("PentahoOFC4JChartHelper.ERROR_0001_FACTORY_INIT", chartType, factoryClassString), // $NON-NLS-1$
e);
throw new RuntimeException(e);
}
}
use of org.dom4j.Node in project pentaho-platform by pentaho.
the class PieChartFactory method setupStyles.
@Override
protected void setupStyles() {
super.setupStyles();
Node temp = chartNode.selectSingleNode(ANIMATE_NODE_LOC);
if (getValue(temp) != null) {
// $NON-NLS-1$
animate = "true".equals(getValue(temp));
}
temp = chartNode.selectSingleNode(START_ANGLE_NODE_LOC);
if (getValue(temp) != null) {
startAngle = Integer.parseInt(getValue(temp));
}
}
use of org.dom4j.Node in project xwiki-platform by xwiki.
the class AbstractDocumentMojo method loadFromXML.
/**
* Loads a XWikiDocument from a XML file
*
* @param file the xml file to load
* @return the XWiki document loaded from XML
* @throws MojoExecutionException
*/
protected XWikiDocument loadFromXML(File file) throws MojoExecutionException {
XWikiDocument doc = new XWikiDocument(new DocumentReference("xwiki", "XWiki", "WebHome"));
FileInputStream fis;
try {
// Load the document as a XWikiDocument from XML
fis = new FileInputStream(file);
doc.fromXML(fis);
// get XML tree
FileReader fr = new FileReader(file);
SAXReader reader = new SAXReader();
Document domdoc;
domdoc = reader.read(fr);
Element root = domdoc.getRootElement();
// Lookup all class nodes, and add them to our xwiki context as BaseClass definitions
List<Node> classNodes = root.selectNodes("//xwikidoc/object/class");
for (Iterator<Node> it = classNodes.iterator(); it.hasNext(); ) {
BaseClass bClass = new BaseClass();
bClass.fromXML((Element) it.next());
context.addBaseClass(bClass);
}
fis.close();
return doc;
} catch (Exception e) {
throw new MojoExecutionException("Error loading XWikiDocument [" + file + "]", e);
}
}
use of org.dom4j.Node in project Spark by igniterealtime.
the class EmoticonManager method addEmoticonPack.
/**
* Loads an emoticon set.
*
* @param packName
* the name of the pack.
*/
public void addEmoticonPack(String packName) {
File emoticonSet = new File(EMOTICON_DIRECTORY, packName + ".adiumemoticonset");
if (!emoticonSet.exists()) {
emoticonSet = new File(EMOTICON_DIRECTORY, packName + ".AdiumEmoticonset");
}
if (!emoticonSet.exists()) {
emoticonSet = new File(EMOTICON_DIRECTORY, "Default.adiumemoticonset");
packName = "Default";
setActivePack("Default");
}
Map<String, Emoticon> emoticons = new LinkedHashMap<>();
final File plist = new File(emoticonSet, "Emoticons.plist");
// Create SaxReader and set to non-validating parser.
// This will allow for non-http problems to not break spark :)
final SAXReader saxParser = new SAXReader();
saxParser.setValidation(false);
try {
saxParser.setFeature("http://xml.org/sax/features/validation", false);
saxParser.setFeature("http://xml.org/sax/features/namespaces", false);
saxParser.setFeature("http://apache.org/xml/features/validation/schema", false);
saxParser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", false);
saxParser.setFeature("http://apache.org/xml/features/validation/dynamic", false);
saxParser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
saxParser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
saxParser.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
saxParser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
} catch (SAXException e) {
e.printStackTrace();
}
Document emoticonFile;
try {
emoticonFile = saxParser.read(plist);
} catch (DocumentException e) {
Log.error(e);
return;
}
Node root = emoticonFile.selectSingleNode("/plist/dict/dict");
List<?> keyList = root.selectNodes("key");
List<?> dictonaryList = root.selectNodes("dict");
Iterator<?> keys = keyList.iterator();
Iterator<?> dicts = dictonaryList.iterator();
while (keys.hasNext()) {
Element keyEntry = (Element) keys.next();
String key = keyEntry.getText();
Element dict = (Element) dicts.next();
String name = dict.selectSingleNode("string").getText();
// Load equivilants
final List<String> equivs = new ArrayList<>();
final List<?> equivilants = dict.selectNodes("array/string");
for (Object equivilant1 : equivilants) {
Element equivilant = (Element) equivilant1;
String equivilantString = equivilant.getText();
equivs.add(equivilantString);
}
final Emoticon emoticon = new Emoticon(key, name, equivs, emoticonSet);
for (String equivalent : emoticon.getEquivalants()) {
emoticons.put(equivalent, emoticon);
}
}
emoticonMap.put(packName, emoticons);
}
use of org.dom4j.Node in project Spark by igniterealtime.
the class PluginViewer method getPluginList.
public Collection<PublicPlugin> getPluginList(InputStream response) {
final List<PublicPlugin> pluginList = new ArrayList<>();
SAXReader saxReader = new SAXReader();
Document pluginXML = null;
try {
pluginXML = saxReader.read(response);
} catch (DocumentException e) {
Log.error(e);
}
List<? extends Node> plugins = pluginXML.selectNodes("/plugins/plugin");
for (Node plugin1 : plugins) {
PublicPlugin publicPlugin = new PublicPlugin();
String clazz;
String name = null;
try {
Element plugin = (Element) plugin1;
try {
String version = plugin.selectSingleNode("minSparkVersion").getText();
if (!isGreaterOrEqual(JiveInfo.getVersion(), version)) {
Log.error("Unable to load plugin " + name + " due to min version incompatibility.");
continue;
}
} catch (Exception e) {
Log.error("Unable to load plugin " + name + " due to no minSparkVersion.");
continue;
}
name = plugin.selectSingleNode("name").getText();
clazz = plugin.selectSingleNode("class").getText();
publicPlugin.setPluginClass(clazz);
publicPlugin.setName(name);
try {
String version = plugin.selectSingleNode("version").getText();
publicPlugin.setVersion(version);
String author = plugin.selectSingleNode("author").getText();
publicPlugin.setAuthor(author);
Node emailNode = plugin.selectSingleNode("email");
if (emailNode != null) {
publicPlugin.setEmail(emailNode.getText());
}
Node descriptionNode = plugin.selectSingleNode("description");
if (descriptionNode != null) {
publicPlugin.setDescription(descriptionNode.getText());
}
Node homePageNode = plugin.selectSingleNode("homePage");
if (homePageNode != null) {
publicPlugin.setHomePage(homePageNode.getText());
}
Node downloadNode = plugin.selectSingleNode("downloadURL");
if (downloadNode != null) {
String downloadURL = downloadNode.getText();
publicPlugin.setDownloadURL(downloadURL);
}
Node changeLogNode = plugin.selectSingleNode("changeLog");
if (changeLogNode != null) {
publicPlugin.setChangeLogURL(changeLogNode.getText());
}
Node readMeNode = plugin.selectSingleNode("readme");
if (readMeNode != null) {
publicPlugin.setReadMeURL(readMeNode.getText());
}
Node smallIcon = plugin.selectSingleNode("smallIcon");
if (smallIcon != null) {
publicPlugin.setSmallIconAvailable(true);
}
Node largeIcon = plugin.selectSingleNode("largeIcon");
if (largeIcon != null) {
publicPlugin.setLargeIconAvailable(true);
}
} catch (Exception e) {
Log.error("Error retrieving PluginInformation from xml.", e);
}
pluginList.add(publicPlugin);
} catch (Exception ex) {
ex.printStackTrace();
}
}
return pluginList;
}
Aggregations