private static boolean hasTargetStyle(AttributeSet attributes) { final List<?> attributeNames = Collections.list(attributes.getAttributeNames()); for(Object name: attributeNames){ if(name.equals(MY_STYLE_NAME)){ return true; } } return false; }
@Nullable private static Object getAttribute(AttributeSet attributes, String name) { for (Enumeration<?> enumeration = attributes.getAttributeNames(); enumeration.hasMoreElements();) { Object nameKey = enumeration.nextElement(); if (name.equals(nameKey.toString())) { return attributes.getAttribute(nameKey); } } return null; } }
private static AttributeSet adjustAttributes(AttributeSet as) { Collection<Object> attrs = new LinkedList<Object>(); for (Enumeration<?> e = as.getAttributeNames(); e.hasMoreElements(); ) { Object key = e.nextElement(); Object value = as.getAttribute(key); if (value != Boolean.FALSE) { attrs.add(key); attrs.add(value); } } return AttributesUtilities.createImmutable(attrs.toArray()); }
private HTML.Tag findTag( final AttributeSet attr ) { final Enumeration names = attr.getAttributeNames(); while ( names.hasMoreElements() ) { final Object name = names.nextElement(); final Object o = attr.getAttribute( name ); if ( o instanceof HTML.Tag ) { if ( HTML.Tag.CONTENT == o ) { continue; } if ( HTML.Tag.COMMENT == o ) { continue; } return (HTML.Tag) o; } } return null; }
private void extractHREF(AttributeSet attributes) { Enumeration e = attributes.getAttributeNames(); while (e.hasMoreElements()) { Object name = e.nextElement(); String value = (String) attributes.getAttribute(name); //System.out.println(" name= <"+name+ ">"+" value= <"+value+ ">"); try { if (name == HTML.Attribute.HREF) { URL u = baseURL.toURI().resolve(value).toURL(); String urlName = u.toString(); if (urlList != null) urlList.add(u.toString()); if (debug) System.out.println(" extracted URL= <" + urlName + ">"); } } catch (MalformedURLException ex) { System.err.println(ex); System.err.println(baseURL); System.err.println(value); ex.printStackTrace(); } catch (URISyntaxException ex) { System.err.println(ex); System.err.println(baseURL); System.err.println(value); ex.printStackTrace(); } } // while } // extractHREF
private void extractHREF(AttributeSet attributes) { Enumeration e = attributes.getAttributeNames(); while (e.hasMoreElements()) { Object name = e.nextElement(); String value = (String) attributes.getAttribute(name); //System.out.println(" name= <"+name+ ">"+" value= <"+value+ ">"); try { if (name == HTML.Attribute.HREF) { URL u = baseURL.toURI().resolve(value).toURL(); String urlName = u.toString(); if (urlList != null) urlList.add(u.toString()); if (debug) System.out.println(" extracted URL= <" + urlName + ">"); } } catch (MalformedURLException ex) { System.err.println(ex); System.err.println(baseURL); System.err.println(value); ex.printStackTrace(); } catch (URISyntaxException ex) { System.err.println(ex); System.err.println(baseURL); System.err.println(value); ex.printStackTrace(); } } // while } // extractHREF
protected static String describeElement(DocumentElement el) { StringBuilder sb = new StringBuilder(); AttributeSet attrs = el.getAttributes(); for (Enumeration names = attrs.getAttributeNames(); names.hasMoreElements();) { String attrName = (String) names.nextElement(); sb.append(" "); //NOI18N sb.append(attrName); sb.append("=\""); //NOI18N Object o = attrs.getAttribute(attrName); if ( o != null) { String value = o.toString(); if (value.length() > MAX_TOOLTIP_ATTR_SIZE) { sb.append(value.substring(0, MAX_TOOLTIP_ATTR_SIZE)); sb.append("..."); //NOI18N } else { sb.append(value); } } sb.append('"'); sb.append(" <br>"); //NOI18N } return sb.toString(); }
private void extractHREF(AttributeSet attributes) { Enumeration e = attributes.getAttributeNames(); while (e.hasMoreElements()) { Object name = e.nextElement(); String value = (String) attributes.getAttribute(name); //System.out.println(" name= <"+name+ ">"+" value= <"+value+ ">"); try { if (name == HTML.Attribute.HREF) { URL u = baseURL.toURI().resolve(value).toURL(); String urlName = u.toString(); if (urlList != null) urlList.add(u.toString()); if (debug) System.out.println(" extracted URL= <" + urlName + ">"); } } catch (MalformedURLException ex) { System.err.println(ex); System.err.println(baseURL); System.err.println(value); ex.printStackTrace(); } catch (URISyntaxException ex) { System.err.println(ex); System.err.println(baseURL); System.err.println(value); ex.printStackTrace(); } } // while } // extractHREF
Enumeration<?> keys = attribs.getAttributeNames(); while (keys.hasMoreElements()) { Object key = keys.nextElement();
public String getAttribsText() { StringBuffer attribsText = new StringBuffer(); Enumeration attrNames = getDocumentElement().getAttributes().getAttributeNames(); if(attrNames.hasMoreElements()) { while(attrNames.hasMoreElements()) { String aname = (String)attrNames.nextElement(); String value = (String)getDocumentElement().getAttributes().getAttribute(aname); attribsText.append(aname); attribsText.append("=\""); //NOI18N attribsText.append(value); attribsText.append("\""); //NOI18N if(attrNames.hasMoreElements()) attribsText.append(", "); //NOI18N } } return attribsText.toString(); }
private static void visitAttributeRec(Element elem, AttributeSet atts, IDocumentVisitor v) { for (Enumeration<?> en = atts.getAttributeNames(); en.hasMoreElements();) { Object nm = en.nextElement(); Object value = atts.getAttribute(nm); if (value instanceof AttributeSet) { visitAttributeRec(elem, (AttributeSet) value, v); } else { v.visitAttribute(elem, atts, nm, value); } } }
int offset, length; //The value of the first 2 parameters in the setParagraphAttributes() call Element section = doc.getDefaultRootElement(); int index0 = section.getElementIndex(offset); int index1 = section.getElementIndex(offset + ((length > 0) ? length - 1 : 0)); for (int i = index0; i <= index1; i++) { Element paragraph = section.getElement(i); AttributeSet attributeSet = paragraph.getAttributes(); Enumeration keys = attributeSet.getAttributeNames(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object attribute = attributeSet.getAttribute(key); //System.out.println("key = " + key); //For other AttributeSet classes this line is useful because it shows the actual parameter, like "Bold" System.out.println(attribute.getClass()); System.out.println(attribute); } }
protected void writeEmbeddedTags(AttributeSet attr) throws IOException { // translate css attributes to html attr = convertToHTML(attr, oConvAttr); Enumeration names = attr.getAttributeNames(); while (names.hasMoreElements()) { Object name = names.nextElement(); if (name instanceof HTML.Tag) { HTML.Tag tag = (HTML.Tag)name; if (tag == HTML.Tag.FORM || tags.contains(tag)) { continue; } write('<'); write(tag.toString());//Here Object o = attr.getAttribute(tag); if (o != null && o instanceof AttributeSet) { writeAttributes((AttributeSet)o); } write('>'); tags.addElement(tag); tagValues.addElement(o); } } }
private void registerHTMLButton(HTMLDocument htm, String elementID, ActionListener action) { Element e = htm.getElement(elementID); if (e != null) { AttributeSet attr = e.getAttributes(); Enumeration enu = attr.getAttributeNames(); while (enu.hasMoreElements()) { Object name = enu.nextElement(); Object value = attr.getAttribute(name); if ("model".equals(name.toString())) { //NOI18N final DefaultButtonModel model = (DefaultButtonModel) value; model.setActionCommand(elementID); model.addActionListener(action); } } } }
private void registerHTMLButton(HTMLDocument htm, String elementID, ActionListener action) { Element e = htm.getElement(elementID); if (e != null) { AttributeSet attr = e.getAttributes(); Enumeration enu = attr.getAttributeNames(); while (enu.hasMoreElements()) { Object name = enu.nextElement(); Object value = attr.getAttribute(name); if ("model".equals(name.toString())) { //NOI18N final DefaultButtonModel model = (DefaultButtonModel) value; model.setActionCommand(elementID); model.addActionListener(action); } } } }
result.append("<b>").append(attrs.toString()).append("</b>"); result.append("<br />"); Enumeration en = attrs.getAttributeNames(); while (en.hasMoreElements()) { Object key = en.nextElement();
/** * Create an older style of HTML attributes. This will convert character * level attributes that have a StyleConstants mapping over to an HTML * tag/attribute. Other CSS attributes will be placed in an HTML style * attribute. */ private static void convertToHTML(final AttributeSet from, final MutableAttributeSet to) { if (from == null) { return; } final Enumeration<?> keys = from.getAttributeNames(); String value = ""; while (keys.hasMoreElements()) { final Object key = keys.nextElement(); if (key instanceof CSS.Attribute) { if (value.length() > 0) { value = value + "; "; } value = value + key + ": " + from.getAttribute(key); } else { to.addAttribute(key, from.getAttribute(key)); } } if (value.length() > 0) { to.addAttribute(HTML.Attribute.STYLE, value); } }
public javax.swing.text.View create(javax.swing.text.Element elem) { AttributeSet as = elem.getAttributes(); HTML.Tag tag = (HTML.Tag) (as .getAttribute(StyleConstants.NameAttribute)); if (tag == HTML.Tag.INPUT) { String type = ""; String name = ""; Enumeration e = as.getAttributeNames(); while (e.hasMoreElements()) { Object key = e.nextElement(); if (key == HTML.Attribute.TYPE) { type = as.getAttribute(key).toString(); } if (key == HTML.Attribute.NAME) { name = as.getAttribute(key).toString(); } } if (type.equalsIgnoreCase("submit")) { return new CustomFormView(elem); } if (type.equalsIgnoreCase("file")) { fileFields.add(name); } } return super.create(elem); } }
@Override protected void writeEmbeddedTags(AttributeSet attr) throws IOException { /* translate css attributes to html */ attr = convertToHTML(attr, oConvAttr); Enumeration names = attr.getAttributeNames(); while (names.hasMoreElements()) { Object name = names.nextElement(); if (name instanceof HTML.Tag) { HTML.Tag tag = (HTML.Tag) name; if (tag == HTML.Tag.FORM || tags.contains(tag)) continue; write('<'); write(tag.toString()); Object o = attr.getAttribute(tag); if (o != null && o instanceof AttributeSet) writeAttributes((AttributeSet) o); write('>'); tags.add(tag); tagValues.add(o); } } }
/** * Searches the specified element for CLASS attribute setting */ private String findStyle(Element element) { AttributeSet as = element.getAttributes(); if (as == null) { return null; } Object val = as.getAttribute(HTML.Attribute.CLASS); if (val != null && (val instanceof String)) { return (String) val; } for (Enumeration e = as.getAttributeNames(); e.hasMoreElements();) { Object key = e.nextElement(); if (key instanceof HTML.Tag && as.getAttribute(key) instanceof AttributeSet) { AttributeSet eas = (AttributeSet) (as.getAttribute(key)); if (eas != null) { val = eas.getAttribute(HTML.Attribute.CLASS); if (val != null) { return (String) val; } } } } return null; }