All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.smartlogic.classificationserver.client.Defaults Maven / Gradle / Ivy

There is a newer version: 5.6.1
Show newest version
package com.smartlogic.classificationserver.client;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Defaults extends XMLReader {
	protected final Log logger = LogFactory.getLog(getClass());
	public Defaults(byte[] data) throws ClassificationException {
		// If there is no data provided, then throw an exception
		defaults = new HashMap();
		if (data == null) throw new ClassificationException("No response from classification server");
		
		Element element = getRootElement(data);
		
		NodeList defaultsNodeList = element.getElementsByTagName("Parameters");
		if ((defaultsNodeList == null) || (defaultsNodeList.getLength() == 0)) {
			//do not throw an exception - for backward compatibility return empty defaults
			return;
			
		}
		
		NodeList paramNodeList = ((Element)defaultsNodeList.item(0)).getElementsByTagName("Param");
		if (paramNodeList == null) return;
		
		for (int i = 0; i < paramNodeList.getLength(); i++) {
			Element paramElement = (Element)paramNodeList.item(i);
			String name = paramElement.getAttribute("name");
			if (name != null){
				name = name.toLowerCase();
			}
			String value = paramElement.getAttribute("value");
			Parameter p = new Parameter();
			p.setName(name);
			p.setValue(value);
			String translation = paramElement.getAttribute("translation");
			if (translation != null){
				p.setTranslation(translation);
			}
			defaults.put(name, p);
			logger.debug("for parameter " + name +" extracted default value " + value);
		}
	}
	
	private Map defaults;
	public Map getDefaults() {
		return defaults;
	}
	

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy