2 * xml 2 vmd SAX Handler
4 * License : The MIT License
5 * Copyright(c) 2013 MikuToga Partners
8 package jp.sfjp.mikutoga.vmd.model.xml;
10 import jp.sfjp.mikutoga.vmd.model.VmdMotion;
11 import org.xml.sax.Attributes;
12 import org.xml.sax.ContentHandler;
13 import org.xml.sax.Locator;
14 import org.xml.sax.SAXException;
17 * XMLモーションファイルパース用SAXハンドラ。
18 * <p>下位リスナに各種通知が振り分けられる。
20 class XmlHandler implements ContentHandler{
22 private VmdMotion vmdMotion;
24 private String nspfx = "";
25 private String nsuri = null;
27 private final SaxVmdListener motionListener;
28 private final SaxVmdListener cameraListener;
29 private final SaxVmdListener lightListener;
31 private SaxVmdListener currentListener = null;
40 this.motionListener = new SaxMotionListener();
41 this.cameraListener = new SaxCameraListener();
42 this.lightListener = new SaxLightingListener();
52 VmdMotion getVmdMotion(){
53 return this.vmdMotion;
58 * @throws SAXException {@inheritDoc}
61 public void startDocument() throws SAXException{
62 this.vmdMotion = new VmdMotion();
64 this.motionListener.setVmdMotion(this.vmdMotion);
65 this.cameraListener.setVmdMotion(this.vmdMotion);
66 this.lightListener .setVmdMotion(this.vmdMotion);
73 * @throws SAXException {@inheritDoc}
76 public void endDocument() throws SAXException{
77 assert this.vmdMotion != null;
83 * @param prefix {@inheritDoc}
84 * @param uri {@inheritDoc}
85 * @throws SAXException {@inheritDoc}
88 public void startPrefixMapping(String prefix, String uri)
90 if(Schema110820.NS_VMDXML.equals(uri)){
99 * @param prefix {@inheritDoc}
100 * @throws SAXException {@inheritDoc}
103 public void endPrefixMapping(String prefix) throws SAXException {
104 if(prefix.equals(this.nspfx)){
113 * @param uri {@inheritDoc}
114 * @param localName {@inheritDoc}
115 * @param qName {@inheritDoc}
116 * @param attr {@inheritDoc}
117 * @throws SAXException {@inheritDoc}
120 public void startElement(String uri,
124 throws SAXException {
125 if( ! this.nsuri.equals(uri) ) return;
127 VmdTag tag = VmdTag.parse(localName);
128 if(tag == null) return;
130 if(tag == VmdTag.MODEL_NAME){
132 SaxAttr.getStringAttr(attr, XmlAttr.ATTR_NAME);
133 this.vmdMotion.setModelName(modelName);
138 if(this.currentListener != null){
139 this.currentListener.openTag(tag, attr);
146 * タグ出現に従い通知リスナを切り替える。
149 private void switchListener(VmdTag tag){
151 case BONE_M_SEQUENCE:
153 this.currentListener = this.motionListener;
155 case CAMERA_SEQUENCE:
156 this.currentListener = this.cameraListener;
159 case SHADOW_SEQUENCE:
160 this.currentListener = this.lightListener;
171 * @param uri {@inheritDoc}
172 * @param localName {@inheritDoc}
173 * @param qName {@inheritDoc}
174 * @throws SAXException {@inheritDoc}
177 public void endElement(String uri, String localName, String qName)
178 throws SAXException {
179 if( ! this.nsuri.equals(uri) ) return;
181 VmdTag tag = VmdTag.parse(localName);
182 if(tag == null) return;
184 if(this.currentListener != null){
185 this.currentListener.closeTag(tag);
193 * @param locator {@inheritDoc}
196 public void setDocumentLocator(Locator locator){
202 * @param target {@inheritDoc}
203 * @param data {@inheritDoc}
204 * @throws SAXException {@inheritDoc}
207 public void processingInstruction(String target, String data)
208 throws SAXException {
214 * @param ch {@inheritDoc}
215 * @param start {@inheritDoc}
216 * @param length {@inheritDoc}
217 * @throws SAXException {@inheritDoc}
220 public void characters(char[] ch, int start, int length)
221 throws SAXException {
227 * @param ch {@inheritDoc}
228 * @param start {@inheritDoc}
229 * @param length {@inheritDoc}
230 * @throws SAXException {@inheritDoc}
233 public void ignorableWhitespace(char[] ch, int start, int length)
234 throws SAXException {
240 * @param name {@inheritDoc}
241 * @throws SAXException {@inheritDoc}
244 public void skippedEntity(String name) throws SAXException{