* @copyright OPEN CASCADE 2012
*/
-import org.apache.log4j.Logger;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.apache.log4j.Logger;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XDOM {
- private final static Logger logger = Logger.getLogger(XDOM.class);
+ private final static Logger LOGGER = Logger.getLogger(XDOM.class);
- public static org.w3c.dom.Document createDocument (String name) {
+ public static org.w3c.dom.Document createDocument (final String name) {
// ---------------------------------------------------------------
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
try {
return document;
}
catch (Exception error) {
- logger.error("Could not create document " + name + ", reason:", error);
+ LOGGER.error("Could not create document " + name + ", reason:", error);
return null;
}
}
- public static Node getChildNode (String name, Node from) {
+ public static Node getChildNode (final String name, final Node from) {
// --------------------------------------------------------
NodeList nlist = from.getChildNodes();
for (int i=0; i<nlist.getLength(); i++) {
Node cnode = nlist.item(i);
- if (cnode.getNodeName().equals(name)) return cnode;
+ if (cnode.getNodeName().equals(name)) {
+ return cnode;
+ }
}
return null;
}
for (int i=0; i<nlist.getLength(); i++) {
node = nlist.item(i);
String name = node.getNodeName();
- if (name.startsWith("#")) continue;
+ if (name.startsWith("#")) {
+ continue;
+ }
result.put(name, node);
}
return result;
}
- public static boolean saveDocument (File xmlOutputFile, org.w3c.dom.Document doc) {
+ public static boolean saveDocument (final File xmlOutputFile, final org.w3c.dom.Document doc) {
// ---------------------------------------------------------------------------------
// Open output stream where XML Document will be saved
// File xmlOutputFile = new File(fileName);
fos = new FileOutputStream(xmlOutputFile);
}
catch (FileNotFoundException error) {
- logger.error("Could not open the " + xmlOutputFile.getName() + " file, reason:", error);
+ LOGGER.error("Could not open the " + xmlOutputFile.getName() + " file, reason:", error);
return false;
}
// Use a Transformer for output
transformer = transformerFactory.newTransformer();
}
catch (TransformerConfigurationException error) {
- logger.error("Transformer configuration error, reason:", error);
+ LOGGER.error("Transformer configuration error, reason:", error);
return false;
}
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
}
catch (TransformerException error) {
- logger.error("Error during XML transformation, reason:", error);
+ LOGGER.error("Error during XML transformation, reason:", error);
}
return true;
}