htmlpolicy.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 704 行 · 第 1/2 页

JAVA
704
字号
      case BASEFONT: case BR: case AREA: case LINK: case IMG: case PARAM:       case HR: case INPUT: case FRAME: case ISINDEX:       case BASE: case META:	return PUSH_EMPTY;      case TD: case TH:        return PUSH;      case SCRIPT: case STYLE:        return PUSH_VERBATIM;      default:        return PUSH;      }    case TD: case TH:      switch (nextCode) {      case THEAD: case TFOOT: case TBODY: case COLGROUP: case COL: case TR:      case TD: case TH:	return POP;      case BASEFONT: case BR: case AREA: case LINK: case IMG: case PARAM:       case HR: case INPUT: case FRAME: case ISINDEX:       case BASE: case META:	return PUSH_EMPTY;      case SCRIPT: case STYLE:        return PUSH_VERBATIM;      default:	return PUSH;      }    case P: case DT:      switch (nextCode) {      case BLOCK: case P: case TABLE: case CAPTION: case THEAD:      case TFOOT: case COLGROUP: case TBODY: case TR: case TD:       case TH: case DT: case LI:	return POP;      case BASEFONT: case BR: case AREA: case LINK: case IMG: case PARAM:       case HR: case INPUT: case COL: case FRAME: case ISINDEX:       case BASE: case META:	return PUSH_EMPTY;      case SCRIPT: case STYLE:        return PUSH_VERBATIM;      default:	return PUSH;      }    case TABLE:      switch (nextCode) {      case CAPTION: case THEAD: case TFOOT: case COL: case COLGROUP:      case TBODY: case TR:	return PUSH;      case SCRIPT: case STYLE:        return PUSH_VERBATIM;      default:        /*	opt = "tr";	return PUSH_OPT;        */        return PUSH;      }    default:      switch (nextCode) {      case BASEFONT: case BR: case AREA: case LINK: case IMG: case PARAM:       case HR: case INPUT: case COL: case FRAME: case ISINDEX:       case BASE: case META:	return PUSH_EMPTY;      case SCRIPT: case STYLE:        return PUSH_VERBATIM;      default:	return PUSH;      }    }  }  private static CharScanner charsetScanner = new CharScanner(" \t=;");  private void checkMetaEncoding(Element elt)  {    String http = elt.getAttribute("http-equiv");    String content = elt.getAttribute("content");    if (http.equals("") || content.equals("") ||	! http.equalsIgnoreCase("content-type"))      return;    CharCursor cursor = new StringCharCursor(content);    charsetScanner.scan(cursor);    charsetScanner.skip(cursor);    CharBuffer buf = CharBuffer.allocate();    while (cursor.current() != cursor.DONE) {      buf.clear();      charsetScanner.scan(cursor, buf);      if (buf.toString().equalsIgnoreCase("charset")) {	charsetScanner.skip(cursor);	buf.clear();	charsetScanner.scan(cursor, buf);	if (buf.length() > 0) {	  try {	    is.setEncoding(buf.close());	  } catch (IOException e) {	  }	  return;	}      }    }  }  int elementCloseAction(XmlParser parser, QName node, String tagEnd)    throws XmlParseException  {    String nodeName = node.getName();    if (nodeName.equals(tagEnd))      return POP;    if (nodeName == "#document" && tagEnd.equals("")) {      /*      Document doc = (Document) node;      // If JSP, move any text into the body element      if (isJsp && doc.getDocumentElement() == null &&          node.getFirstChild() instanceof Text) {        Element html = doc.createElement("html");        doc.appendChild(html);        Element body = doc.createElement("body");        html.appendChild(body);        Node child;        while ((child = doc.getFirstChild()) instanceof Text ||        child instanceof Comment) {          body.appendChild(child);        }      }      */      return POP;    }    switch (names.get(tagEnd)) {    case BASEFONT: case BR: case AREA: case LINK: case IMG: case PARAM:     case HR: case INPUT: case COL: case FRAME: case ISINDEX:     case BASE: case META:      String errorTagEnd;      if (tagEnd.equals(""))        errorTagEnd = L.l("end of file");      else        errorTagEnd = "`<" + tagEnd + ">'";      throw parser.error(L.l("{0} expects to be empty",                             errorTagEnd));    }    switch (names.get(nodeName)) {    case BODY: case P:    case DT: case DD: case LI: case OPTION:    case THEAD: case TFOOT: case TBODY: case COLGROUP:     case TR: case TH: case TD:      return POP_AND_LOOP;    case HTML:    case HEAD:      // If JSP and missing a body, move any text into the body element      /*      if (isJsp && node.getLastChild() instanceof Text) {        Node child;        for (child = node.getLastChild();             child != null;             child = child.getPreviousSibling()) {          if (child.getNodeName().equals("body"))            return POP_AND_LOOP;        }        Document doc = node.getOwnerDocument();        Element body = doc.createElement("body");                while ((child = node.getLastChild()) instanceof Text ||               child instanceof Comment) {          body.insertBefore(child, body.getFirstChild());        }                doc.getDocumentElement().appendChild(body);      }      */      return POP_AND_LOOP;    default:      if (forgiving) {        /*	Node parent = node;	for (; parent != null; parent = parent.getParentNode()) {	  if (parent.getNodeName().equals(tagEnd))	    return POP_AND_LOOP;	}	return IGNORE;        */        return POP_AND_LOOP;      }            String errorTagEnd;      if (tagEnd.equals(""))        errorTagEnd = L.l("end of file");      else        errorTagEnd = "`</" + tagEnd + ">'";      String expect;      if (nodeName.equals("#document")) {        throw parser.error(L.l("expected {0} at {1}",                               L.l("end of document"), errorTagEnd));      }      else	expect = "`</" + nodeName + ">'";      throw parser.error(L.l("expected {0} at {1} (open at {2})",                             expect, errorTagEnd,                             "" + parser.getNodeLine()));    }  }  private static void addName(String name, int code)  {    names.put(name, code);    cbNames.put(new CharBuffer(name), code);    String upper = name.toUpperCase();    names.put(upper, code);    cbNames.put(new CharBuffer(upper), code);  }  static {    names = new IntMap();    cbNames = new IntMap();        addName("#document", DOCUMENT);    addName("#comment", COMMENT);    addName("#text", TEXT);    addName("#jsp", JSP);    addName("#whitespace", WHITESPACE);    addName("html", HTML);    addName("head", HEAD);    addName("title", TITLE);    addName("isindex", ISINDEX);    addName("base", BASE);    addName("script", SCRIPT);    addName("style", STYLE);    addName("meta", META);    addName("link", LINK);    addName("object", OBJECT);    addName("body", BODY);    addName("basefont", BASEFONT);    addName("br", BR);    addName("area", AREA);    addName("link", LINK);    addName("img", IMG);    addName("param", PARAM);    addName("hr", HR);    addName("input", INPUT);    addName("frame", FRAME);    addName("p", P);    addName("dt", DT);    addName("dd", DD);    addName("li", LI);    addName("option", OPTION);    addName("table", TABLE);    addName("caption", CAPTION);    addName("thead", THEAD);    addName("tfoot", TFOOT);    addName("col", COL);    addName("colgroup", COLGROUP);    addName("tbody", TBODY);    addName("tr", TR);    addName("th", TH);    addName("td", TD);    addName("h1", BLOCK);    addName("h2", BLOCK);    addName("h3", BLOCK);    addName("h4", BLOCK);    addName("h5", BLOCK);    addName("h6", BLOCK);    addName("ul", BLOCK);    addName("ol", BLOCK);    addName("dir", BLOCK);    addName("menu", BLOCK);    addName("pre", BLOCK);    addName("dl", BLOCK);    addName("div", BLOCK);    addName("center", BLOCK);    addName("noscript", BLOCK);    addName("noframes", BLOCK);    addName("blockquote", BLOCK);    addName("form", BLOCK);    addName("fieldset", BLOCK);    addName("address", BLOCK);    addName("tt", INLINE);    addName("i", INLINE);    addName("b", INLINE);    addName("u", INLINE);    addName("s", INLINE);    addName("strike", INLINE);    addName("big", INLINE);    addName("small", INLINE);    addName("em", INLINE);    addName("strong", INLINE);    addName("dfn", INLINE);    addName("code", INLINE);    addName("samp", INLINE);    addName("kbd", INLINE);    addName("var", INLINE);    addName("cite", INLINE);    addName("abbr", INLINE);    addName("acronym", INLINE);    addName("font", INLINE);    addName("iframe", INLINE);    addName("applet", INLINE);    addName("ins", INLINE);    addName("del", INLINE);    addName("a", INLINE);    addName("map", INLINE);    addName("q", INLINE);    addName("sub", INLINE);    addName("sup", INLINE);    addName("span", INLINE);    addName("bdo", INLINE);    addName("select", INLINE);    addName("textarea", INLINE);    addName("label", INLINE);    addName("optgroup", INLINE);    addName("button", INLINE);    addName("legend", INLINE);    addName("frameset", FRAMESET);    // CDATA -- STYLE, SCRIPT  }}

⌨️ 快捷键说明

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