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


Java Attribute.getKey方法代码示例

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


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

示例1: 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

示例2: 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

示例3: renameAllAnnotatedEventAttributes

import org.jsoup.nodes.Attribute; //导入方法依赖的package包/类
private void renameAllAnnotatedEventAttributes(Element element) {
  Attributes attributes = element.attributes();
  if (attributes != null) {
    for (Attribute attribute : attributes) {
      String key = attribute.getKey();
      if (key.startsWith("on-")) {
        String renamedEventHandler = renameMap.get(attribute.getValue());
        if (renamedEventHandler != null) {
          attribute.setValue(renamedEventHandler);
        }
      }
    }
  }
}
 
开发者ID:PolymerLabs,项目名称:PolymerRenamer,代码行数:15,代码来源:HtmlRenamer.java

示例4: convertAttributesToCSS

import org.jsoup.nodes.Attribute; //导入方法依赖的package包/类
/**
 * Convertit les attributs de l'élément ciblés en leurs équivalents CSS
 * @param e l'élément à modifier
 */
public static void convertAttributesToCSS(Element e) {
    Map<String, String> styles = getStyleMap(e.attr("style"));
    for(Attribute attribute : e.attributes()) {
        String key = attribute.getKey();
        String value = attribute.getValue();
        String css = HTMLtoCSSAttribute.getValue(key);
        if(css!=null) {
            styles.put(css, value);
            e.removeAttr(key);
        }
    }
    setStyle(e, styles);
    if(!getStyle(e, "size").isEmpty()) {setStyleAttribute(e, "font-size", getFontSize(e)+"pt");}//Conversion de la taille en pt
}
 
开发者ID:Sharcoux,项目名称:MathEOS,代码行数:19,代码来源:JsoupTools.java

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

    Set<AttributeKey> okSet = attributes.get(tag);
    if (okSet != null && okSet.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;
        }
    }
    // might be an enforced attribute?
    Map<AttributeKey, AttributeValue> enforcedSet = enforcedAttributes.get(tag);
    if (enforcedSet != null) {
        Attributes expect = getEnforcedAttributes(tagName);
        String attrKey = attr.getKey();
        if (expect.hasKeyIgnoreCase(attrKey)) {
            return expect.getIgnoreCase(attrKey).equals(attr.getValue());
        }
    }
    // no attributes defined for tag, try :all tag
    return !tagName.equals(":all") && isSafeAttribute(":all", el, attr);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:34,代码来源:Whitelist.java

示例6: translateAttribute

import org.jsoup.nodes.Attribute; //导入方法依赖的package包/类
private void translateAttribute(Attribute attribute, Element element, LanguageBundle bundle){
    String name = attribute.getKey();
    int firstHyphenIndex = name.indexOf('-');

    //Translate inner HTML
    if(firstHyphenIndex==-1){

        String translateKey = attribute.getValue();

        //inner HTML
        if(translateKey==null||translateKey.isEmpty())
            translateKey = element.html();

        if(translateKey.isEmpty())
            return;

        String translated = bundle.translate(translateKey);
        if(translated!=null)
            element.html(translated);
        return;

    }

    String targetAttrName = name.substring(firstHyphenIndex+1,name.length());

    if(attribute.getValue()!=null&&!attribute.getValue().isEmpty()){
        //Translate based in a key: do nothing if cant find the key
        String keyTranslation = bundle.translate(attribute.getValue());

        if(keyTranslation!=null)//Key translated successfully
            element.attr(targetAttrName,keyTranslation);

        return;
    }

    //Translate the value of the target attribute
    String targetAttrValue = element.attr(targetAttrName);
    if(targetAttrValue.isEmpty())
        return;

    String translatedValue = bundle.translate(targetAttrValue);

    if(translatedValue!=null)//Value translated successfully
        element.attr(targetAttrName,translatedValue);
}
 
开发者ID:Emerjoin,项目名称:Hi-Framework,代码行数:46,代码来源:DOMTranslator.java


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