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


Java Attributes类代码示例

本文整理汇总了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;
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:22,代码来源:JSoupTest.java

示例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);
}
 
开发者ID:Juchar,项目名称:md-stepper,代码行数:25,代码来源:AbstractStepper.java

示例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());
    }
}
 
开发者ID:zanata,项目名称:zanata-mt,代码行数:23,代码来源:ArticleUtilTest.java

示例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) : "";
}
 
开发者ID:cpusoft,项目名称:common,代码行数:25,代码来源:W3CDom.java

示例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));
      }
    }
  }
}
 
开发者ID:PolymerLabs,项目名称:PolymerRenamer,代码行数:17,代码来源:HtmlRenamer.java

示例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);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:Cleaner.java

示例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;
}
 
开发者ID:LTBuses,项目名称:LTB-android,代码行数:18,代码来源:LTCScraper.java

示例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;

}
 
开发者ID:LTBuses,项目名称:LTB-android,代码行数:20,代码来源:LTCScraper.java

示例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;

}
 
开发者ID:LTBuses,项目名称:LTB-android,代码行数:20,代码来源:LTCScraper.java

示例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;
	}
}
 
开发者ID:JoanaDalmeida,项目名称:ForumsParser,代码行数:28,代码来源:ParsingPostsOnWebPage.java

示例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);
    }
}
 
开发者ID:maxschuster,项目名称:Vaadin-SignatureField,代码行数:19,代码来源:SignatureField.java

示例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);

}
 
开发者ID:bsutton,项目名称:scoutmaster,代码行数:17,代码来源:VaadinServlet.java

示例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);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:29,代码来源:HeadCleaner.java

示例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()));
    }
}
 
开发者ID:blackbluegl,项目名称:calendar-component,代码行数:28,代码来源:Calendar.java

示例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));
}
 
开发者ID:Cognifide,项目名称:knotx,代码行数:9,代码来源:DefaultFormSimplifier.java


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