private Tag newTag(Class<? extends Tag> klass) { Tag tag = null; try { tag = klass.newInstance(); tag.setTagName(tag.getTagName().toLowerCase()); Tag endTag = klass.newInstance(); endTag.setTagName("/" + tag.getTagName().toLowerCase()); endTag.setParent(tag); tag.setEndTag(endTag); } catch (Exception e) { e.printStackTrace(); } return tag; }
public void visitTag(Tag tag) { for (int i = 0; i < tagsToBeFound.length; i++) if (tag.getTagName().equalsIgnoreCase(tagsToBeFound[i])) { count[i]++; tags[i].add(tag); } }
/** * Extract the object <code>PARAM</code> tags from the child list. * * @return The list of object parameters (keys and values are String objects). */ public HashMap createObjectParamsTable() { NodeList kids; Node node; Tag tag; String paramName; String paramValue; HashMap ret; ret = new HashMap(); kids = getChildren(); if (null != kids) for (int i = 0; i < kids.size(); i++) { node = children.elementAt(i); if (node instanceof Tag) { tag = (Tag) node; if (tag.getTagName().equals("PARAM")) { paramName = tag.getAttribute("NAME"); if (null != paramName && 0 != paramName.length()) { paramValue = tag.getAttribute("VALUE"); ret.put(paramName.toUpperCase(), paramValue); } } } } return (ret); }
public void visitEndTag(Tag tag) { if (!endTagCheck) return; for (int i = 0; i < tagsToBeFound.length; i++) if (tag.getTagName().equalsIgnoreCase(tagsToBeFound[i])) { endTagCount[i]++; endTags[i].add(tag); } }
/** * Returns true if a given tag is allowed. Also, it checks and removes any unwanted attribute the * tag may contain. * * @param node The tag node to analyze * @return true if it is a valid tag. */ private boolean isTagWelcome(Node node) { Tag tag = (Tag) node; if (!welcomeTags.contains(tag.getTagName())) { return false; } this.checkAndValidateAttributes(tag, true); return true; }
public int getEndLine() { int nr = arg0.getStartingLineNumber() + 1; int nrE = nr; Tag endTag = arg0.getEndTag(); if (endTag != null) { nrE = endTag.getEndingLineNumber(); int offset = endTag.getStartPosition() - endTag.getEndPosition(); if (offset == 0) fEditor.addProblemMarker( endTag.getTagName().toLowerCase() + " is not correctly closed proposed line for closing is line " + nrE, nr, IMarker.SEVERITY_WARNING); } return nrE; }
/** Test child filtering. */ public void testChild() throws ParserException { String guts; String html; NodeList list; guts = "<body>Now is the <a id=target><b>time</b></a> for all good <a href=http://bongo.com>men</a>..</body>"; html = "<html>" + guts + "</html>"; createParser(html); list = parser.extractAllNodesThatMatch(new HasChildFilter(new TagNameFilter("b"))); assertEquals("only one element", 1, list.size()); assertType("should be LinkTag", LinkTag.class, list.elementAt(0)); LinkTag link = (LinkTag) list.elementAt(0); assertEquals("three children", 3, link.getChildCount()); assertSuperType("should be TagNode", Tag.class, link.getChildren().elementAt(0)); Tag tag = (Tag) link.getChildren().elementAt(0); assertStringEquals("name", "B", tag.getTagName()); }
@Override public void visitTag(Tag tag) { Element e = Document.get().createElement(tag.getTagName()); map.put(tag, e); for (Object o : tag.getAttributesEx()) { Attribute a = (Attribute) o; if ("id".equalsIgnoreCase(a.getName())) { e.setId(a.getValue()); } else if ("style".equalsIgnoreCase(a.getName())) { processStyle(e, a.getValue()); } else if ("class".equalsIgnoreCase(a.getName())) { e.setClassName(a.getValue()); } else if (!a.isEmpty() && !a.isWhitespace() && a.isValued()) { e.setAttribute(a.getName(), a.getValue()); } } Element parent = getParent(tag.getParent()); parent.appendChild(e); }
public void assertTagNameShouldBe(String message, Node node, String expectedTagName) { Tag tag = (Tag) node; assertStringEquals(message, expectedTagName, tag.getTagName()); }