use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class XmlText method getAttributes.
/**
* @param xpath XPath , pointing to a XML element
* @return a HashMap , containing the attributes and their values
* @throws XMLException
*/
@PublicAtsApi
public Map<String, String> getAttributes(String xpath) throws XMLException {
if (StringUtils.isNullOrEmpty(xpath)) {
throw new XMLException("Null/empty xpath is not allowed.");
}
Element element = findElement(xpath);
if (element == null) {
throw new XMLException("'" + xpath + "' is not a valid path");
}
HashMap<String, String> attributes = new HashMap<>(1);
Iterator<Attribute> it = element.attributeIterator();
while (it.hasNext()) {
Attribute attr = it.next();
attributes.put(attr.getName(), attr.getValue());
}
return attributes;
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class XmlText method setAttribute.
/**
* Adds attribute to XML element.
*
* @param xpath XPath , pointing to a XML element
* @param name the name of the attribute
* @param value the value of the attribute
* @return this instance
* @throws XMLException
*/
@PublicAtsApi
public XmlText setAttribute(String xpath, String name, String value) throws XMLException {
if (StringUtils.isNullOrEmpty(xpath)) {
throw new XMLException("Null/empty xpath is not allowed.");
}
if (StringUtils.isNullOrEmpty(name)) {
throw new XMLException("Null/empty attribute name is not allowed.");
}
if (StringUtils.isNullOrEmpty(value)) {
throw new XMLException("Null/empty attribute value is not allowed.");
}
Element element = findElement(xpath);
if (element == null) {
throw new XMLException("'" + xpath + "' is not a valid path");
}
element.addAttribute(name, value);
return this;
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class XmlText method getFloat.
/**
* @param xpath XPath , pointing to a XML element
* @return a float XML value
* @throws XMLException
*/
@PublicAtsApi
public float getFloat(String xpath) throws XMLException {
Object object = get(xpath);
Element root = ((XmlText) object).root;
if (root.isTextOnly()) {
object = root.getText().trim();
} else {
object = "";
}
try {
return Float.parseFloat(((String) object).trim());
} catch (NumberFormatException nfe) {
throw new XMLException("'" + xpath + "' does not point to a float value:\n" + object.toString());
}
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class XmlText method getInt.
/**
* @param xpath XPath , pointing to a XML element
* @return an Integer XML value
* @throws XMLException
*/
@PublicAtsApi
public int getInt(String xpath) throws XMLException {
Object object = get(xpath);
Element root = ((XmlText) object).root;
if (root.isTextOnly()) {
object = root.getText().trim();
} else {
object = "";
}
try {
return Integer.parseInt(((String) object).trim());
} catch (NumberFormatException nfe) {
throw new XMLException("'" + xpath + "' does not point to an int value:\n" + object.toString());
}
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class XmlText method appendText.
/**
* Append text to a XML element.
*
* @param xpath XPath , pointing to a XML element
* @param text the text , which will be appended to a XML element
* @return this instance
* @throws XMLException
*/
@PublicAtsApi
public XmlText appendText(String xpath, String text) throws XMLException {
if (StringUtils.isNullOrEmpty(xpath)) {
throw new XMLException("Null/empty xpath is not allowed.");
}
if (StringUtils.isNullOrEmpty(text)) {
throw new XMLException("Null/empty text is not allowed.");
}
Element element = findElement(xpath);
if (element == null) {
throw new XMLException("'" + xpath + "' is not a valid path");
}
element.addText(text);
return this;
}
Aggregations