2 * Sax 2 Xsd-types converter
4 * License : The MIT License
5 * Copyright(c) 2013 MikuToga Partners
8 package jp.sfjp.mikutoga.xml;
10 import org.xml.sax.Attributes;
13 * XSD各種型のSAX属性値をJavaプリミティブ型へ変換する。
15 public final class SaxAttr {
22 throw new AssertionError();
27 * 属性名に対応する属性値があるか否か判定する。
30 * @return 属性名に対応する属性値がある場合はtrue
32 public static boolean hasAttr(Attributes attr, String name){
33 if(attr.getValue(name) == null) return false;
38 * xsd:string型属性値の読み込み。
41 * @return 属性値。該当する属性が無ければnull。
43 public static String getStringAttr(Attributes attr, String name){
44 String attrVal = attr.getValue(name);
49 * xsd:boolean型属性値の読み込み。
53 * @throws IllegalArgumentException boolean型表記ではない
55 public static boolean getBooleanAttr(Attributes attr, String name)
56 throws IllegalArgumentException{
57 String attrVal = attr.getValue(name);
59 bVal = DatatypeIo.parseBoolean(attrVal);
64 * xsd:boolean型属性値の読み込み。
67 * @param def 属性が無い場合のデフォルト値
69 * @throws IllegalArgumentException boolean型表記ではない
71 public static boolean getBooleanAttr(Attributes attr,
74 throws IllegalArgumentException{
75 String attrVal = attr.getValue(name);
76 if(attrVal == null) return def;
79 bVal = DatatypeIo.parseBoolean(attrVal);
89 * @throws NumberFormatException byte型表記ではない
91 public static byte getByteAttr(Attributes attr, String name)
92 throws NumberFormatException{
93 String attrVal = attr.getValue(name);
95 bVal = DatatypeIo.parseByte(attrVal);
100 * xsd:float型属性値の読み込み。
104 * @throws NumberFormatException float型表記ではない
106 public static float getFloatAttr(Attributes attr, String name)
107 throws NumberFormatException {
108 String attrVal = attr.getValue(name);
110 fVal = DatatypeIo.parseFloat(attrVal);
119 * @throws NumberFormatException int型表記ではない
121 public static int getIntAttr(Attributes attr, String name)
122 throws NumberFormatException {
123 String attrVal = attr.getValue(name);
125 iVal = DatatypeIo.parseInt(attrVal);