X-Git-Url: http://git.osdn.net/view?p=mikutoga%2FTogaGem.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fjp%2Fsfjp%2Fmikutoga%2Fxml%2FDomNsUtils.java;fp=src%2Fmain%2Fjava%2Fjp%2Fsfjp%2Fmikutoga%2Fxml%2FDomNsUtils.java;h=0000000000000000000000000000000000000000;hp=0bda0462f8c400e8f3f37d2bea33f294cde0bf90;hb=ca790c392b3e12ba485b897aa10334aff7fce4b1;hpb=3747423c564042a26a0d1db6cc1fc79965c5140c 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 0bda046..0000000 --- a/src/main/java/jp/sfjp/mikutoga/xml/DomNsUtils.java +++ /dev/null @@ -1,290 +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