• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use CSS parser for writing or replacing property value ?

 
Ranch Hand
Posts: 62
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I would like to use CSSParser(http://cssparser.sourceforge.net/) for the manipulation of css file using Java.

I was able to read the css file using following piece of code.



In above code, i was able to read the properties and display . But, now i would like to replace 'color' property in following css class.

.loginproductname
{
color : #ffff;
}

I used the following , but it is not writing into the css file previously mentioned through input stream



What is the code for writing or committing the changes set ( replacing certain properties values in css file ) in this case ?

Note : If you know any other good css parser to read and write , please suggest me. Please try to clarify above doubt also.

Thank you...


 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say "didn't work", exactly what does that mean? I can see a few things which might be problems, but since I don't know what the actual problem is there is no point in guessing. Have a look at this page: ItDoesntWorkIsUseless (<== click that link) for more detail on how to explain your problem.
 
Prashanth Patha
Ranch Hand
Posts: 62
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi @Paul Clapham , i have edited my post . My actual question is : "how to commit the changes (set through setCssText(string) ) so that the new property value of color would be written into the css file ?"

 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An input stream won't update a file. To write to a file you need to use a FileWriter. Maybe your css api has methods to open a file for editing. If not then you need to create a new file and copy the contents from the first to the new one making any required amendments along the way.
 
Prashanth Patha
Ranch Hand
Posts: 62
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi @E Armitage

I have gone through api also, but didn't find the way to do it. I think there would be some way to do it without trying to write entire contents into new file.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you didn't find it in the API then it's most likely not there. You can confirm by asking in the project forums here: http://sourceforge.net/p/cssparser/discussion/283564/
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In practice if you want to update a text file, any text file at all, the way to do that is to make a new copy of the old file. If this product allows you to update the CSS at all, that is how it's going to work.
 
Prashanth Patha
Ranch Hand
Posts: 62
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all,

I am able to set the values for properties using the method "setCssText(string)" and i have written code to extract the the content from "styleSheet" object initialized previously and written that into new file. Its working properly now.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prashant,

It would be a great help if you can tell me how did you change the property of css using the CSS parser api. Do you have any sample code for it?
 
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic