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.Node; 030 import nu.xom.Text; 031 import nu.xom.Attribute.Type; 032 033 /** 034 * A simpler node factory that does not use <code>Nodes</code>.. 035 * 036 * @version $Id: SimpleNodeFactory.java 150 2007-08-16 19:21:25Z hsivonen $ 037 * @author hsivonen 038 */ 039 public class SimpleNodeFactory { 040 041 /** 042 * <code>return new Attribute(localName, uri, value, type);</code> 043 * @param localName 044 * @param uri 045 * @param value 046 * @param type 047 * @return 048 */ 049 public Attribute makeAttribute(String localName, String uri, String value, Type type) { 050 return new Attribute(localName, uri, value, type); 051 } 052 053 /** 054 * <code>return new Text(string);</code> 055 * @param string 056 * @return 057 */ 058 public Text makeText(String string) { 059 return new Text(string); 060 } 061 062 /** 063 * <code>return new Comment(string);</code> 064 * @param string 065 * @return 066 */ 067 public Comment makeComment(String string) { 068 return new Comment(string); 069 } 070 071 /** 072 * <code>return new Element(name, namespace);</code> 073 * @param name 074 * @param namespace 075 * @return 076 */ 077 public Element makeElement(String name, String namespace) { 078 return new Element(name, namespace); 079 } 080 081 /** 082 * <code>return new FormPtrElement(name, namespace, form);</code> 083 * @param name 084 * @param namespace 085 * @param form 086 * @return 087 */ 088 public Element makeElement(String name, String namespace, Element form) { 089 return new FormPtrElement(name, namespace, form); 090 } 091 092 /** 093 * <code>return new ModalDocument(new Element("root", "http://www.xom.nu/fakeRoot"));</code> 094 * 095 * <p>Subclasses adviced to return an instance of <code>Mode</code>. (Not required, though.) 096 * 097 * @return 098 */ 099 public Document makeDocument() { 100 return new ModalDocument(new Element("root", "http://www.xom.nu/fakeRoot")); 101 } 102 103 }