- Common ways to obtain Attributes
private void myMethod () {Attributes a =
Element design;design.attributes()
new Attributes()
Node node;node.attributes()
- Smart code suggestions by Codota
}
/** Set the attribute value. @param val the new attribute value; must not be null */ public String setValue(String val) { String oldVal = parent.get(this.key); if (parent != null) { int i = parent.indexOfKey(this.key); if (i != Attributes.NotFound) parent.vals[i] = val; } this.val = val; return oldVal; }
@Override public String put(String key, String value) { String dataKey = dataKey(key); String oldValue = attributes.hasKey(dataKey) ? attributes.get(dataKey) : null; attributes.put(dataKey, value); return oldValue; }
return tb.process(t, InHead); } else if (name.equals("input")) { if (!startTag.attributes.get("type").equalsIgnoreCase("hidden")) { return anythingElse(t, tb); } else {
@Override public void readDesign(Element design, DesignContext designContext) { // process default attributes super.readDesign(design, designContext); // handle children for (Element childComponent : design.children()) { Attributes attr = childComponent.attributes(); Component newChild = designContext.readDesign(childComponent); StringBuilder css = new StringBuilder(); if (attr.hasKey(ATTR_TOP)) { css.append("top:").append(attr.get(ATTR_TOP)).append(';'); } if (attr.hasKey(ATTR_RIGHT)) { css.append("right:").append(attr.get(ATTR_RIGHT)).append(';'); } if (attr.hasKey(ATTR_BOTTOM)) { css.append("bottom:").append(attr.get(ATTR_BOTTOM)).append(';'); } if (attr.hasKey(ATTR_LEFT)) { css.append("left:").append(attr.get(ATTR_LEFT)).append(';'); } if (attr.hasKey(ATTR_Z_INDEX)) { css.append("z-index:").append(attr.get(ATTR_Z_INDEX)) .append(';'); } addComponent(newChild, css.toString()); } }
void processAttributes(Node node) { Attributes attributes = myState.myAttributes; if (myOptions.outputAttributesIdAttr || !myOptions.outputAttributesNamesRegex.isEmpty()) { final org.jsoup.nodes.Attributes nodeAttributes = node.attributes(); boolean idDone = false; if (myOptions.outputAttributesIdAttr) { String id = nodeAttributes.get("id"); if (id == null || id.isEmpty()) { id = nodeAttributes.get("name"); } if (id != null && !id.isEmpty()) { attributes.replaceValue("id", id); idDone = true; } } if (!myOptions.outputAttributesNamesRegex.isEmpty()) { for (org.jsoup.nodes.Attribute attribute : nodeAttributes) { if (idDone && (attribute.getKey().equals("id") || attribute.getKey().equals("name"))) { continue; } if (attribute.getKey().matches(myOptions.outputAttributesNamesRegex)) { attributes.replaceValue(attribute.getKey(), attribute.getValue()); } } } } }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attributes = design.attributes(); if (design.hasAttr("color")) { // Ignore the # character String hexColor = DesignAttributeHandler .readAttribute("color", attributes, String.class) .substring(1); doSetValue(new Color(Integer.parseInt(hexColor, 16))); } if (design.hasAttr("popup-style")) { setPopupStyle(PopupStyle.valueOf("POPUP_" + attributes.get("popup-style").toUpperCase(Locale.ROOT))); } if (design.hasAttr("position")) { String[] position = attributes.get("position").split(","); setPosition(Integer.parseInt(position[0]), Integer.parseInt(position[1])); } }
/** * Reads the given attribute from a set of attributes. * * @param attribute * the attribute key * @param attributes * the set of attributes to read from * @param outputType * the output type for the attribute * @return the attribute value or null */ public static <T> T readAttribute(String attribute, Attributes attributes, Class<T> outputType) { if (!getFormatter().canConvert(outputType)) { throw new IllegalArgumentException( "output type: " + outputType.getName() + " not supported"); } if (!attributes.hasKey(attribute)) { return null; } else { try { String value = attributes.get(attribute); return getFormatter().parse(value, outputType); } catch (Exception e) { throw new DesignException( "Failed to read attribute " + attribute, e); } } }
@Override public void readDesign(Element design, DesignContext designContext) { // process default attributes super.readDesign(design, designContext); setMargin(readMargin(design, getMargin(), designContext)); // handle children for (Element childComponent : design.children()) { Attributes attr = childComponent.attributes(); Component newChild = designContext.readDesign(childComponent); addComponent(newChild); // handle alignment setComponentAlignment(newChild, DesignAttributeHandler.readAlignment(attr)); // handle expand ratio if (attr.hasKey(":expand")) { String value = attr.get(":expand"); if (!value.isEmpty()) { try { float ratio = Float.valueOf(value); setExpandRatio(newChild, ratio); } catch (NumberFormatException nfe) { getLogger() .info("Failed to parse expand ratio " + value); } } else { setExpandRatio(newChild, 1.0f); } } } }
/** * Reads the size of this component from the given design attributes. If the * attributes do not contain relevant size information, defaults is * consulted. * * @param attributes * the design attributes */ private void readSize(Attributes attributes) { // read width if (attributes.hasKey("width-auto") || attributes.hasKey("size-auto")) { this.setWidth(null); } else if (attributes.hasKey("width-full") || attributes.hasKey("size-full")) { this.setWidth("100%"); } else if (attributes.hasKey("width")) { this.setWidth(attributes.get("width")); } // read height if (attributes.hasKey("height-auto") || attributes.hasKey("size-auto")) { this.setHeight(null); } else if (attributes.hasKey("height-full") || attributes.hasKey("size-full")) { this.setHeight("100%"); } else if (attributes.hasKey("height")) { this.setHeight(attributes.get("height")); } }
String localId = attributes.get(LOCAL_ID_ATTRIBUTE); boolean mappingExists = setComponentLocalId(component, localId); if (mappingExists) {
private String generateImageAlternativeText(Element element) { return Optional.ofNullable(element.attributes().get(ALT_TAG)) .map(StringUtils::normalizeSpace) .filter(s -> !s.isEmpty()) .map(s -> "[" + s + "]") .orElse(""); }
@Override public String getAttribute(final Node node, final String name) { return node.attributes().get(name).trim(); }
private NodeWrapper(Node wrapped) { this.wrapped = wrapped; Attributes attributes = wrapped.attributes(); if (nonNull(attributes)) { String value = attributes.get("class"); if (nonNull(value)) { value = whitespace.matcher(value).replaceAll(" "); String[] split = value.split(" "); Arrays.sort(split); classAttribute = join(split, " "); } value = attributes.get("style"); if (nonNull(value)) { value = whitespace.matcher(value).replaceAll(" "); String[] split = value.split(";"); Arrays.sort(split); styleAttribute = join(split, ";"); } } }
public void extrair(String html, String nomeArquivo) throws ErroCarregamentoAjuda { Document documento = Jsoup.parse(html); for (Element tag : documento.head().getElementsByTag("title")) { titulo = tag.text(); } for (Element tag : documento.head().getElementsByTag("link")) { String rel = tag.attributes().get("rel"); if (rel != null && rel.toLowerCase().equals("shortcut icon")) { icone = tag.attributes().get("href"); break; } } if (titulo == null) { throw new ErroCarregamentoAjuda(String.format("Erro ao carregar a ajuda: o arquivo '%s' não possui a tag 'title'", nomeArquivo)); } } }
private List<RaeResult> findResultsFromRedirect(Element element, String word) { List<RaeResult> results = new ArrayList<>(); Element redirect = element.getElementsByTag("a").first(); if (redirect != null) { String link = redirect.attributes().get("href"); results = fetchWord(link, word); } return results; }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attributes = design.attributes(); if (design.hasAttr("color")) { // Ignore the # character String hexColor = DesignAttributeHandler .readAttribute("color", attributes, String.class) .substring(1); setColor(new Color(Integer.parseInt(hexColor, 16))); } if (design.hasAttr("popup-style")) { setPopupStyle(PopupStyle.valueOf("POPUP_" + attributes.get("popup-style").toUpperCase(Locale.ROOT))); } if (design.hasAttr("position")) { String[] position = attributes.get("position").split(","); setPosition(Integer.parseInt(position[0]), Integer.parseInt(position[1])); } }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attr = design.attributes(); // handle immediate if (attr.hasKey("immediate")) { setImmediate(DesignAttributeHandler.getFormatter() .parse(attr.get("immediate"), Boolean.class)); } }