public synchronized boolean convert(String propertiesFileName, String xmlOutputFileName) throws FileNotFoundException, IOException { FileInputStream input = new FileInputStream(propertiesFileName); Properties props = new Properties(); props.load(input); convertConfigToXML(props, xmlOutputFileName); processListedElements(elementsForProcessing); /* Make sure we have the latest output location */ outputLocation = Utils.getCurrentOutputLocation(); printXMLDocument(hostDoc, outputLocation + "/xml/" + Utils.hostXMLFile); printXMLDocument(serviceDoc, outputLocation + "/xml/" + Utils.serviceXMLFile); printXMLDocument(contactDoc, outputLocation + "/xml/" + Utils.contactXMLFile); printXMLDocument(timeperiodDoc, outputLocation + "/xml/" + Utils.timeperiodXMLFile); printXMLDocument(contactDoc, outputLocation + "/xml/" + Utils.contactXMLFile); printXMLDocument(commandDoc, outputLocation + "/xml/" + Utils.commandXMLFile); printXMLDocument(contactgroupDoc, outputLocation + "/xml/" + Utils.contactgroupXMLFile); printXMLDocument(servicegroupDoc, outputLocation + "/xml/" + Utils.servicegroupXMLFile); printXMLDocument(hostgroupDoc, outputLocation + "/xml/" + Utils.hostgroupXMLFile); printXMLDocument(hostescalationDoc, outputLocation + "/xml/" + Utils.hostescalationXMLFile); printXMLDocument( serviceescalationDoc, outputLocation + "/xml/" + Utils.serviceescalationXMLFile); printXMLDocument(serviceextinfoDoc, outputLocation + "/xml/" + Utils.serviceextinfoXMLFile); printXMLDocument(hostextinfoDoc, outputLocation + "/xml/" + Utils.hostextinfoXMLFile); printXMLDocument(hostdependencyDoc, outputLocation + "/xml/" + Utils.hostdependencyXMLFile); printXMLDocument( servicedependencyDoc, outputLocation + "/xml/" + Utils.servicedependencyXMLFile); return true; }
private void convertConfigToXML(Properties props, String xmlFileName) throws IOException, FileNotFoundException { Namespace schemaNameSpace = Namespace.getNamespace("blue", Utils.schemaHost + Utils.schemaContext + "mainblueconfig"); Element root = new Element("blue_config", schemaNameSpace); Document doc = new Document(root); LinkedList<String> list; for (String s : Utils.elementOrder) { String propertyValue = props.getProperty(s); if (propertyValue != null) { if (s.equals("cfg_file")) { list = retrieveRepeatingElements("cfg_file", configLocation); elementsForProcessing.addAll(list); addRepeatingElements(root, list, schemaNameSpace); } else if (s.equals("cfg_dir")) { list = retrieveRepeatingElements("cfg_dir", configLocation); elementsForProcessing.addAll(list); addRepeatingElements(root, list, schemaNameSpace); } else if (s.equals("broker_module")) { list = retrieveRepeatingElements("broker_module", configLocation); addRepeatingElements(root, list, schemaNameSpace); } else if (s.equals("resource_file")) { elementsForProcessing.add("resource_file = " + propertyValue); createXMLRepresentation(root, s, propertyValue, schemaNameSpace); } else { createXMLRepresentation(root, s, propertyValue, schemaNameSpace); } } } outputLocation = Utils.getCurrentOutputLocation(); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); FileOutputStream output = new FileOutputStream(outputLocation + "/xml/" + xmlFileName); outputter.output(doc, output); }
private void convertResourceFileToXML(BufferedReader resourceFileHandle) throws IOException, FileNotFoundException { /* Update outputLocation */ outputLocation = Utils.getCurrentOutputLocation(); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); FileOutputStream output = new FileOutputStream(outputLocation + "/xml/macros.xml"); Namespace schemaNamespace = Namespace.getNamespace("macros", Utils.schemaHost + Utils.schemaContext + "macros"); Element root = new Element("macros", schemaNamespace); Document doc = new Document(root); String line = resourceFileHandle.readLine(); while (resourceFileHandle.readLine() != null) { line = line.trim(); if (line.indexOf("$USER") == 0) { Element macro = new Element("macro", schemaNamespace); Attribute macroId = new Attribute("macro_id", line.split("=")[0]); macro.setAttribute(macroId); createXMLRepresentation(macro, "macro_value", line.split("=")[1], schemaNamespace); root.addContent(macro); } line = resourceFileHandle.readLine(); } outputter.output(doc, output); /* Clear up */ outputter = null; output = null; root = null; doc = null; }