hvv_admin.HVV_AdminStepNames.java Source code

Java tutorial

Introduction

Here is the source code for hvv_admin.HVV_AdminStepNames.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package hvv_admin;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.QName;
import org.dom4j.io.SAXReader;

/**
 *
 * @author yaroslav
 */
public class HVV_AdminStepNames {
    static Logger logger = Logger.getLogger(HVV_AdminStepNames.class);

    public HashMap m_mapSteps;

    public HVV_AdminStepNames(String strAMSRoot) {
        m_mapSteps = new HashMap();

        ReadSettings();
    }

    private boolean ReadSettings() {
        boolean bResOk = true;
        try {
            SAXReader reader = new SAXReader();

            String strSettingsFilePathName = System.getenv("AMS_ROOT") + "/etc/hvv8.step.names.xml";
            URL url = (new java.io.File(strSettingsFilePathName)).toURI().toURL();

            Document document = reader.read(url);

            Element root = document.getRootElement();

            // iterate through child elements of root
            for (Iterator i = root.elementIterator(); i.hasNext();) {
                Element element = (Element) i.next();
                String id = element.attributeValue("id");
                String num = element.attributeValue("num");
                String value = element.getText();
                m_mapSteps.put(id, new ItemStepNames(num, value));
            }

        } catch (MalformedURLException ex) {
            logger.error("MalformedURLException caught while loading settings!", ex);
            bResOk = false;
        } catch (DocumentException ex) {
            logger.error("DocumentException caught while loading settings!", ex);
            bResOk = false;
        }

        return bResOk;
    }
}