本文整理汇总了Java中org.jsoup.nodes.Attributes.put方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes.put方法的具体用法?Java Attributes.put怎么用?Java Attributes.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Attributes
的用法示例。
在下文中一共展示了Attributes.put方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replacePlaceholderWithNode
import org.jsoup.nodes.Attributes; //导入方法依赖的package包/类
@Test
public void replacePlaceholderWithNode() {
Map<String, Node> nodeIdMap = new HashMap<>();
String html = "<div>";
for (int i = 0; i < 5; i++) {
Attributes attrs = new Attributes();
String id = "id" + i;
attrs.put("id", id);
Element ele = new Element(Tag.valueOf("span"), "", attrs);
ele.append("The original node");
nodeIdMap.put(id, ele);
Element placeholder = ArticleUtil.generatePlaceholderNode(id);
html += placeholder.outerHtml();
}
html += "</div>";
String results = ArticleUtil.replacePlaceholderWithNode(nodeIdMap, html);
for (Node originalNode: nodeIdMap.values()) {
assertThat(results).contains(originalNode.outerHtml());
}
}
示例2: createSafeElement
import org.jsoup.nodes.Attributes; //导入方法依赖的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);
}
示例3: addMeta
import org.jsoup.nodes.Attributes; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private void addMeta(Element head, String... attributes)
{
Attributes attr = new Attributes();
for (String attribute : attributes)
{
String[] keyValue = attribute.split("=");
String key = keyValue[0];
String value = keyValue[1];
attr.put(key, value);
}
Element linkElement = new Element(Tag.valueOf("meta"), "", attr);
head.appendChild(linkElement);
}
示例4: generatePlaceholderNode
import org.jsoup.nodes.Attributes; //导入方法依赖的package包/类
/**
* Generate a non-translatable element
*/
public static Element generatePlaceholderNode(@NotNull String id) {
Attributes attrs = new Attributes();
attrs.put("id", id);
attrs.put("translate", "no");
return new Element(Tag.valueOf("var"), "", attrs);
}
示例5: getEnforcedAttributes
import org.jsoup.nodes.Attributes; //导入方法依赖的package包/类
Attributes getEnforcedAttributes(String tagName) {
Attributes attrs = new Attributes();
TagName tag = TagName.valueOf(tagName);
if (enforcedAttributes.containsKey(tag)) {
Map<AttributeKey, AttributeValue> keyVals = enforcedAttributes.get(tag);
for (Map.Entry<AttributeKey, AttributeValue> entry : keyVals.entrySet()) {
attrs.put(entry.getKey().toString(), entry.getValue().toString());
}
}
return attrs;
}
示例6: createSafeElement
import org.jsoup.nodes.Attributes; //导入方法依赖的package包/类
/**
* 按原Element重建一个新的Element
* @param sourceEl
* @return
*/
private static Element createSafeElement(Element sourceEl) {
String sourceTag = sourceEl.tagName();
Attributes destAttrs = new Attributes();
Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs);
Attributes sourceAttrs = sourceEl.attributes();
for (Attribute sourceAttr : sourceAttrs) {
destAttrs.put(sourceAttr);
}
return dest;
}
示例7: attributesCaseNormalization
import org.jsoup.nodes.Attributes; //导入方法依赖的package包/类
@Test @MultiLocaleTest public void attributesCaseNormalization() throws Exception {
ParseSettings parseSettings = new ParseSettings(false, false);
Attributes attributes = new Attributes();
attributes.put("ITEM", "1");
Attributes normalizedAttributes = parseSettings.normalizeAttributes(attributes);
assertEquals("item", normalizedAttributes.asList().get(0).getKey());
}
示例8: addLink
import org.jsoup.nodes.Attributes; //导入方法依赖的package包/类
private void addLink(Element head, String... attributes)
{
Attributes attr = new Attributes();
for (String attribute : attributes)
{
String[] keyValue = attribute.split("=");
String key = keyValue[0];
String value = keyValue[1];
attr.put(key, value);
}
Element linkElement = new Element(Tag.valueOf("link"), "", attr);
head.appendChild(linkElement);
}
示例9: setUp
import org.jsoup.nodes.Attributes; //导入方法依赖的package包/类
@Before
public void setUp() {
charsetAttributes = new Attributes();
charsetAttributes.put("charset", "UTF-8");
charsetElement = new Element(Tag.valueOf("meta"), "", charsetAttributes);
dublinElementAttributes = new Attributes();
dublinElementAttributes.put("name", "dcterms.title");
dublinElementAttributes.put("content", "CT Abdomen");
dublinElement = new Element(Tag.valueOf("meta"), "", dublinElementAttributes);
}