001    /*
002     * Copyright (c) 2007 Henri Sivonen
003     *
004     * Permission is hereby granted, free of charge, to any person obtaining a 
005     * copy of this software and associated documentation files (the "Software"), 
006     * to deal in the Software without restriction, including without limitation 
007     * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
008     * and/or sell copies of the Software, and to permit persons to whom the 
009     * Software is furnished to do so, subject to the following conditions:
010     *
011     * The above copyright notice and this permission notice shall be included in 
012     * all copies or substantial portions of the Software.
013     *
014     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
015     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
016     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
017     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
018     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
019     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
020     * DEALINGS IN THE SOFTWARE.
021     */
022    
023    package nu.validator.htmlparser.xom;
024    
025    import nu.xom.Attribute;
026    import nu.xom.Comment;
027    import nu.xom.Document;
028    import nu.xom.Element;
029    import nu.xom.Text;
030    import nu.xom.Attribute.Type;
031    
032    /**
033     * A simpler node factory that does not use <code>Nodes</code>..
034     * 
035     * @version $Id$
036     * @author hsivonen
037     */
038    public class SimpleNodeFactory {
039    
040        /**
041         * <code>return new Attribute(localName, uri, value, type);</code>
042         * @param localName
043         * @param uri
044         * @param value
045         * @param type
046         * @return
047         */
048        public Attribute makeAttribute(String localName, String uri, String value, Type type) {
049            return new Attribute(localName, uri, value, type);
050        }
051    
052        /**
053         * <code>return new Text(string);</code>
054         * @param string
055         * @return
056         */
057        public Text makeText(String string) {
058            return new Text(string);
059        }
060    
061        /**
062         * <code>return new Comment(string);</code>
063         * @param string
064         * @return
065         */
066        public Comment makeComment(String string) {
067            return new Comment(string);
068        }
069    
070        /**
071         * <code>return new Element(name, namespace);</code>
072         * @param name
073         * @param namespace
074         * @return
075         */
076        public Element makeElement(String name, String namespace) {
077            return new Element(name, namespace);
078        }
079    
080        /**
081         * <code>return new FormPtrElement(name, namespace, form);</code>
082         * @param name
083         * @param namespace
084         * @param form
085         * @return
086         */
087        public Element makeElement(String name, String namespace, Element form) {
088            return new FormPtrElement(name, namespace, form);
089        }
090        
091        /**
092         * <code>return new ModalDocument(new Element("root", "http://www.xom.nu/fakeRoot"));</code>
093         * 
094         * <p>Subclasses adviced to return an instance of <code>Mode</code>. (Not required, though.)
095         * 
096         * @return
097         */
098        public Document makeDocument() {
099            return new ModalDocument(new Element("root", "http://www.xom.nu/fakeRoot"));
100        }
101        
102    }