Search in sources :

Example 6 with XMLException

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());
    }
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) Element(org.dom4j.Element) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 7 with XMLException

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());
    }
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) Element(org.dom4j.Element) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 8 with XMLException

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;
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) Element(org.dom4j.Element) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 9 with XMLException

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();
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) IOException(java.io.IOException) File(java.io.File) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Example 10 with XMLException

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());
    }
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) File(java.io.File) Before(org.junit.Before)

Aggregations

XMLException (com.axway.ats.common.xml.XMLException)18 PublicAtsApi (com.axway.ats.common.PublicAtsApi)14 Element (org.dom4j.Element)14 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Attribute (org.dom4j.Attribute)2 BaseTest (com.axway.ats.action.BaseTest)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Document (org.dom4j.Document)1 DocumentException (org.dom4j.DocumentException)1 SAXReader (org.dom4j.io.SAXReader)1 XMLWriter (org.dom4j.io.XMLWriter)1 Before (org.junit.Before)1 Test (org.junit.Test)1