This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Prashanth Patha
Ranch Hand
Posts: 62
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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...


 
Paul Clapham
Sheriff
Pie
Posts: 20188
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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 Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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 ?"

 
E Armitage
Rancher
Posts: 989
9
  • 0
  • Mark post as helpful
  • send pies
  • 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 Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Pie
Posts: 20188
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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 Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
akshay pandey
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic