本文整理汇总了Java中org.jsoup.nodes.Attributes类的典型用法代码示例。如果您正苦于以下问题:Java Attributes类的具体用法?Java Attributes怎么用?Java Attributes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Attributes类属于org.jsoup.nodes包,在下文中一共展示了Attributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isIllegalStringInTag
import org.jsoup.nodes.Attributes; //导入依赖的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;
}
示例2: readDesign
import org.jsoup.nodes.Attributes; //导入依赖的package包/类
@Override
public void readDesign(Element design, DesignContext designContext) {
super.readDesign(design, designContext);
for (Element child : design.children()) {
Component childComponent = designContext.readDesign(child);
if (!(childComponent instanceof Step)) {
throw new IllegalArgumentException("Only implementations of " + Step.class.getName() +
" are allowed as children of " + getClass().getName());
}
stepIterator.add(((Step) childComponent));
}
boolean linear = false;
Attributes attributes = design.attributes();
if (attributes.hasKey(DESIGN_ATTRIBUTE_LINEAR)) {
linear = DesignAttributeHandler.getFormatter()
.parse(design.attr(DESIGN_ATTRIBUTE_LINEAR), Boolean.class);
}
stepIterator.setLinear(linear);
}
示例3: 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());
}
}
示例4: updateNamespaces
import org.jsoup.nodes.Attributes; //导入依赖的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) : "";
}
示例5: renameAllAttributeKeys
import org.jsoup.nodes.Attributes; //导入依赖的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));
}
}
}
}
示例6: 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);
}
示例7: loadRoutes
import org.jsoup.nodes.Attributes; //导入依赖的package包/类
public ArrayList<LTCRoute> loadRoutes() throws ScrapeException, IOException {
ArrayList<LTCRoute> routes = new ArrayList<LTCRoute>();
Document doc = parseDocFromUri(ROUTE_PATH, ROUTE_PATH);
Elements routeLinks = doc.select("a[href]");
for (Element routeLink : routeLinks) {
String name = routeLink.text();
Attributes attrs = routeLink.attributes();
String href = attrs.get("href");
Matcher m = ROUTE_NUM_PATTERN.matcher(href);
if (m.find()) {
String number = m.group(1);
LTCRoute route = new LTCRoute(number, name/*, href*/);
routes.add(route);
}
}
return routes;
}
示例8: loadDirections
import org.jsoup.nodes.Attributes; //导入依赖的package包/类
ArrayList<LTCDirection> loadDirections(String routeNum) throws ScrapeException, IOException {
ArrayList<LTCDirection> directions = new ArrayList<LTCDirection>(2); // probably 2
String path = String.format(DIRECTION_PATH, routeNum);
Document doc = parseDocFromUri(path, path);
Elements dirLinks = doc.select("a[href]");
for (Element dirLink : dirLinks) {
String name = dirLink.text();
Attributes attrs = dirLink.attributes();
String href = attrs.get("href");
Matcher m = DIRECTION_NUM_PATTERN.matcher(href);
if (m.find()) {
Integer number = Integer.valueOf(m.group(1));
LTCDirection dir = new LTCDirection(number, name);
directions.add(dir);
}
}
return directions;
}
示例9: loadStops
import org.jsoup.nodes.Attributes; //导入依赖的package包/类
HashMap<Integer, LTCStop> loadStops(String routeNum, int direction) throws ScrapeException, IOException {
HashMap<Integer, LTCStop> stops = new HashMap<Integer, LTCStop>();
String path = String.format(STOPS_PATH, routeNum, direction);
Document doc = parseDocFromUri(path, path);
Elements stopLinks = doc.select("a[href]");
for (Element stopLink : stopLinks) {
String name = stopLink.text();
Attributes attrs = stopLink.attributes();
String href = attrs.get("href");
Matcher m = STOP_NUM_PATTERN.matcher(href);
if (m.find()) {
Integer number = Integer.valueOf(m.group(1));
LTCStop stop = new LTCStop(number, name);
stops.put(stop.number, stop);
}
}
return stops;
}
示例10: searchDirectParentWithAttribute
import org.jsoup.nodes.Attributes; //导入依赖的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;
}
}
示例11: readDesign
import org.jsoup.nodes.Attributes; //导入依赖的package包/类
@Override
public void readDesign(Element design, DesignContext designContext) {
super.readDesign(design, designContext);
Attributes attr = design.attributes();
if (attr.hasKey("mime-type")) {
MimeType mimeType = null;
String mimeTypeString = DesignAttributeHandler.getFormatter().parse(
attr.get("mime-type"), String.class);
try {
mimeType = MimeType.valueOfMimeType(mimeTypeString);
} catch (IllegalArgumentException e) {
Logger.getLogger(SignatureField.class.getName()).info(
"Unsupported MIME-Type found when reading from design : "
.concat(mimeTypeString));
}
setMimeType(mimeType);
}
}
示例12: 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);
}
示例13: head
import org.jsoup.nodes.Attributes; //导入依赖的package包/类
public void head(Node source, int depth) {
if (skipChildren) {
return;
}
if (source instanceof Element) {
Element sourceElement = (Element) source;
if (isSafeTag(sourceElement)) {
String sourceTag = sourceElement.tagName();
Attributes destinationAttributes = sourceElement.attributes().clone();
Element destinationChild = new Element(Tag.valueOf(sourceTag), sourceElement.baseUri(), destinationAttributes);
destination.appendChild(destinationChild);
destination = destinationChild;
} else if (source != root) {
skipChildren = true;
}
} else if (source instanceof TextNode) {
TextNode sourceText = (TextNode) source;
TextNode destinationText = new TextNode(sourceText.getWholeText(), source.baseUri());
destination.appendChild(destinationText);
} else if (source instanceof DataNode && isSafeTag(source.parent())) {
DataNode sourceData = (DataNode) source;
DataNode destinationData = new DataNode(sourceData.getWholeData(), source.baseUri());
destination.appendChild(destinationData);
}
}
示例14: readDesign
import org.jsoup.nodes.Attributes; //导入依赖的package包/类
@Override
public void readDesign(Element design, DesignContext designContext) {
super.readDesign(design, designContext);
Attributes attr = design.attributes();
if (design.hasAttr("time-zone")) {
setZoneId(ZoneId.of(DesignAttributeHandler.readAttribute("end-date", attr, String.class)));
}
if (design.hasAttr("time-format")) {
setTimeFormat(TimeFormat.valueOf(
"Format" + design.attr("time-format").toUpperCase()));
}
if (design.hasAttr("start-date")) {
setStartDate(
ZonedDateTime.ofInstant(DesignAttributeHandler.readAttribute("start-date", attr, Date.class)
.toInstant(), getZoneId()));
}
if (design.hasAttr("end-date")) {
setEndDate(
ZonedDateTime.ofInstant(DesignAttributeHandler.readAttribute("end-date", attr, Date.class)
.toInstant(), getZoneId()));
}
}
示例15: addHiddenInputTag
import org.jsoup.nodes.Attributes; //导入依赖的package包/类
private void addHiddenInputTag(Element form, String formIdAttrName, String formIdAttrValue) {
Attributes attributes = Stream.of(
new Attribute("type", "hidden"),
new Attribute("name", formIdAttrName),
new Attribute("value", formIdAttrValue))
.collect(Attributes::new, Attributes::put, Attributes::addAll);
form.prependChild(new Element(Tag.valueOf("input"), "/", attributes));
}