aspose file tools*
The moose likes Other Open Source Projects and the fly likes How to use CSS parser for writing or replacing property value ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How to use CSS parser for writing or replacing property value ?" Watch "How to use CSS parser for writing or replacing property value ?" New topic
Author

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

Prashanth Patha
Ranch Hand

Joined: May 06, 2011
Posts: 62

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...



Thanks & Regards
Prashanth

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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

Joined: May 06, 2011
Posts: 62

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

Joined: Mar 17, 2012
Posts: 892
    
    9
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

Joined: May 06, 2011
Posts: 62

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

Joined: Mar 17, 2012
Posts: 892
    
    9
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
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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

Joined: May 06, 2011
Posts: 62

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

Joined: Aug 04, 2014
Posts: 1
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
 
subject: How to use CSS parser for writing or replacing property value ?