Java Code Examples for org.htmlcleaner.TagNode#getAttributeByName()
The following examples show how to use
org.htmlcleaner.TagNode#getAttributeByName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlUtil.java From ispider with Apache License 2.0 | 6 votes |
/** * 得到url列表 * @param tagNode * @param attr * @param xpath * @return */ public static List<String> getListUrlByXpath(TagNode tagNode, String attr, String xpath) { List<String> urls = new ArrayList<>(); try { Object[] objs = tagNode.evaluateXPath(xpath); if (objs != null && objs.length > 0) { for (Object obj : objs) { TagNode aTagNode = (TagNode) obj; String url = aTagNode.getAttributeByName(attr); urls.add("https:" + url); } } return urls; } catch (XPatherException e) { e.printStackTrace(); } return null; }
Example 2
Source File: AlignmentAttributeHandler.java From SDHtmlTextView with Apache License 2.0 | 6 votes |
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end, Style style, SpanStack spanStack) { String align = node.getAttributeByName("align"); if ( "right".equalsIgnoreCase(align) ) { style = style.setTextAlignment(Style.TextAlignment.RIGHT); } else if ( "center".equalsIgnoreCase(align) ) { style = style.setTextAlignment(Style.TextAlignment.CENTER); } else if ( "left".equalsIgnoreCase(align) ) { style = style.setTextAlignment(Style.TextAlignment.LEFT); } super.handleTagNode(node, builder, start, end, style, spanStack); }
Example 3
Source File: ResponseRenderPrintWriter.java From zrlog with Apache License 2.0 | 6 votes |
private void parseCustomHtmlTag(HtmlCleaner htmlCleaner, Map<String, String> plugin, TagNode tag, String tagName) throws IOException { if ("plugin".equals(tagName) && tag.hasAttribute("name")) { tag.setForeignMarkup(true); Map<String, String> tmp = new LinkedHashMap<>(tag.getAttributes()); tmp.put("_tmp", System.currentTimeMillis() + ""); tag.setAttributes(tmp); SimpleHtmlSerializer serializer = new SimpleHtmlSerializer(htmlCleaner.getProperties()); StringWriter stringWriter = new StringWriter(); tag.serialize(serializer, stringWriter); String content = stringWriter.toString(); try { String url = "/" + tag.getAttributeByName("name") + "/" + tag.getAttributeByName("view"); if (tag.hasAttribute("param")) { url += "?" + tag.getAttributeByName("param"); } CloseResponseHandle handle = PluginHelper.getContext(url, "GET", request, false, adminTokenVO); byte[] bytes = IOUtil.getByteByInputStream(handle.getT().getEntity().getContent()); plugin.put(content, new String(bytes, StandardCharsets.UTF_8)); } catch (Exception e) { LOGGER.error("", e); } } }
Example 4
Source File: HtmlUtil.java From ispider with Apache License 2.0 | 5 votes |
/** * 根据xpath和属性获取对应标签的属性值 * * @param tagNode * @param attr * @param xpath * @return */ public static String getAttrByXpath(TagNode tagNode, String attr, String xpath) { try { Object[] objs = tagNode.evaluateXPath(xpath); if (objs != null && objs.length > 0) { TagNode node = (TagNode) objs[0]; return node.getAttributeByName(attr); } } catch (XPatherException e) { e.printStackTrace(); } return null; }
Example 5
Source File: ListsHandler.java From mvvm-template with GNU General Public License v3.0 | 5 votes |
@Override public void beforeChildren(TagNode node, SpannableStringBuilder builder) { TodoItems todoItem = null; if (node.getChildTags() != null && node.getChildTags().length > 0) { for (TagNode tagNode : node.getChildTags()) { Logger.e(tagNode.getName(), tagNode.getText()); if (tagNode.getName() != null && tagNode.getName().equals("input")) { todoItem = new TodoItems(); todoItem.isChecked = tagNode.getAttributeByName("checked") != null; break; } } } if ("ol".equals(getParentName(node))) { builder.append(String.valueOf(getMyIndex(node))).append(". "); } else if ("ul".equals(getParentName(node))) { if (todoItem != null) { if (checked == null || unchecked == null) { builder.append(todoItem.isChecked ? "☑" : "☐"); } else { builder.append(SpannableBuilder.builder() .append(todoItem.isChecked ? checked : unchecked)) .append(" "); } } else { builder.append("\u2022 "); } } }
Example 6
Source File: DrawableHandler.java From mvvm-template with GNU General Public License v3.0 | 5 votes |
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end) { String src = node.getAttributeByName("src"); if (!InputHelper.isEmpty(src)) { builder.append(""); if (isNull()) return; DrawableGetter imageGetter = new DrawableGetter(textView, width); builder.setSpan(new ImageSpan(imageGetter.getDrawable(src)), start, builder.length(), SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new CenterSpan(), start, builder.length(), SPAN_EXCLUSIVE_EXCLUSIVE); appendNewLine(builder); } }
Example 7
Source File: LinkHandler.java From mvvm-template with GNU General Public License v3.0 | 5 votes |
@Override public void handleTagNode(TagNode node, SpannableStringBuilder spannableStringBuilder, int start, int end) { String href = node.getAttributeByName("href"); if (href != null) { spannableStringBuilder.setSpan(new LinkSpan(href, linkColor), start, end, 33); } else if (node.getText() != null) { spannableStringBuilder.setSpan(new LinkSpan("https://github.com/" + node.getText().toString(), linkColor), start, end, 33); } }
Example 8
Source File: CSSCompiler.java From SDHtmlTextView with Apache License 2.0 | 5 votes |
@Override public boolean matches(TagNode tagNode) { if ( tagNode == null ) { return false; } //If a tag name is given it should match if (tagName != null && tagName.length() > 0 && ! tagName.equals(tagNode.getName() ) ) { return false; } String classAttribute = tagNode.getAttributeByName("class"); return classAttribute != null && classAttribute.equals(className); }
Example 9
Source File: CSSCompiler.java From SDHtmlTextView with Apache License 2.0 | 5 votes |
@Override public boolean matches(TagNode tagNode) { if ( tagNode == null ) { return false; } String idAttribute = tagNode.getAttributeByName("id"); return idAttribute != null && idAttribute.equals( id ); }
Example 10
Source File: BorderAttributeHandler.java From SDHtmlTextView with Apache License 2.0 | 5 votes |
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end, Style useStyle, SpanStack spanStack) { if ( node.getAttributeByName("border") != null ) { Log.d("BorderAttributeHandler", "Adding BorderSpan from " + start + " to " + end); spanStack.pushSpan(new BorderSpan(useStyle, start, end, getSpanner().isUseColoursFromStyle() ), start, end); } super.handleTagNode(node, builder, start, end, useStyle, spanStack); }
Example 11
Source File: StyleAttributeHandler.java From SDHtmlTextView with Apache License 2.0 | 5 votes |
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end, Style useStyle, SpanStack spanStack) { String styleAttr = node.getAttributeByName("style"); if ( getSpanner().isAllowStyling() && styleAttr != null ) { super.handleTagNode(node, builder, start, end, parseStyleFromAttribute(useStyle, styleAttr), spanStack); } else { super.handleTagNode(node, builder, start, end, useStyle, spanStack); } }
Example 12
Source File: LinkHandler.java From SDHtmlTextView with Apache License 2.0 | 5 votes |
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end, SpanStack spanStack) { final String href = node.getAttributeByName("href"); spanStack.pushSpan(new URLSpan(href), start, end); }
Example 13
Source File: TableHandler.java From mvvm-template with GNU General Public License v3.0 | 3 votes |
private Table getTable(TagNode node) { String border = node.getAttributeByName("border"); boolean drawBorder = !"0".equals(border); Table result = new Table(drawBorder); readNode(node, result); return result; }
Example 14
Source File: TableHandler.java From SDHtmlTextView with Apache License 2.0 | 3 votes |
private Table getTable(TagNode node) { String border = node.getAttributeByName("border"); boolean drawBorder = !"0".equals(border)&& border!=null ; Table result = new Table(drawBorder); readNode(node, result); return result; }