Menu

Access several background values

icke79
2009-12-11
2012-07-18
  • icke79

    icke79 - 2009-12-11

    Hi there,

    I have used CSS Parser for searching all URL's within one CSS file and found a
    problem with following CSS construct:

    body {

    margin : 0;

    (...)

    background : #123456 url("/firstUrl.file") no-repeat;

    background : #123456 url("/secondUrl.file") no-repeat;

    background : #123456 url("/thirdUrl.file") no-repeat;

    }

    h1 {(...)}

    I tried to access all three url's within the 3 backgrounds with looping over
    all rules, contained styles and properties and their values:

    property = styleDeclaration.item(j);

    System.out.println(((CSSValueImpl)((CSSValueImpl)((CSSStyleRule)ruleList.item(
    i)).getStyle().getPropertyCSSValue(property)).item(k)).getValue());


    i is the counter for the CSSStyleRule's

    j is the counter for the CSSStyleDeclaration of the rule's

    k is the counter for CSSValueImpl's containing more then 1 item


    With this atempt I do always get the CSSValueImpl of the first background
    element. So in each loop over the 3 backgrounds the output on the screen is
    url("/firstUrl.file").


    I already thought that the j counter should be included anyhow within the
    whole construct? Any idea, how this could be realized?

    Regards

    icke

     
  • Jose Enrique

    Jose Enrique - 2011-10-19

    Hi

    I have the same problem.

    I download the source code and fix that issue in method getPropertyDeclaration
    at CSSStyleDeclarationImpl

    The code:

    public Property getPropertyDeclaration(final String name) {
    
            for(int i=properties_.size()-1; i>=0; i--) {
                 final Property p = properties_.get(i);
                 if (p.getName().equalsIgnoreCase(name)) {
                     return p;
                 }
            }
    
            return null;
        }
    
     
  • Alan Krueger

    Alan Krueger - 2011-10-25

    Could you attach a JUnit test or some other piece of compilable code that
    exhibits the behavior?

     

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.