From c74f1633ca25cf01240c92be14e82e76fd783350 Mon Sep 17 00:00:00 2001 From: Olyutorskii Date: Wed, 26 Jun 2019 00:18:02 +0900 Subject: [PATCH] remove discarded XML classes. --- src/main/java/jp/sfjp/mikutoga/xml/DomNsUtils.java | 295 ----------------- src/main/java/jp/sfjp/mikutoga/xml/DomUtils.java | 362 --------------------- .../jp/sfjp/mikutoga/xml/LocalXmlResource.java | 32 -- .../jp/sfjp/mikutoga/xml/SiblingElemIterator.java | 132 -------- .../java/jp/sfjp/mikutoga/xml/DomUtilsTest.java | 213 ------------ 5 files changed, 1034 deletions(-) delete mode 100644 src/main/java/jp/sfjp/mikutoga/xml/DomNsUtils.java delete mode 100644 src/main/java/jp/sfjp/mikutoga/xml/DomUtils.java delete mode 100644 src/main/java/jp/sfjp/mikutoga/xml/LocalXmlResource.java delete mode 100644 src/main/java/jp/sfjp/mikutoga/xml/SiblingElemIterator.java delete mode 100644 src/test/java/jp/sfjp/mikutoga/xml/DomUtilsTest.java diff --git a/src/main/java/jp/sfjp/mikutoga/xml/DomNsUtils.java b/src/main/java/jp/sfjp/mikutoga/xml/DomNsUtils.java deleted file mode 100644 index f36313c..0000000 --- a/src/main/java/jp/sfjp/mikutoga/xml/DomNsUtils.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * XML DOM utilities with namespace - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sfjp.mikutoga.xml; - -import java.text.MessageFormat; -import java.util.Iterator; -import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * DOMユーティリティ(名前空間対応)。 - * - *

各種名前空間引数にnullが渡された場合、全ての名前空間にマッチする。 - * - *

各種ローカル名引数にnullが渡された場合、全てのローカル名にマッチする。 - * - *

