Rohit Bajaj
asked on
Help refactoring a java code
HI,
I came across a code like :
I am basically using this code in my spring web application. to clean html before saving it into the Database.
I am using Jsoup and using the above class like : HTMLSanitizer.sanitizeHTML (text)
I need advice from experts on the way this class is designed. Do you see any problems here. This is the only class where i have used static blocks...
Other approach will be to make a constructor of this class and annotate this class with @Component and then autowire it where i have to use it...
Please suggest what are the advantages or disadvantages of this approach ?
Thanks
I came across a code like :
public class HTMLSanitizer {
private static Whitelist whitelist;
private static Document.OutputSettings settings;
static {
whitelist = Whitelist.basicWithImages();
whitelist.addTags("div", "s", "span");
whitelist.addAttributes(":all", "style");
settings = new Document.OutputSettings();
settings.prettyPrint(false);
}
public static String sanitizeHTML(String unsafeHTML) {
return Jsoup.clean(unsafeHTML, "", whitelist, settings);
}
}
I am basically using this code in my spring web application. to clean html before saving it into the Database.
I am using Jsoup and using the above class like : HTMLSanitizer.sanitizeHTML
I need advice from experts on the way this class is designed. Do you see any problems here. This is the only class where i have used static blocks...
Other approach will be to make a constructor of this class and annotate this class with @Component and then autowire it where i have to use it...
Please suggest what are the advantages or disadvantages of this approach ?
Thanks
I don't think we can help with actual code - you've got to do that bit yourself. Experts can only make suggestions. Sadly, I don't have one for your particular case. And if it's not your own code anyway, then there's no chance, since it could be an infringement of copyright or patent.
ASKER
there is no copy right infringment.. its something me and my friend both working on.. and this is a modified code... not the actual one...just to give idea about the approach..
ASKER
there is no copy right infringment.. its something me and my friend both working on.. and this is a modified code... not the actual one...just to give idea about the approach..
So then only the first condition applies.
By the way it's not " a code" (that is a term concerned with secrecy or cryptography) it's just "code".
ASKER
HI,
I am not looking for coding help here.
I am looking for alternative approach and comparison between two approaches which i mentioned above..
I am not looking for coding help here.
I am looking for alternative approach and comparison between two approaches which i mentioned above..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.