当前位置: 首页>>代码示例>>Java>>正文


Java Attribute类代码示例

本文整理汇总了Java中org.jsoup.nodes.Attribute的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Attribute类属于org.jsoup.nodes包,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isIllegalStringInTag

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
private boolean isIllegalStringInTag(final Element tag){
	final String[] illegalWords = {"advert", "werbung", "anzeige", "adsense"};
	
	if (tag == null){
		return false;
	}
	
	for (final String word : illegalWords) {
		final Attributes tagAttrs = tag.attributes();
		if (tagAttrs != null){
			for(final Attribute attr : tagAttrs){
				if(attr.toString().toLowerCase().contains(word.toLowerCase())){
					return true;
				}
			}
		}else{
			return false;
		}
	}
	return false;
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:22,代码来源:JSoupTest.java

示例2: setQuestion

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
public void setQuestion(ExamSectionQuestion esq) {
    Document doc = Jsoup.parse(esq.getQuestion().getQuestion());
    Elements blanks = doc.select(CLOZE_SELECTOR);
    blanks.forEach(b -> {
        boolean isNumeric = isNumeric(b);
        Iterator<Attribute> it = b.attributes().iterator();
        while (it.hasNext()) {
            Attribute a = it.next();
            if (!a.getKey().equals("id")) {
                it.remove();
            }
        }
        b.tagName("input");
        b.text("");
        b.attr("type", isNumeric ? "number" : "text");
        b.attr("class", "cloze-input");
        if (isNumeric) {
            b.attr("step", "any");
            // Should allow for using both comma and period as decimal separator
            b.attr( "lang", "en-150");
        }
    });
    this.question = doc.body().children().toString();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:25,代码来源:ClozeTestAnswer.java

示例3: getExpressionReturnTypeForAttribute

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
/**
 * Guess the type of the expression based on where it is used.
 * The guessed type can be overridden by adding a Cast to the desired type at the
 * beginning of the expression.
 * @param attribute The attribute the expression is in
 * @return
 */
private String getExpressionReturnTypeForAttribute(Attribute attribute)
{
    String attributeName = attribute.getKey().toLowerCase();

    if (attributeName.indexOf("@") == 0 || attributeName.indexOf("v-on:") == 0)
        return "void";

    if ("v-if".equals(attributeName) || "v-show".equals(attributeName))
        return "boolean";

    if (currentProp != null)
        return currentProp.getType().toString();

    return Any.class.getCanonicalName();
}
 
开发者ID:Axellience,项目名称:vue-gwt,代码行数:23,代码来源:TemplateParser.java

示例4: isSafeAttribute

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
/**
 * Test if the supplied attribute is allowed by this whitelist for this tag
 * @param tagName tag to consider allowing the attribute in
 * @param el element under test, to confirm protocol
 * @param attr attribute under test
 * @return true if allowed
 */
protected boolean isSafeAttribute(String tagName, Element el, Attribute attr) {
    TagName tag = TagName.valueOf(tagName);
    AttributeKey key = AttributeKey.valueOf(attr.getKey());

    if (attributes.containsKey(tag)) {
        if (attributes.get(tag).contains(key)) {
            if (protocols.containsKey(tag)) {
                Map<AttributeKey, Set<Protocol>> attrProts = protocols.get(tag);
                // ok if not defined protocol; otherwise test
                return !attrProts.containsKey(key) || testValidProtocol(el, attr, attrProts.get(key));
            } else { // attribute found, no protocols defined, so OK
                return true;
            }
        }
    }
    // no attributes defined for tag, try :all tag
    return !tagName.equals(":all") && isSafeAttribute(":all", el, attr);
}
 
开发者ID:cpusoft,项目名称:common,代码行数:26,代码来源:Whitelist.java

示例5: updateNamespaces

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
/**
 * Finds any namespaces defined in this element. Returns any tag prefix.
 */
private String updateNamespaces(org.jsoup.nodes.Element el) {
    // scan the element for namespace declarations
    // like: xmlns="blah" or xmlns:prefix="blah"
    Attributes attributes = el.attributes();
    for (Attribute attr : attributes) {
        String key = attr.getKey();
        String prefix;
        if (key.equals(xmlnsKey)) {
            prefix = "";
        } else if (key.startsWith(xmlnsPrefix)) {
            prefix = key.substring(xmlnsPrefix.length());
        } else {
            continue;
        }
        namespaces.put(prefix, attr.getValue());
    }

    // get the element prefix if any
    int pos = el.tagName().indexOf(":");
    return pos > 0 ? el.tagName().substring(0, pos) : "";
}
 
开发者ID:cpusoft,项目名称:common,代码行数:25,代码来源:W3CDom.java

示例6: parsesBooleanAttributes

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
@Test public void parsesBooleanAttributes() {
      String html = "<a normal=\"123\" boolean empty=\"\"></a>";
      Element el = Jsoup.parse(html).select("a").first();
      
      assertEquals("123", el.attr("normal"));
      assertEquals("", el.attr("boolean"));
      assertEquals("", el.attr("empty"));
      
      List<Attribute> attributes = el.attributes().asList();
      assertEquals("There should be 3 attribute present", 3, attributes.size());
      
      // Assuming the list order always follows the parsed html
assertFalse("'normal' attribute should not be boolean", attributes.get(0) instanceof BooleanAttribute);        
assertTrue("'boolean' attribute should be boolean", attributes.get(1) instanceof BooleanAttribute);        
assertFalse("'empty' attribute should not be boolean", attributes.get(2) instanceof BooleanAttribute);        
      
      assertEquals(html, el.outerHtml());
  }
 
开发者ID:cpusoft,项目名称:common,代码行数:19,代码来源:AttributeParseTest.java

示例7: renameAllAttributeKeys

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
private static void renameAllAttributeKeys(
    ImmutableMap<String, String> renameMap, Element element) {
  Attributes attributes = element.attributes();
  for (Attribute attribute : attributes) {
    String key = attribute.getKey();
    // Polymer events are referenced as strings. As a result they do not participate in renaming.
    // Additionally, it is not valid to have a Polymer property start with "on".
    if (!key.startsWith("on-")) {
      String renamedProperty = renameMap.get(
          CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, key));
      if (renamedProperty != null) {
        attribute.setKey(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, renamedProperty));
      }
    }
  }
}
 
