Hi @eakbas and @Favonius Thanks for your reply.
I finally got a solution, maybe this is not the best, but at least it works for me.
As I said, I used the flute library to implement the DocumentHandler class of the org.w3c.sac package of the package to parse the css file.
Therefore, I applied the 'property' method, this method has 3 parameters, the name of the property, the LexicalUnit object and a boolean value indicating that the property has an important operator or not.
public void property(String property, LexicalUnit lexicalUnit, boolean important)
Since I need the line number where the particular property was found, I did a search, and I realized that the class that uses the flute to implement the LexicalUnit interface contains the line number (this is LexicalUnitImp), so I used reflection to cast from the LexicalUnit interface to one object LexicalUnitImp.
Class<?> clazz = ClassUtils.getClass("org.w3c.flute.parser.LexicalUnitImpl"); Object lexicalObject = clazz.cast(lexicalUnit); Integer line = (Integer)MethodUtils.invokeMethod(lexicalObject, "getLineNumber", null, null);
I did it this way because the LexicalUnitImpl class is “protected” and I cannot use it in the traditional way.
class LexicalUnitImpl implements LexicalUnit
Note. The ClassUtils class and MethodUtils are part of the apache commons-beanutils library.
Carlos Vega G
source share