4,10 → 4,10 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.59 $ |
* @version $Revision: 1.60 $ |
* |
* Last modification: $Date: 2003/07/25 16:40:07 $ |
* $Id: PluginManager.java,v 1.59 2003/07/25 16:40:07 swalkenh Exp $ |
* Last modification: $Date: 2003/07/25 17:12:41 $ |
* $Id: PluginManager.java,v 1.60 2003/07/25 17:12:41 swalkenh Exp $ |
*/ |
|
package src.plugins; |
32,7 → 32,15 |
import javax.xml.parsers.DocumentBuilderFactory; |
import javax.xml.parsers.FactoryConfigurationError; |
import javax.xml.parsers.ParserConfigurationException; |
import javax.xml.transform.Transformer; |
import javax.xml.transform.TransformerConfigurationException; |
import javax.xml.transform.TransformerException; |
import javax.xml.transform.TransformerFactory; |
import javax.xml.transform.dom.DOMSource; |
import javax.xml.transform.stream.StreamResult; |
import org.w3c.dom.Attr; |
import org.w3c.dom.Document; |
import org.w3c.dom.Element; |
import org.w3c.dom.NamedNodeMap; |
import org.w3c.dom.Node; |
import org.w3c.dom.NodeList; |
56,7 → 64,7 |
* |
* @author Sascha Walkenhorst |
* |
* @version $Revision: 1.59 $ Last modification: $Date: 2003/07/25 16:40:07 $ |
* @version $Revision: 1.60 $ Last modification: $Date: 2003/07/25 17:12:41 $ |
*/ |
public class PluginManager implements TreeSelectionListener, |
PluginManagerInterface, |
1331,14 → 1339,18 |
} |
} |
|
|
/** |
* Transforms given node for specified plugin |
* |
* @param associatedPlugin name of associated plugin for the node |
* @param node the node |
* |
* @return the transformed node |
* |
* autor Y.Klassen, V.Zudova |
* |
* Last revision: 24-Jul-2003 |
*/ |
public Node transformsNode(String associatedPlugin, Node node) |
{ |
1350,5 → 1362,71 |
|
return transformer.transformNode(node); |
} |
|
|
/** |
* Saves the name of the default plugin in the configuration. In the former parsed |
* configuration file, saved in <code>configuration</code>, the attribute |
* <em>defaultplugin</em> is set to the actual value of <code>defaultPluginName</code>. |
* If the requiered element <em>PLUGINS</em> doesn't exist, or more than one exists |
* a new one will be created or the first will be taken, others are deleted. |
* |
* author Sascha Walkenhorst |
* |
* Last revision: 25-Jul-2003 by Sascha W. |
*/ |
public void saveConfiguration() { |
/* open element "PLUGINS" */ |
NodeList nodes = configuration.getElementsByTagName("PLUGINS"); |
|
/* for the attribute "defaultplugin" */ |
Attr attribute = null; |
|
/* check if there is one element with name "PLUGINS" */ |
if (nodes.getLength() == 0) { |
/* create a "PLUGINS"-node, make needed attribute named "defaultplugin" */ |
Node nodePlugins = ((Document) configuration.cloneNode(true)).createElement("PLUGINS").getElementsByTagName("PLUGINS").item(0); |
Element temp = (Element) nodePlugins; |
temp.setAttribute("defaultplugin", defaultPluginName); |
attribute = temp.getAttributeNode("defaultplugin"); |
|
/* set new node "PLUGINS" in configuration */ |
configuration.appendChild(nodePlugins); |
} |
else { |
/* case: more than one element with name "PLUGINS" |
* -> take first, delete other elements with name "PLUGINS" */ |
if (nodes.getLength() > 1) { |
// |
} |
Node nodePlugins = nodes.item(0); |
Element temp = (Element) nodePlugins; |
attribute = temp.getAttributeNode("defaultplugin"); |
} |
|
attribute.setNodeValue(defaultPluginName); |
|
|
/* save the configuration-file to file with path of "configurationFilePath" */ |
/* create input and output for transformation of configuration */ |
DOMSource source = new DOMSource(configuration); |
StreamResult result = new StreamResult(new File(configurationFilePath)); |
try { |
/* create transformer */ |
TransformerFactory tF = TransformerFactory.newInstance(); |
Transformer transformer = tF.newTransformer(); |
|
/* transform configuration */ |
transformer.transform(source, result); |
log(LogInterface.TYPE_INFO, "Document saved successfully."); |
} |
catch (TransformerConfigurationException tce) { |
log(LogInterface.TYPE_ERROR, "TransformerFactory error: " + |
tce.getMessage()); |
} |
catch (TransformerException te) { |
log(LogInterface.TYPE_ERROR, "Error transforming configuration file: " + te.getMessage()); |
} |
} |
|
} |