开发者ID:PolymerLabs,项目名称:PolymerRenamer,代码行数:17,代码来源:HtmlRenamer.java

示例8: createSafeElement

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
private ElementMeta createSafeElement(Element sourceEl) {
    String sourceTag = sourceEl.tagName();
    Attributes destAttrs = new Attributes();
    Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs);
    int numDiscarded = 0;

    Attributes sourceAttrs = sourceEl.attributes();
    for (Attribute sourceAttr : sourceAttrs) {
        if (whitelist.isSafeAttribute(sourceTag, sourceEl, sourceAttr))
            destAttrs.put(sourceAttr);
        else
            numDiscarded++;
    }
    Attributes enforcedAttrs = whitelist.getEnforcedAttributes(sourceTag);
    destAttrs.addAll(enforcedAttrs);

    return new ElementMeta(dest, numDiscarded);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:Cleaner.java

示例9: testValidProtocol

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
private boolean testValidProtocol(Element el, Attribute attr, Set<Protocol> protocols) {
    // try to resolve relative urls to abs, and optionally update the attribute so output html has abs.
    // rels without a baseuri get removed
    String value = el.absUrl(attr.getKey());
    if (value.length() == 0)
        value = attr.getValue(); // if it could not be made abs, run as-is to allow custom unknown protocols
    if (!preserveRelativeLinks)
        attr.setValue(value);
    
    for (Protocol protocol : protocols) {
        String prot = protocol.toString() + ":";
        if (value.toLowerCase().startsWith(prot)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:Nader-Sl,项目名称:BoL-API-Parser,代码行数:18,代码来源:Whitelist.java

示例10: searchDirectParentWithAttribute

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
/**
 * this method  gets the parent node of the node in param 
 * with attribute Class not null
 * @param n
 * @return
 */
public Node searchDirectParentWithAttribute(Node n){
	if (n!=null) {
		Attributes attributes =n.attributes();
		List <Attribute> list_attributes= attributes.asList();
		if (list_attributes.size()>0){
			for (int i=0; i<list_attributes.size(); i++){
				String attributeHtml =list_attributes.get(i).html();
				if(attributeHtml.toLowerCase().contains("class=")) {
					if(list_attributes.get(i).getValue().length()>0) {
						return n;
					}
				} 
			}
			return searchDirectParentWithAttribute( n.parent());
		} else {
			return searchDirectParentWithAttribute( n.parent());
		}
	} else {
		return n;
	}
}
 
开发者ID:JoanaDalmeida,项目名称:ForumsParser,代码行数:28,代码来源:ParsingPostsOnWebPage.java

示例11: isSafeAttribute

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
boolean isSafeAttribute(String tagName, Element el, Attribute attr) {
    TagName tag = TagName.valueOf(tagName);
    AttributeKey key = AttributeKey.valueOf(attr.getKey());

    if (attributes.containsKey(tag)) {
        if (attributes.get(tag).contains(key)) {
            if (protocols.containsKey(tag)) {
                Map<AttributeKey, Set<Protocol>> attrProts = protocols.get(tag);
                // ok if not defined protocol; otherwise test
                return !attrProts.containsKey(key) || testValidProtocol(el, attr, attrProts.get(key));
            } else { // attribute found, no protocols defined, so OK
                return true;
            }
        }
    } else { // no attributes defined for tag, try :all tag
        return !tagName.equals(":all") && isSafeAttribute(":all", el, attr);
    }
    return false;
}
 
开发者ID:gumulka,项目名称:JabRefAutocomplete,代码行数:20,代码来源:Whitelist.java

示例12: elementToHtml

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
/**
 * Produce predictable html (attributes in alphabetical order), always
 * include close tags
 */
private String elementToHtml(Element producedElem, StringBuilder sb) {
    ArrayList<String> names = new ArrayList<String>();
    for (Attribute a : producedElem.attributes().asList()) {
        names.add(a.getKey());
    }
    Collections.sort(names);

    sb.append("<" + producedElem.tagName() + "");
    for (String attrName : names) {
        sb.append(" ").append(attrName).append("=").append("\'")
                .append(producedElem.attr(attrName)).append("\'");
    }
    sb.append(">");
    for (Node child : producedElem.childNodes()) {
        if (child instanceof Element) {
            elementToHtml((Element) child, sb);
        } else if (child instanceof TextNode) {
            String text = ((TextNode) child).text();
            sb.append(text.trim());
        }
    }
    sb.append("</").append(producedElem.tagName()).append(">");
    return sb.toString();
}
 
开发者ID:maxschuster,项目名称:Vaadin-SignatureField,代码行数:29,代码来源:DeclarativeTestBaseBase.java

示例13: isSafeAttribute

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
/**
 * Test if the supplied attribute is allowed by this whitelist for this tag
 * @param tagName tag to consider allowing the attribute in
 * @param el element under test, to confirm protocol
 * @param attr attribute under test
 * @return true if allowed
 */
boolean isSafeAttribute(String tagName, Element el, Attribute attr) {
    TagName tag = TagName.valueOf(tagName);
    AttributeKey key = AttributeKey.valueOf(attr.getKey());

    if (attributes.containsKey(tag)) {
        if (attributes.get(tag).contains(key)) {
            if (protocols.containsKey(tag)) {
                Map<AttributeKey, Set<Protocol>> attrProts = protocols.get(tag);
                // ok if not defined protocol; otherwise test
                return !attrProts.containsKey(key) || testValidProtocol(el, attr, attrProts.get(key));
            } else { // attribute found, no protocols defined, so OK
                return true;
            }
        }
    }
    // no attributes defined for tag, try :all tag
    return !tagName.equals(":all") && isSafeAttribute(":all", el, attr);
}
 
开发者ID:danielbenedykt,项目名称:AngelList-Mobile,代码行数:26,代码来源:Whitelist.java

示例14: removeMalformedAttributes

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
/**
 * Remove the comments of the page 
 * 
 * @param node 
 */
private void removeMalformedAttributes(Node node) {
    // as we are removing child nodes while iterating, we cannot use a normal foreach over children,
    // or will get a concurrent list modification error.
    int i = 0;
    while (i < node.childNodes().size()) {
        Node child = node.childNode(i);
        for (Attribute attr : child.attributes()) {
            if (attr.getKey().startsWith("\"") && attr.getKey().endsWith("\"")) {
                child.removeAttr(attr.getKey());
            }
        }
        removeMalformedAttributes(child);
        i++;
    }
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:21,代码来源:HTMLJsoupCleanerImpl.java

示例15: parseAttributeToExtractCaptcha

import org.jsoup.nodes.Attribute; //导入依赖的package包/类
/**
 *
 * @param element
 * @return wheter either one attribute of the current element, either its
 * text, either one attribute of one of its parent or the text of one of
 * its parents contains the "captcha" keyword
 */
private boolean parseAttributeToExtractCaptcha(Element element) {
    if (element.nodeName().equalsIgnoreCase(HTML_ELEMENT) || 
            element.nodeName().equalsIgnoreCase(BODY_ELEMENT)) {
        return false;
    }
    if (StringUtils.containsIgnoreCase(element.ownText(), CAPTCHA_KEY)) {
        return true;
    } else {
        for (Attribute attr : element.attributes()) {
            if (StringUtils.containsIgnoreCase(attr.getValue(), CAPTCHA_KEY)) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:24,代码来源:CaptchaElementSelector.java


注:本文中的org.jsoup.nodes.Attribute类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。