Author: dmaliarevich
Date: 2011-12-20 07:44:37 -0500 (Tue, 20 Dec 2011)
New Revision: 37460
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-5861 - CSS comments were removed.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2011-12-20
11:57:57 UTC (rev 37459)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2011-12-20
12:44:37 UTC (rev 37460)
@@ -320,7 +320,7 @@
}
return false;
}
-
+
/**
* Creates new visual node representing {@code sourceNode} and its descendants.
*
@@ -1148,18 +1148,21 @@
String styleForParse = styleText.toString();
/*
*
https://issues.jboss.org/browse/JBIDE-5861
- * Add nested @import constructions
+ * Remove CSS comments first:
*/
+ styleForParse = VpeStyleUtil.removeAllCssComments(styleForParse);
List<String> imports = VpeStyleUtil.findCssImportConstruction(styleForParse,
pageContext);
if (imports.size() > 0) {
for (String key : imports) {
+ /*
+ * Add nested @import constructions
+ */
addLinkNodeToHead(key, "css_nested_import_construction", false);
//$NON-NLS-1$
}
/*
* Replace @import constructions
*/
- Matcher m = VpeStyleUtil.CSS_IMPORT_PATTERN.matcher(styleForParse);
- styleForParse = m.replaceAll(Constants.EMPTY);
+ styleForParse = VpeStyleUtil.removeAllCssImportConstructions(styleForParse);
}
styleForParse = VpeStyleUtil.addFullPathIntoURLValue(styleForParse, href_val);
inlineStyle.appendChild(getVisualDocument().createTextNode(styleForParse));
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java 2011-12-20
11:57:57 UTC (rev 37459)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java 2011-12-20
12:44:37 UTC (rev 37460)
@@ -41,19 +41,22 @@
text = textNode.getNodeValue();
/*
*
https://issues.jboss.org/browse/JBIDE-5861
- * Add inline <style> element for each found css @import
+ * Remove CSS comments first:
*/
+ text = VpeStyleUtil.removeAllCssComments(text);
+ List<String> imports = VpeStyleUtil.findCssImportConstruction(text,
pageContext);
VpeVisualDomBuilder vvdb = pageContext.getVisualBuilder();
- List<String> imports = VpeStyleUtil.findCssImportConstruction(text,
pageContext);
if (imports.size() > 0) {
for (String key : imports) {
+ /*
+ * Add inline <style> element for each found css @import.
+ */
vvdb.addLinkNodeToHead(key, "css_import_construction", false);
//$NON-NLS-1$
}
/*
- * Replace @import constructions
+ * Replace @import constructions that've been added.
*/
- Matcher m = VpeStyleUtil.CSS_IMPORT_PATTERN.matcher(text);
- text = m.replaceAll(Constants.EMPTY);
+ text = VpeStyleUtil.removeAllCssImportConstructions(text);
}
text = VpeStyleUtil.addFullPathIntoURLValue(text, pageContext);
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2011-12-20
11:57:57 UTC (rev 37459)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2011-12-20
12:44:37 UTC (rev 37460)
@@ -82,9 +82,14 @@
* For the long string regexp could be updated:
* (.*) should be replaced with ([^;]*)
*/
+ public static final String LINE_SEPARATOR =
System.getProperty("line.separator"); //$NON-NLS-1$
public static final Pattern CSS_URL_PATTERN =
Pattern.compile("(?<=\\burl\\b)(?:[\\p{Space}]*\\()[\\p{Space}]*([^;]*)[\\p{Space}]*(?:\\)[\\p{Space}]*)(?=(?>[^\\)]*;|[^\\)]*))");
//$NON-NLS-1$
public static final Pattern CSS_IMPORT_PATTERN =
Pattern.compile("@import[\\p{Space}]+(?:\\burl\\b[\\p{Space}]*\\()*[\\p{Space}]*([^;]*)[\\p{Space}]*(?:\\)[\\p{Space}]*(?=(?>[^\\)]*;|[^\\)]*)))*");
//$NON-NLS-1$
public static final Pattern CSS_URI_PATTERN =
Pattern.compile("(?:\\\"{1}(.*)\\\"{1})|(?:\\'{1}(.*)\\'{1})");
//$NON-NLS-1$
+ /*
+ * Pattern "|(//.*)" could be added at the end to remove single line
comments.
+ */
+ public static final Pattern CSS_COMMENT_PATTERN =
Pattern.compile("(/\\*([^*]|["+LINE_SEPARATOR+"]|(\\*+([^*/]|["+LINE_SEPARATOR+"])))*\\*+/)");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
public static String ATTR_URL = "url"; //$NON-NLS-1$
public static String OPEN_BRACKET = "("; //$NON-NLS-1$
@@ -934,4 +939,12 @@
}
return uri;
}
-}
+
+ public static String removeAllCssImportConstructions(String cssText) {
+ return CSS_IMPORT_PATTERN.matcher(cssText).replaceAll(Constants.EMPTY);
+ }
+
+ public static String removeAllCssComments(String cssText) {
+ return CSS_COMMENT_PATTERN.matcher(cssText).replaceAll(Constants.EMPTY);
+ }
+}
\ No newline at end of file