Author: alevkovsky
Date: 2008-11-06 07:43:15 -0500 (Thu, 06 Nov 2008)
New Revision: 11043
Modified:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/resources/EditorHTMLRenderer.java
Log:
Editor html resource renderer implementation
Modified:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/resources/EditorHTMLRenderer.java
===================================================================
---
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/resources/EditorHTMLRenderer.java 2008-11-06
11:53:32 UTC (rev 11042)
+++
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/resources/EditorHTMLRenderer.java 2008-11-06
12:43:15 UTC (rev 11043)
@@ -27,6 +27,8 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.faces.context.FacesContext;
@@ -46,6 +48,8 @@
private final static String SPECIFIC_SCRIPT_RESOURCE_NAME =
"org/richfaces/renderkit/html/1$1.js";
private final static String SPECIFIC_XCSS_RESOURCE_NAME =
"org/richfaces/renderkit/html/1$1.xcss";
+ private final static String REGEXP =
"\\<(script|link|img)\\s+.*(?:src|href)\\s*=\\s*[\"']([^'\"]+)\\.([^\\'\"]+)[\"'][^>]*\\>";
+
/**
* @see org.ajax4jsf.resource.BaseResourceRenderer#getCommonAttrs()
*/
@@ -105,37 +109,43 @@
*/
private int updateAndSendResource(InputStream in, OutputStream out) throws IOException
{
- //TODO Pasha, replace with regular expression if needed?
-
int total = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
String scriptSuffix = getSriptMappingSuffix();
String cssSuffix = getCssMappingSuffix();
+
+ Pattern pattern = Pattern.compile(REGEXP, Pattern.CASE_INSENSITIVE);
+
try {
while (br.ready()) {
String line = br.readLine();
- if(scriptSuffix != null && line.indexOf("script") != -1 &&
line.indexOf("src=") != -1){
- if (line.indexOf(".js") != -1) {
- line = line.replace(".js", ".js" + scriptSuffix);
+
+
+ Matcher matcher = pattern.matcher(line);
+ if (matcher.find()){
+ String tagName = matcher.group(1);
+
+ if(scriptSuffix != null &&
tagName.toLowerCase().equals("script")){
+ String path = matcher.group(2);
+ String extension = matcher.group(3);
+ line = line.replace(path + "." + extension, path + "." +
extension + scriptSuffix);
}
- }
- if(scriptSuffix != null && line.indexOf("img") != -1 &&
line.indexOf("src=") != -1 && line.indexOf("src=\"http:")
== -1){
- if (line.indexOf(".gif") != -1) {
- line = line.replace(".gif", ".gif" + scriptSuffix);
+
+ if(scriptSuffix != null && tagName.toLowerCase().equals("img")){
+ String path = matcher.group(2);
+ String extension = matcher.group(3);
+ if(path.indexOf("http://") == -1){
+ line = line.replace(path + "." + extension, path + "." +
extension + scriptSuffix);
+ }
}
- if (line.indexOf(".png") != -1) {
- line = line.replace(".png", ".png" + scriptSuffix);
+
+ if(cssSuffix != null && tagName.toLowerCase().equals("link")){
+ String path = matcher.group(2);
+ String extension = matcher.group(3);
+ line = line.replace(path + "." + extension, path + "." +
"xcss" + cssSuffix);
}
- if (line.indexOf(".jpg") != -1) {
- line = line.replace(".jpg", ".jpg" + scriptSuffix);
- }
}
- if(cssSuffix != null && line.indexOf("link") != -1 &&
line.indexOf("href=") != -1){
- if (line.indexOf(".css") != -1) {
- line = line.replace(".css", ".xcss" + cssSuffix);
- }
- }
bw.write(line);
bw.newLine();
total += line.getBytes().length;
Show replies by date