This commit is contained in:
Suraj Khurana
2020-09-13 11:29:46 +05:30
8 changed files with 97 additions and 13 deletions
@@ -18,6 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.base.util;
import org.apache.ofbiz.widget.model.ThemeFactory;
import org.jsoup.parser.ParseError;
import org.jsoup.parser.Parser;
@@ -28,9 +29,12 @@ import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Stack;
@@ -39,6 +43,7 @@ public final class UtilHtml {
private static final String MODULE = UtilHtml.class.getName();
private static final Parser JSOUP_HTML_PARSER = createJSoupHtmlParser();
private static final String[] TAG_SHOULD_CLOSE_LIST = new String[]{"div"};
private static List<String> visualThemeBasePathsName;
private UtilHtml() { }
private static Parser createJSoupHtmlParser() {
@@ -110,7 +115,33 @@ public final class UtilHtml {
return errorList;
}
public static void logFormattedError(String content, String location, String error, String module) {
Debug.logError("[Parsing " + location + "] " + error, module);
public static List<String> getVisualThemeFolderNamesToExempt() {
if (visualThemeBasePathsName == null) {
try {
List<File> xmlThemes = ThemeFactory.getThemeXmlFiles();
visualThemeBasePathsName = new ArrayList<>();
String themePathKey = File.separator + "themes" + File.separator;
String pluginPathKey = File.separator + "plugins" + File.separator;
for (File xmlTheme : xmlThemes) {
String path = xmlTheme.toURI().toURL().toString();
if (path.indexOf(themePathKey) > 0) {
path = path.substring(path.indexOf(themePathKey) + 8);
} else if (path.indexOf(pluginPathKey) > 0) {
path = path.substring(path.indexOf(pluginPathKey) + 9);
}
path = path.substring(0, path.indexOf(File.separator));
if (!path.contains("common-theme") && !path.contains("ecommerce")) {
visualThemeBasePathsName.add(File.separator + path + File.separator);
}
}
} catch (IOException e) {
Debug.logError(e, MODULE);
}
}
return Collections.unmodifiableList(visualThemeBasePathsName);
}
public static void logHtmlWarning(String content, String location, String error, String module) {
Debug.logWarning("[Parsing " + location + "] " + error, module);
}
}