/*
* ###
* PHR_NodeJSWebService
* %%
* Copyright (C) 1999 - 2012 Photon Infotech Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ###
*/
package com.photon.phresco.uiconstants;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.lang.NullArgumentException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.photon.phresco.selenium.util.ScreenException;
public class ReadXMLFile {
private static Element eElement;
private Log log = LogFactory.getLog(getClass());
private static final String phrsc = "./src/main/resources/phresco-env-config.Xml";
private static final String nodejs = "./src/main/resources/NodejsData.xml";
private static final String nodeui = "./src/main/resources/UIConstants.xml";
private static final String nodeinfo = "./src/main/resources/UserInfo.xml";
public ReadXMLFile() throws ScreenException {
log.info("@ReadXMLFile Constructor::loading *****PhrescoUIConstants******");
loadPhrescoConstansts(phrsc);
}
public void loadPhrescoConstansts(String properties) throws ScreenException {
try {
File fXmlFile = new File(properties);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
NodeList nList = doc.getElementsByTagName("environment");
System.out.println("-----------------------");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
eElement = (Element) nNode;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void NodejsData() throws ScreenException {
loadPhrescoConstansts(nodejs);
}
public void loadUIConstants() throws ScreenException {
loadPhrescoConstansts(nodeui);
}
public void loadUserInfoConstants() throws ScreenException {
loadPhrescoConstansts(nodeinfo);
}
public String getValue(String elementName) {
NodeList nlList = eElement.getElementsByTagName(elementName).item(0)
.getChildNodes();
Node nValue = (Node) nlList.item(0);
if (nValue.getNodeValue() == null) {
throw new NullArgumentException("***The element value is zero***");
}
return nValue.getNodeValue();
}
}