Menu

STYLE attribute get / set properties

Help
2005-12-09
2013-04-27
  • david walters

    david walters - 2005-12-09

    Would the following be valid as a feature request - getting / setting the ";" delimited properties of the STYLE attribute of a tag? Or is there already a way to do this?

    e.g. (very rough and ready example)

    public String getStyleProperty(Tag tag, String propName) {
        String prop = "";
        String ret = "";
       
        String styleString = tag.getAttribute("STYLE");
       
        if (styleString != null) {
       
          StringTokenizer st = new StringTokenizer(styleString,":;");
          while (ret == "" && st.hasMoreTokens()) {
            prop = st.nextToken().trim();
           
            if (prop.toUpperCase().equals(propName.toUpperCase())) {
              if (st.hasMoreTokens()) {
                ret = st.nextToken(); 
              }
            }
            else {
              if (st.hasMoreTokens()) {
                st.nextToken(); 
              }
            }
          }
        }
        return ret;
      }
     
      public void setStyleProperty(Tag tag, String propName, String propValue) {
        String prop = "";
        String value = "";
       
        String newStyle = "";
        boolean set = false;
       
        String styleString = tag.getAttribute("STYLE");
       
        if (styleString != null) {
       
          StringTokenizer st = new StringTokenizer(styleString,":;");
          while (st.hasMoreTokens()) {
            prop = st.nextToken().trim();
          
            newStyle += prop + ":";
           
            value = "";
            if (prop.toUpperCase().equals(propName.toUpperCase())) {
              if (st.hasMoreTokens()) {
                value = propValue;
                set = true;
                st.nextToken();
              }
            }
            else {
              if (st.hasMoreTokens()) {
                value = st.nextToken(); 
              }
            }
           
            newStyle += value + ";";
          }
        }
       
        if (!set) {
          newStyle += propName + ":" + propValue + ";";
        }
      
        tag.setAttribute("STYLE", newStyle);
      }

     
    • Derrick Oswald

      Derrick Oswald - 2005-12-11

      Enter it as a Request For Enhancement on the StyleTag class...
      http://sourceforge.net/tracker/?atid=381402&group_id=24399&func=browse

      ...or do it yourself, it's easy to become a developer on the project.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.