X-Git-Url: http://git.osdn.net/view?p=mikutoga%2FTogaGem.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fjp%2Fsourceforge%2Fmikutoga%2Fpmd%2Fxml%2FXml2PmdLoader.java;h=84d15c082cb7633e936b3a619513550df9b7a8bb;hp=ae48ea7a5b7a645e55fd11e77ec81abf326351ff;hb=33966bcaef20e7786e58d6c2744bd4c066c5ae87;hpb=ab0f2745c1495f5ebb3d2779b5e0187c482acda7 diff --git a/src/main/java/jp/sourceforge/mikutoga/pmd/xml/Xml2PmdLoader.java b/src/main/java/jp/sourceforge/mikutoga/pmd/xml/Xml2PmdLoader.java index ae48ea7..84d15c0 100644 --- a/src/main/java/jp/sourceforge/mikutoga/pmd/xml/Xml2PmdLoader.java +++ b/src/main/java/jp/sourceforge/mikutoga/pmd/xml/Xml2PmdLoader.java @@ -90,7 +90,7 @@ public class Xml2PmdLoader { * @param elem 要素 * @param attrName 属性名 * @return 文字列 - * @throw TogaXmlException 属性値が見つからなかった。 + * @throws TogaXmlException 属性値が見つからなかった。 */ private static String getStringAttr(Element elem, String attrName) throws TogaXmlException{ @@ -102,7 +102,7 @@ public class Xml2PmdLoader { * @param elem 要素 * @param attrName 属性名 * @return 真ならtrue - * @throw TogaXmlException 属性値が見つからなかった。 + * @throws TogaXmlException 属性値が見つからなかった。 */ private static boolean getBooleanAttr(Element elem, String attrName) throws TogaXmlException{ @@ -114,7 +114,7 @@ public class Xml2PmdLoader { * @param elem 要素 * @param attrName 属性名 * @return int値 - * @throw TogaXmlException 属性値が見つからなかった。 + * @throws TogaXmlException 属性値が見つからなかった。 */ private static int getIntegerAttr(Element elem, String attrName) throws TogaXmlException{ @@ -126,7 +126,7 @@ public class Xml2PmdLoader { * @param elem 要素 * @param attrName 属性名 * @return float値 - * @throw TogaXmlException 属性値が見つからなかった。 + * @throws TogaXmlException 属性値が見つからなかった。 */ private static float getFloatAttr(Element elem, String attrName) throws TogaXmlException{ @@ -139,7 +139,7 @@ public class Xml2PmdLoader { * @param elem 要素 * @param attrName 属性名 * @return ファイル名 - * @throw TogaXmlException 属性値が見つからなかった。 + * @throws TogaXmlException 属性値が見つからなかった。 */ private static String getSjisFileNameAttr(Element elem, String attrName) throws TogaXmlException{ @@ -151,7 +151,7 @@ public class Xml2PmdLoader { * @param parent 親要素 * @param tagName 子要素名 * @return 子要素 - * @throw TogaXmlException 1つも見つからなかった + * @throws TogaXmlException 1つも見つからなかった */ private static Element getChild(Element parent, String tagName) throws TogaXmlException{ @@ -179,6 +179,12 @@ public class Xml2PmdLoader { return DomUtils.getEachChild(parent, childTag); } + /** + * グローバル名を取得する。 + * 元要素のname属性及びi18nNameタグを持つ子要素が検索対象 + * @param parent 元要素 + * @return グローバル名。なければnull + */ private static String getGlobalName(Element parent){ NodeList nodeList = parent.getElementsByTagName("i18nName"); int length = nodeList.getLength(); @@ -232,6 +238,12 @@ public class Xml2PmdLoader { return result.toString(); } + /** + * 多言語名を取得する。 + * @param baseElement 元要素 + * @param text 多言語名 + * @throws TogaXmlException あるべき属性が存在しない。 + */ private static void buildI18nName(Element baseElement, I18nText text) throws TogaXmlException{ String primaryText; @@ -251,6 +263,14 @@ public class Xml2PmdLoader { return; } + /** + * XMLのパースを開始する。 + * @param source XML入力 + * @return モデルデータ + * @throws SAXException 構文エラー + * @throws IOException 入力エラー + * @throws TogaXmlException 構文エラー + */ public PmdModel parse(InputSource source) throws SAXException, IOException, TogaXmlException{ Document document = this.builder.parse(source); @@ -462,7 +482,8 @@ public class Xml2PmdLoader { for(Element surfaceGroupElem : eachChild(surfaceGroupListElem, "surfaceGroup") ){ - String groupId = getStringAttr(surfaceGroupElem, "surfaceGroupId"); + String groupId = + getStringAttr(surfaceGroupElem, "surfaceGroupId"); List surfaceList = buildSurface(surfaceGroupElem); this.surfaceGroupMap.put(groupId, surfaceList); @@ -587,7 +608,8 @@ public class Xml2PmdLoader { ikChainList.add(ikChain); String ikBoneIdRef = getStringAttr(ikChainElem, "ikBoneIdRef"); - int rucursiveDepth = getIntegerAttr(ikChainElem, "recursiveDepth"); + int rucursiveDepth = + getIntegerAttr(ikChainElem, "recursiveDepth"); float weight = getFloatAttr(ikChainElem, "weight"); BoneInfo ikBone = this.boneMap.get(ikBoneIdRef); @@ -624,9 +646,11 @@ public class Xml2PmdLoader { MorphType morphType = MorphType.valueOf(type); morphPart.setMorphType(morphType); - List morphVertexList = morphPart.getMorphVertexList(); + List morphVertexList = + morphPart.getMorphVertexList(); - for(Element morphVertexElem : eachChild(morphElem, "morphVertex")){ + for(Element morphVertexElem + : eachChild(morphElem, "morphVertex")){ String vtxIdRef = getStringAttr(morphVertexElem, "vtxIdRef"); Vertex baseVertex = this.vertexMap.get(vtxIdRef); float xOff = getFloatAttr(morphVertexElem, "xOff"); @@ -675,15 +699,18 @@ public class Xml2PmdLoader { BoneGroup defaultGroup = new BoneGroup(); boneGroupList.add(defaultGroup); - for(Element boneGroupElem : eachChild(boneGroupListElem, "boneGroup")){ + for(Element boneGroupElem + : eachChild(boneGroupListElem, "boneGroup")){ BoneGroup group = new BoneGroup(); boneGroupList.add(group); I18nText name = group.getGroupName(); buildI18nName(boneGroupElem, name); - for(Element boneGroupMemberElem : eachChild(boneGroupElem, "boneGroupMember")){ - String boneIdRef = getStringAttr(boneGroupMemberElem, "boneIdRef"); + for(Element boneGroupMemberElem + : eachChild(boneGroupElem, "boneGroupMember")){ + String boneIdRef = + getStringAttr(boneGroupMemberElem, "boneIdRef"); BoneInfo bone = this.boneMap.get(boneIdRef); group.getBoneList().add(bone); } @@ -715,10 +742,12 @@ public class Xml2PmdLoader { String rigidId = getStringAttr(rigidElem, "rigidId"); this.rigidMap.put(rigidId, rigid); - Element linkedBoneElem = getChild(rigidElem, "linkedBone"); - String boneIdRef = getStringAttr(linkedBoneElem, "boneIdRef"); - BoneInfo linkedBone = this.boneMap.get(boneIdRef); - rigid.setLinkedBone(linkedBone); + if(hasChild(rigidElem, "linkedBone")){ + Element linkedBoneElem = getChild(rigidElem, "linkedBone"); + String boneIdRef = getStringAttr(linkedBoneElem, "boneIdRef"); + BoneInfo linkedBone = this.boneMap.get(boneIdRef); + rigid.setLinkedBone(linkedBone); + } RigidShape rigidShape = rigid.getRigidShape(); if(hasChild(rigidElem, "rigidShapeSphere")){ @@ -773,8 +802,10 @@ public class Xml2PmdLoader { Element dynamicsElem = getChild(rigidElem, "dynamics"); float mass = getFloatAttr(dynamicsElem, "mass"); - float dampingPosition = getFloatAttr(dynamicsElem, "dampingPosition"); - float dampingRotation = getFloatAttr(dynamicsElem, "dampingRotation"); + float dampingPosition = + getFloatAttr(dynamicsElem, "dampingPosition"); + float dampingRotation = + getFloatAttr(dynamicsElem, "dampingRotation"); float restitution = getFloatAttr(dynamicsElem, "restitution"); float friction = getFloatAttr(dynamicsElem, "friction"); DynamicsInfo dynamics = rigid.getDynamicsInfo(); @@ -797,14 +828,17 @@ public class Xml2PmdLoader { List groupList = this.model.getRigidGroupList(); - for(Element rigidGroupElem : eachChild(rigidGroupListElem, "rigidGroup")){ + for(Element rigidGroupElem + : eachChild(rigidGroupListElem, "rigidGroup")){ RigidGroup rigidGroup = new RigidGroup(); groupList.add(rigidGroup); - String rigidGroupId = getStringAttr(rigidGroupElem, "rigidGroupId"); + String rigidGroupId = + getStringAttr(rigidGroupElem, "rigidGroupId"); this.rigidGroupMap.put(rigidGroupId, rigidGroup); - for(Element memberElem : eachChild(rigidGroupElem, "rigidGroupMember")){ + for(Element memberElem + : eachChild(rigidGroupElem, "rigidGroupMember")){ String rigidIdRef = getStringAttr(memberElem, "rigidIdRef"); RigidInfo rigid = this.rigidMap.get(rigidIdRef); rigidGroup.getRigidList().add(rigid); @@ -832,7 +866,8 @@ public class Xml2PmdLoader { int serialNum = 0; for(Element rigidElem : eachChild(rigidListElem, "rigid")){ RigidInfo rigid = rigidList.get(serialNum++); - for(Element groupElem : eachChild(rigidElem, "throughRigidGroup")){ + for(Element groupElem + : eachChild(rigidElem, "throughRigidGroup")){ String groupId = getStringAttr(groupElem, "rigidGroupIdRef"); RigidGroup group = this.rigidGroupMap.get(groupId); rigid.getThroughGroupColl().add(group); @@ -916,7 +951,8 @@ public class Xml2PmdLoader { limitRotation.setZRange(zFrom, zTo); Pos3d elasticPosition = joint.getElasticPosition(); - Element elasticPositionElem = getChild(jointElem, "elasticPosition"); + Element elasticPositionElem = + getChild(jointElem, "elasticPosition"); xVal = getFloatAttr(elasticPositionElem, "x"); yVal = getFloatAttr(elasticPositionElem, "y"); zVal = getFloatAttr(elasticPositionElem, "z"); @@ -925,7 +961,8 @@ public class Xml2PmdLoader { elasticPosition.setZPos(zVal); Deg3d elasticRotation = joint.getElasticRotation(); - Element elasticRotationElem = getChild(jointElem, "elasticRotation"); + Element elasticRotationElem = + getChild(jointElem, "elasticRotation"); xVal = getFloatAttr(elasticRotationElem, "xDeg"); yVal = getFloatAttr(elasticRotationElem, "yDeg"); zVal = getFloatAttr(elasticRotationElem, "zDeg");