ノードの持つ名前空間がnullの場合、全ての名前空間引数にマッチする。 - */ -public final class DomNsUtils { - - private static final String ERRMSG_NOELEM = - "Elem:[{0}] was not found in Elem:[{1}]"; - private static final String ERRMSG_NOATTR = - "Attr:[{0}] was not found in Elem:[{1}]"; - private static final String ERRMSG_INVATTR = - "Invalid attribute form Attr[{0}] Value[{1}]"; - - - /** - * 隠しコンストラクタ。 - */ - private DomNsUtils(){ - assert false; - throw new AssertionError(); - } - - - /** - * 名前空間とローカル名が一致するノードか判定する。 - * @param node ノード - * @param nsuri 名前空間URI - * @param localName ローカル名。 - * @return ノードの名前空間およびローカル名が一致したらtrue - */ - public static boolean hasNsLocalNameNode(Node node, - String nsuri, - String localName ){ - String nodeLocalName = node.getLocalName(); - String nodeNsUri = node.getNamespaceURI(); - - if(localName != null){ - if( ! localName.equals(nodeLocalName) ) return false; - } - - if(nsuri != null && nodeNsUri != null){ - if( ! nsuri.equals(nodeNsUri) ) return false; - } - - return true; - } - - /** - * 名前空間とローカル名が一致する要素か判定する。 - * @param node ノード - * @param nsuri 名前空間URI - * @param localName ローカル名。 - * @return 名前空間およびローカル名が一致する要素であればtrue - */ - public static boolean hasNsLocalNameElem(Node node, - String nsuri, - String localName ){ - if(node.getNodeType() != Node.ELEMENT_NODE) return false; - if( ! hasNsLocalNameNode(node, nsuri, localName) ) return false; - return true; - } - - /** - * 親要素が指定された名前の子要素を持つか判定する。 - * @param parent 親要素 - * @param nsuri 名前空間URI - * @param localName ローカル名 - * @return 指定名の子要素が存在すればtrue - */ - public static boolean hasChild(Element parent, - String nsuri, - String localName ){ - for(Node node = parent.getFirstChild(); - node != null; - node = node.getNextSibling() ){ - - if(hasNsLocalNameElem(node, nsuri, localName)){ - return true; - } - } - - return false; - } - - /** - * 指定された名前空間とローカル名に合致する最初の直下子要素を返す。 - * @param parent 親要素 - * @param nsuri 名前空間URI - * @param localName ローカル名 - * @return 最初の直下子要素。見つからなければnull。 - */ - public static Element pickFirstChild(Node parent, - String nsuri, - String localName ){ - Node node = parent.getFirstChild(); - while(node != null){ - if(hasNsLocalNameElem(node, nsuri, localName)){ - break; - } - node = node.getNextSibling(); - } - return (Element) node; - } - - /** - * 指定された名前空間とローカル名に合致する最初の直下子要素を返す。 - * - *

見つからなければ例外を投げる。 - * - * @param parent 親要素 - * @param nsuri 名前空間URI - * @param localName ローカル名 - * @return 最初の直下子要素。 - * @throws TogaXmlException 1つも見つからなかった - */ - public static Element getFirstChild(Element parent, - String nsuri, - String localName ) - throws TogaXmlException{ - Element elem = pickFirstChild(parent, nsuri, localName); - - if(elem == null){ - String message = MessageFormat.format(ERRMSG_NOELEM, - localName, - parent.getLocalName() ); - throw new TogaXmlException(message); - } - - return elem; - } - - /** - * 指定された名前の子要素のforeachを返す。 - * @param parent 親要素 - * @param nsuri 名前空間URI - * @param localName 子要素名 - * @return 子要素のforeach - */ - public static Iterable getEachChild(final Element parent, - final String nsuri, - final String localName ){ - Iterable result = new Iterable(){ - @Override - public Iterator iterator(){ - return new SiblingElemIterator(parent, nsuri, localName); - } - }; - return result; - } - - /** - * 要素に属性が存在するか判定する。 - * @param elem 要素 - * @param nsuri 名前空間URI - * @param localName ローカル名 - * @return 存在するならtrue - */ - public static boolean hasAttrNS(Element elem, - String nsuri, - String localName ){ - return elem.hasAttributeNS(nsuri, localName); - } - - /** - * 要素からxsd:string型属性値を読み取る。 - * @param elem 要素 - * @param nsuri 名前空間URI - * @param localName 属性名 - * @return 文字列 - * @throws TogaXmlException 属性値が見つからなかった。 - */ - public static String getStringAttrNS(Element elem, - String nsuri, - String localName ) - throws TogaXmlException{ - if( ! hasAttrNS(elem, nsuri, localName) ){ - String message = MessageFormat.format(ERRMSG_NOATTR, - localName, - elem.getLocalName() ); - throw new TogaXmlException(message); - } - - String result; - try{ - result = elem.getAttributeNS(nsuri, localName); - }catch(DOMException e){ - assert false; - throw new AssertionError(e); - } - - return result; - } - - /** - * 要素からxsd:boolean型属性値を読み取る。 - * @param elem 要素 - * @param nsuri 名前空間URI - * @param localName 属性名 - * @return 真ならtrue - * @throws TogaXmlException 属性値が見つからなかった。 - */ - public static boolean getBooleanAttrNS(Element elem, - String nsuri, - String localName ) - throws TogaXmlException{ - String value = getStringAttrNS(elem, nsuri, localName); - - boolean result; - try{ - result = DatatypeIo.parseBoolean(value); - }catch(IllegalArgumentException e){ - String message = MessageFormat.format(ERRMSG_INVATTR, - localName, - value ); - throw new TogaXmlException(message, e); - } - - return result; - } - - /** - * 要素からxsd:integer型属性値を読み取る。 - * @param elem 要素 - * @param nsuri 名前空間URI - * @param localName 属性名 - * @return int値 - * @throws TogaXmlException 属性値が見つからなかった。 - */ - public static int getIntegerAttrNS(Element elem, - String nsuri, - String localName ) - throws TogaXmlException{ - String value = getStringAttrNS(elem, nsuri, localName); - - int result; - try{ - result = DatatypeIo.parseInt(value); - }catch(NumberFormatException e){ - String message = MessageFormat.format(ERRMSG_INVATTR, - localName, - value ); - throw new TogaXmlException(message, e); - } - - return result; - } - - /** - * 要素からxsd:float型属性値を読み取る。 - * @param elem 要素 - * @param nsuri 名前空間URI - * @param localName 属性名 - * @return float値 - * @throws TogaXmlException 属性値が見つからなかった。 - */ - public static float getFloatAttrNS(Element elem, - String nsuri, - String localName ) - throws TogaXmlException{ - String value = getStringAttrNS(elem, nsuri, localName); - - float result; - try{ - result = DatatypeIo.parseFloat(value); - }catch(NumberFormatException e){ - String message = MessageFormat.format(ERRMSG_INVATTR, - localName, - value ); - throw new TogaXmlException(message, e); - } - - return result; - } - -} diff --git a/src/main/java/jp/sfjp/mikutoga/xml/DomUtils.java b/src/main/java/jp/sfjp/mikutoga/xml/DomUtils.java deleted file mode 100644 index 1861728..0000000 --- a/src/main/java/jp/sfjp/mikutoga/xml/DomUtils.java +++ /dev/null @@ -1,362 +0,0 @@ -/* - * XML DOM utilities - * - * License : The MIT License - * Copyright(c) 2010 MikuToga Partners - */ - -package jp.sfjp.mikutoga.xml; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.NoSuchElementException; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * DOMユーティリティ。 - */ -public final class DomUtils { - - // 構文解析バグ回避。 - private static final char BS_CHAR = (char) 0x005c; - - /** - * 隠しコンストラクタ。 - */ - private DomUtils(){ - super(); - assert false; - throw new AssertionError(); - } - - /** - * 要素からxsd:string型属性値を読み取る。 - * @param elem 要素 - * @param attrName 属性名 - * @return 文字列 - * @throws TogaXmlException 属性値が見つからなかった。 - */ - public static String getStringAttr(Element elem, String attrName) - throws TogaXmlException{ - if( ! elem.hasAttribute(attrName) ){ - String message = "Attr:[" + attrName + "] " - + "was not found in " - + "Elem:[" + elem.getTagName()+"]"; - throw new TogaXmlException(message); - } - - String result; - try{ - result = elem.getAttribute(attrName); - }catch(IllegalArgumentException e){ - String message = "Invalid attribute form [" + attrName + "]"; - throw new TogaXmlException(message, e); - } - - return result; - } - - /** - * 要素からxsd:boolean型属性値を読み取る。 - * @param elem 要素 - * @param attrName 属性名 - * @return 真ならtrue - * @throws TogaXmlException 属性値が見つからなかった。 - */ - public static boolean getBooleanAttr(Element elem, String attrName) - throws TogaXmlException{ - String value = getStringAttr(elem, attrName); - - boolean result; - try{ - result = DatatypeIo.parseBoolean(value); - }catch(IllegalArgumentException e){ - String message = - "Invalid boolean attribute form " - + "[" + attrName + "][" + value + "]"; - throw new TogaXmlException(message, e); - } - - return result; - } - - /** - * 要素からxsd:integer型属性値を読み取る。 - * @param elem 要素 - * @param attrName 属性名 - * @return int値 - * @throws TogaXmlException 属性値が見つからなかった。 - */ - public static int getIntegerAttr(Element elem, String attrName) - throws TogaXmlException{ - String value = getStringAttr(elem, attrName); - - int result; - try{ - result = DatatypeIo.parseInt(value); - }catch(IllegalArgumentException e){ - String message = - "Invalid integer attribute form " - + "[" + attrName + "][" + value + "]"; - throw new TogaXmlException(message, e); - } - - return result; - } - - /** - * 要素からxsd:float型属性値を読み取る。 - * @param elem 要素 - * @param attrName 属性名 - * @return float値 - * @throws TogaXmlException 属性値が見つからなかった。 - */ - public static float getFloatAttr(Element elem, String attrName) - throws TogaXmlException{ - String value = getStringAttr(elem, attrName); - - float result; - try{ - result = DatatypeIo.parseFloat(value); - }catch(IllegalArgumentException e){ - String message = - "Invalid float attribute form " - + "[" + attrName + "][" + value + "]"; - throw new TogaXmlException(message, e); - } - - return result; - } - - /** - * 要素から日本語Windows用ファイル名を属性値として読み取る。 - * 念のため文字U+00A5は文字U-005Cに変換される。 - * @param elem 要素 - * @param attrName 属性名 - * @return ファイル名 - * @throws TogaXmlException 属性値が見つからなかった。 - */ - public static String getSjisFileNameAttr(Element elem, String attrName) - throws TogaXmlException{ - String result; - try{ - result = getStringAttr(elem, attrName); - }catch(IllegalArgumentException e){ - String message = - "Invalid winfile attribute form " - + "[" + attrName + "]"; - throw new TogaXmlException(message, e); - } - - result = result.replace("" + '\u00a5', "" + BS_CHAR); - - return result; - } - - /** - * 指定された名前の子要素を1つだけ返す。 - * @param parent 親要素 - * @param tagName 子要素名 - * @return 子要素 - * @throws TogaXmlException 1つも見つからなかった - */ - public static Element getChild(Element parent, String tagName) - throws TogaXmlException{ - Element result = null; - - for(Node node = parent.getFirstChild(); - node != null; - node = node.getNextSibling() ){ - - if(node.getNodeType() != Node.ELEMENT_NODE) continue; - Element elem = (Element) node; - - String elemTagName = elem.getTagName(); - if( tagName.equals(elemTagName) ){ - result = elem; - break; - } - } - - if(result == null){ - String message = - "Elem:[" + tagName + "] was not found in " - +"Elem:[" + parent.getTagName() + "]"; - throw new TogaXmlException(message); - } - - return result; - } - - /** - * 親要素が指定された名前の子要素を持つか判定する。 - * @param parent 親要素 - * @param tagName 子要素名 - * @return 指定名の子要素が存在すればtrue - */ - public static boolean hasChild(Element parent, String tagName){ - for(Node node = parent.getFirstChild(); - node != null; - node = node.getNextSibling() ){ - - if(node.getNodeType() != Node.ELEMENT_NODE) continue; - Element elem = (Element) node; - - String elemTagName = elem.getTagName(); - if( tagName.equals(elemTagName) ) return true; - } - - return false; - } - - /** - * 指定された名前の子要素のリストを返す。 - * @param parent 親要素 - * @param childTag 子要素名 - * @return 子要素のリスト - */ - public static List getChildList(Element parent, - String childTag){ - List result = new LinkedList<>(); - - for(Node node = parent.getFirstChild(); - node != null; - node = node.getNextSibling() ){ - - if(node.getNodeType() != Node.ELEMENT_NODE) continue; - Element elem = (Element) node; - - String tagName = elem.getTagName(); - if( ! childTag.equals(tagName) ) continue; - - result.add(elem); - } - - return result; - } - - /** - * 指定された名前の子要素の列挙子を返す。 - * @param parent 親要素 - * @param childTag 子要素名 - * @return 子要素の列挙子 - */ - public static Iterator getChildIterator(Element parent, - String childTag){ - Element firstElem; - try{ - firstElem = getChild(parent, childTag); - }catch(TogaXmlException e){ - firstElem = null; - } - - Iterator result = new ElemIterator(firstElem); - - return result; - } - - /** - * 指定された名前の子要素のforeachを返す。 - * @param parent 親要素 - * @param childTag 子要素名 - * @return 子要素のforeach - */ - public static Iterable getEachChild(Element parent, - String childTag){ - final Iterator iterator = getChildIterator(parent, childTag); - Iterable result = new Iterable(){ - @Override - public Iterator iterator(){ - return iterator; - } - }; - return result; - } - - /** - * 要素の次の要素を返す。 - * @param elem 要素 - * @return 次の要素。なければnull - */ - public static Element nextElement(Element elem){ - Node nextNode = elem; - for(;;){ - nextNode = nextNode.getNextSibling(); - if(nextNode == null) break; - if(nextNode.getNodeType() == Node.ELEMENT_NODE){ - break; - } - } - - return (Element) nextNode; - } - - /** - * 同じ要素名を持つ次の要素を返す。 - * @param elem 要素 - * @return 次の要素。なければnull - */ - public static Element nextNamedElement(Element elem){ - String tagName = elem.getTagName(); - Element nextElem = elem; - for(;;){ - nextElem = nextElement(nextElem); - if(nextElem == null) break; - if(tagName.equals(nextElem.getTagName())) break; - } - - return nextElem; - } - - /** - * 同じ親要素と同じ要素名を持つ兄弟要素を列挙する列挙子。 - */ - private static final class ElemIterator implements Iterator { - private Element next; - - /** - * コンストラクタ。 - * @param elem 最初の要素。nullを指定すれば空列挙子となる。 - */ - ElemIterator(Element elem){ - super(); - this.next = elem; - } - - /** - * {@inheritDoc} - * @return {@inheritDoc} - */ - @Override - public boolean hasNext(){ - if(this.next == null) return false; - return true; - } - - /** - * {@inheritDoc} - * @return {@inheritDoc} - * @throws NoSuchElementException {@inheritDoc} - */ - @Override - public Element next() throws NoSuchElementException{ - if(this.next == null) throw new NoSuchElementException(); - Element result = this.next; - this.next = nextNamedElement(this.next); - return result; - } - - /** - * {@inheritDoc} - * ※ 未サポート。 - */ - @Override - public void remove(){ - throw new UnsupportedOperationException(); - } - - } - -} diff --git a/src/main/java/jp/sfjp/mikutoga/xml/LocalXmlResource.java b/src/main/java/jp/sfjp/mikutoga/xml/LocalXmlResource.java deleted file mode 100644 index 0ccccd4..0000000 --- a/src/main/java/jp/sfjp/mikutoga/xml/LocalXmlResource.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * xml local resource map - * - * License : The MIT License - * Copyright(c) 2013 olyutorskii - */ - -package jp.sfjp.mikutoga.xml; - -import java.net.URI; - -/** - * 代用ローカルリソースの管理を行う。 - * - *

ネットワークを介したグローバルなリソースと、 - * アプリ上のローカルな代用リソースとを対応付ける。 - */ -public interface LocalXmlResource { - - /** - * オリジナル版XMLリソースのURIを返す。 - * @return オリジナル版リソースのURL。 - */ - public abstract URI getOriginalResource(); - - /** - * ローカル版XMLリソースのURIを返す。 - * @return ローカル版リソースのURL。 - */ - public abstract URI getLocalResource(); - -} diff --git a/src/main/java/jp/sfjp/mikutoga/xml/SiblingElemIterator.java b/src/main/java/jp/sfjp/mikutoga/xml/SiblingElemIterator.java deleted file mode 100644 index 63912bc..0000000 --- a/src/main/java/jp/sfjp/mikutoga/xml/SiblingElemIterator.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * sibling element iterator on DOM tree - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sfjp.mikutoga.xml; - -import java.util.Iterator; -import java.util.NoSuchElementException; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * 兄弟要素間用Iterator。 - * - *

同じ親と名前空間とローカル名を持つ要素同士を「兄弟要素」とする。 - * - *

ノードの持つ名前空間がnullの場合、全ての名前空間引数にマッチする。 - * - *

削除操作は未サポート。 - */ -public class SiblingElemIterator implements Iterator { - - private Element next; - private final String nsuri; - private final String localName; - - - /** - * コンストラクタ。 - * @param first 最初の兄弟要素。nullだと一度もiterateしない。 - */ - public SiblingElemIterator(Element first){ - super(); - - this.next = first; - - if(this.next == null){ - this.nsuri = null; - this.localName = null; - }else{ - this.nsuri = this.next.getNamespaceURI(); - this.localName = this.next.getLocalName(); - } - - return; - } - - /** - * コンストラクタ。 - * - *

名前空間引数にnullが渡された場合、全ての名前空間にマッチする。 - * - *

ローカル名引数にnullが渡された場合、全てのローカル名にマッチする。 - * - * @param parent 親要素 - * @param nsuri 子要素の名前空間URI - * @param localName 子要素のローカル名 - */ - public SiblingElemIterator(Element parent, - String nsuri, - String localName ){ - super(); - - this.next = DomNsUtils.pickFirstChild(parent, nsuri, localName); - - if(this.next == null){ - this.nsuri = null; - this.localName = null; - }else{ - this.nsuri = nsuri; - this.localName = localName; - } - - return; - } - - - /** - * {@inheritDoc} - * @return {@inheritDoc} - */ - @Override - public boolean hasNext(){ - if(this.next != null) return true; - return false; - } - - /** - * {@inheritDoc} - * @return {@inheritDoc} - * @throws NoSuchElementException {@inheritDoc} - */ - @Override - public Element next() throws NoSuchElementException { - if(this.next == null) throw new NoSuchElementException(); - - Element result = this.next; - - Node sibNode = result; - do{ - sibNode = sibNode.getNextSibling(); - if(sibNode == null) break; - }while( ! matchElemName(sibNode) ); - this.next = (Element) sibNode; - - return result; - } - - /** - * 兄弟要素にふさわしい名前を持つか判定する。 - * @param node 判定対象 - * @return 兄弟にふさわしい名前を持つならtrue - */ - private boolean matchElemName(Node node){ - return DomNsUtils.hasNsLocalNameElem(node, - this.nsuri, this.localName ); - } - - /** - * {@inheritDoc} - * ※削除不可。 - * @throws UnsupportedOperationException 削除を試みたので失敗した - */ - @Override - public void remove() throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - -} diff --git a/src/test/java/jp/sfjp/mikutoga/xml/DomUtilsTest.java b/src/test/java/jp/sfjp/mikutoga/xml/DomUtilsTest.java deleted file mode 100644 index f319a31..0000000 --- a/src/test/java/jp/sfjp/mikutoga/xml/DomUtilsTest.java +++ /dev/null @@ -1,213 +0,0 @@ -/* -@see https://www.w3.org/TR/xmlschema-2/ - */ - -package jp.sfjp.mikutoga.xml; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * - */ -public class DomUtilsTest { - - private static final DocumentBuilderFactory FACTORY = - DocumentBuilderFactory.newInstance(); - private static final DocumentBuilder BUILDER; - - private static final String TESTELEM = "testelem"; - private static final String TESTATTR = "testattr"; - - private static Element getTestAttredElem(String attrVal){ - Document doc = BUILDER.newDocument(); - Element elem = doc.createElement(TESTELEM); - elem.setAttribute(TESTATTR, attrVal); - return elem; - } - - static{ - try{ - BUILDER = FACTORY.newDocumentBuilder(); - }catch(ParserConfigurationException e){ - throw new ExceptionInInitializerError(e); - } - } - - public DomUtilsTest() { - } - - @BeforeClass - public static void setUpClass() throws ParserConfigurationException{ - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of getBooleanAttr method, of class DomUtils. - */ - @Test - public void testGetBooleanAttr() throws Exception { - System.out.println("getBooleanAttr"); - - boolean result; - Element elem; - - elem = getTestAttredElem("true"); - result = DomUtils.getBooleanAttr(elem, TESTATTR); - assertTrue(result); - - elem = getTestAttredElem("false"); - result = DomUtils.getBooleanAttr(elem, TESTATTR); - assertFalse(result); - - elem = getTestAttredElem("0"); - result = DomUtils.getBooleanAttr(elem, TESTATTR); - assertFalse(result); - - elem = getTestAttredElem("1"); - result = DomUtils.getBooleanAttr(elem, TESTATTR); - assertTrue(result); - - elem = getTestAttredElem("\n\rtrue\u0020\t"); - result = DomUtils.getBooleanAttr(elem, TESTATTR); - assertTrue(result); - - elem = getTestAttredElem("?"); - try{ - DomUtils.getBooleanAttr(elem, TESTATTR); - fail(); - }catch(TogaXmlException e){ - assert true; - } - - return; - } - - /** - * Test of getIntegerAttr method, of class DomUtils. - */ - @Test - public void testGetIntegerAttr() throws TogaXmlException { - System.out.println("getIntegerAttr"); - - int result; - Element elem; - - elem = getTestAttredElem("0"); - result = DomUtils.getIntegerAttr(elem, TESTATTR); - assertEquals(0, result); - - elem = getTestAttredElem("1"); - result = DomUtils.getIntegerAttr(elem, TESTATTR); - assertEquals(1, result); - - elem = getTestAttredElem("-1"); - result = DomUtils.getIntegerAttr(elem, TESTATTR); - assertEquals(-1, result); - - elem = getTestAttredElem("999"); - result = DomUtils.getIntegerAttr(elem, TESTATTR); - assertEquals(999, result); - - elem = getTestAttredElem("-9999"); - result = DomUtils.getIntegerAttr(elem, TESTATTR); - assertEquals(-9999, result); - - elem = getTestAttredElem("\n\r999\u0020\t"); - result = DomUtils.getIntegerAttr(elem, TESTATTR); - assertEquals(999, result); - - elem = getTestAttredElem("?"); - try{ - result = DomUtils.getIntegerAttr(elem, TESTATTR); - fail(); - }catch(TogaXmlException e){ - assert true; - } - - return; - } - - /** - * Test of getFloatAttr method, of class DomUtils. - */ - @Test - public void testGetFloatAttr() throws TogaXmlException { - System.out.println("getFloatAttr"); - - float result; - Element elem; - - elem = getTestAttredElem("0.0"); - result = DomUtils.getFloatAttr(elem, TESTATTR); - assertEquals(0.0f, result, 0.0f); - - elem = getTestAttredElem("-0.0"); - result = DomUtils.getFloatAttr(elem, TESTATTR); - assertEquals(0.0f, result, 0.0f); - assertEquals("-0.0", Float.toString(result)); - - elem = getTestAttredElem("-123.456"); - result = DomUtils.getFloatAttr(elem, TESTATTR); - assertEquals(-123.456f, result, 0.0f); - - elem = getTestAttredElem("654.321"); - result = DomUtils.getFloatAttr(elem, TESTATTR); - assertEquals(654.321f, result, 0.0f); - - elem = getTestAttredElem("2.3E4"); - result = DomUtils.getFloatAttr(elem, TESTATTR); - assertEquals(23000.0f, result, 0.0f); - - elem = getTestAttredElem("INF"); - result = DomUtils.getFloatAttr(elem, TESTATTR); - assertEquals(Float.POSITIVE_INFINITY, result, 0.0f); - - elem = getTestAttredElem("+INF"); - try{ - DomUtils.getFloatAttr(elem, TESTATTR); - fail(); - }catch(TogaXmlException e){ - assert true; - } - - elem = getTestAttredElem("NaN"); - result = DomUtils.getFloatAttr(elem, TESTATTR); - assertTrue(Float.isNaN(result)); - - elem = getTestAttredElem("\n\r123.456\u0020\t"); - result = DomUtils.getFloatAttr(elem, TESTATTR); - assertEquals(123.456f, result, 0.0f); - - elem = getTestAttredElem("?"); - try{ - DomUtils.getFloatAttr(elem, TESTATTR); - fail(); - }catch(TogaXmlException e){ - assert true; - } - - return; - } - -} -- 2.11.0