001    /*
002     * To change this template, choose Tools | Templates
003     * and open the template in the editor.
004     */
005    
006    package org.util.xml.parse.policy;
007    
008    import org.util.xml.element.Element;
009    import org.util.xml.element.TagElement;
010    
011    /**
012     *
013     * @author masaru
014     */
015    public class XMLParserPolicy extends DefaultParserPolicy {
016    
017        String encoding_;
018        public String selectEncoding(String last_tag_key) {
019            return encoding_;
020        }
021    
022        public boolean checkEndTag() {
023            return true;
024        }
025        public boolean forceEmptyTag(String key) {
026            return false;
027        }
028    
029        public Element allowElement(Element element) {
030            if(encoding_ == null) {
031                if(element.isTagElement()) {
032                    TagElement te = (TagElement)element;
033                    if(te.isPI())
034                        encoding_ = te.getAttributeValue("encoding");
035                }
036                if(encoding_ == null) encoding_ = "utf-8";
037            }
038            return element;
039        }
040    
041    }