A base class for wrapping a W3C DOM Node as a FreeMarker template model. @author Jonathan Revusky @version $Id: NodeModel.java,v 1.80 2005/06/22 11:33:31 ddekany Exp $
| 95 | * @version $Id: NodeModel.java,v 1.80 2005/06/22 11:33:31 ddekany Exp $ |
| 96 | */ |
| 97 | abstract public class NodeModel |
| 98 | implements TemplateNodeModel, TemplateHashModel, TemplateSequenceModel, |
| 99 | AdapterTemplateModel, WrapperTemplateModel |
| 100 | { |
| 101 | |
| 102 | static final Logger logger = Logger.getLogger("freemarker.dom"); |
| 103 | |
| 104 | static private DocumentBuilderFactory docBuilderFactory; |
| 105 | |
| 106 | static private Map xpathSupportMap = Collections.synchronizedMap(new WeakHashMap()); |
| 107 | |
| 108 | static private XPathSupport jaxenXPathSupport; |
| 109 | |
| 110 | static private ErrorHandler errorHandler; |
| 111 | |
| 112 | static Class xpathSupportClass; |
| 113 | |
| 114 | static { |
| 115 | try { |
| 116 | useDefaultXPathSupport(); |
| 117 | } catch (Exception e) { |
| 118 | // do nothing |
| 119 | } |
| 120 | if (xpathSupportClass == null && logger.isWarnEnabled()) { |
| 121 | logger.warn("No XPath support is available."); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * The W3C DOM Node being wrapped. |
| 127 | */ |
| 128 | final Node node; |
| 129 | private TemplateSequenceModel children; |
| 130 | private NodeModel parent; |
| 131 | |
| 132 | /** |
| 133 | * Sets the DOM Parser implementation to be used when building NodeModel |
| 134 | * objects from XML files. |
| 135 | */ |
| 136 | static public void setDocumentBuilderFactory(DocumentBuilderFactory docBuilderFactory) { |
| 137 | NodeModel.docBuilderFactory = docBuilderFactory; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * @return the DOM Parser implementation that is used when |
| 142 | * building NodeModel objects from XML files. |
| 143 | */ |
| 144 | static public DocumentBuilderFactory getDocumentBuilderFactory() { |
| 145 | if (docBuilderFactory == null) { |
| 146 | docBuilderFactory = DocumentBuilderFactory.newInstance(); |
| 147 | docBuilderFactory.setNamespaceAware(true); |
| 148 | docBuilderFactory.setIgnoringElementContentWhitespace(true); |
| 149 | } |
| 150 | return docBuilderFactory; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * sets the error handler to use when parsing the document. |
nothing calls this directly
no test coverage detected
searching dependent graphs…