nodewalker.java

来自「webwork source」· Java 代码 · 共 54 行

JAVA
54
字号
/* * WebWork, Web Application Framework * * Distributable under Apache license. * See terms of license at opensource.org */package webwork.view.xslt.SAXAdapter.dom;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.xml.sax.ContentHandler;import org.xml.sax.SAXException;import org.xml.sax.helpers.AttributesImpl;import webwork.view.xslt.SAXAdapter.AbstractWalker;import webwork.view.xslt.SAXAdapter.XMLWalker;import java.util.List;public class NodeWalker extends AbstractWalker{   public void doWalk(XMLWalker rootWalker, ContentHandler contentHandler, Object value, String attributeName, List walkedInstances) throws SAXException   {      Node node = (Node) value;      NamedNodeMap attributes = node.getAttributes();      AttributesImpl saxAttributes = new AttributesImpl();      if (attributes != null)      {         for (int i = 0; i < attributes.getLength(); i++)         {            Node current = attributes.item(i);            saxAttributes.addAttribute("", current.getNodeName(), "", "CDATA", current.getNodeValue());         }      }      contentHandler.startElement("", attributeName, "", saxAttributes);      NodeList children = node.getChildNodes();      if (children != null)      {         for (int i = 0; i < children.getLength(); i++)         {            rootWalker.walk(contentHandler, children.item(i), children.item(i).getNodeName(), walkedInstances);         }      }      contentHandler.endElement("", attributeName, "");   }   public final Class getWalkedType()   {      return Node.class;   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?