use of com.axway.ats.common.xml.XMLException 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.xml.XMLException 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.xml.XMLException 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;
}
use of com.axway.ats.common.xml.XMLException in project ats-framework by Axway.
the class Test_XmlText method constructXmlTextInvallidXMLFile.
@Test
public void constructXmlTextInvallidXMLFile() {
File xml = null;
try {
xml = File.createTempFile("temp_xml", null);
} catch (IOException ex) {
ex.printStackTrace();
}
XmlText xmlText = null;
try {
xmlText = new XmlText(xml);
} catch (XMLException e) {
log.error(e.getMessage());
}
assertEquals(null, xmlText);
xml.delete();
}
use of com.axway.ats.common.xml.XMLException in project ats-framework by Axway.
the class Test_XmlText method setUpTest_XmlText.
@Before
public void setUpTest_XmlText() {
file = new File(Test_XmlText.class.getResource("test.xml").getPath());
try {
xmlText1 = new XmlText(body1.toString());
xmlText2 = new XmlText(body2.toString());
xmlText3 = new XmlText(body3.toString());
} catch (XMLException e) {
log.error(e.getMessage());
}
}
Aggregations