Skip to content

Commit 80e5513

Browse files
committed
Revert "Remove unintended changes from last commit"
This reverts commit 1ba806b.
1 parent 2670d94 commit 80e5513

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ configure(allprojects) { project ->
2222
apply plugin: "java"
2323
apply plugin: "test-source-set-dependencies"
2424
apply from: "${gradleScriptDir}/ide.gradle"
25+
apply plugin: "maven"
2526

2627
[compileJava, compileTestJava]*.options*.compilerArgs = [
2728
"-Xlint:serial",
@@ -631,6 +632,7 @@ project("spring-webmvc") {
631632
optional("org.freemarker:freemarker:2.3.19")
632633
optional("org.codehaus.jackson:jackson-mapper-asl:1.9.12")
633634
optional("com.fasterxml.jackson.core:jackson-databind:2.2.0")
635+
optional("org.lesscss:lesscss:1.3.3")
634636
provided("javax.servlet:jstl:1.2")
635637
provided("javax.servlet:javax.servlet-api:3.0.1")
636638
provided("javax.servlet.jsp:jsp-api:2.1")
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.servlet.resource;
18+
19+
import java.io.IOException;
20+
21+
import javax.servlet.http.HttpServletRequest;
22+
23+
import org.lesscss.LessCompiler;
24+
import org.lesscss.LessException;
25+
import org.springframework.core.io.Resource;
26+
import org.springframework.util.StringUtils;
27+
28+
29+
/**
30+
*
31+
* @author Jeremy Grelle
32+
* @since 4.0
33+
*/
34+
public class LessResourceTransformer implements ResourceTransformer {
35+
36+
private static final String LESS_EXT = "less";
37+
38+
private final LessCompiler compiler = new LessCompiler();
39+
40+
41+
@Override
42+
public Resource transform(Resource original) throws IOException {
43+
TransformedResource transformed;
44+
try {
45+
String content = "";
46+
if (original instanceof TransformedResource) {
47+
content = ((TransformedResource) original).getContentAsString();
48+
}
49+
else {
50+
content = this.compiler.compile(original.getFile());
51+
}
52+
transformed = new TransformedResource(original.getFilename().replace(
53+
"." + LESS_EXT, ""), content.getBytes("UTF-8"), original.lastModified());
54+
}
55+
catch (LessException ex) {
56+
//TODO - Nicely print out the compilation error
57+
ex.printStackTrace();
58+
return null;
59+
}
60+
return transformed;
61+
}
62+
63+
@Override
64+
public boolean willTransform(HttpServletRequest request, Resource original) {
65+
return LESS_EXT.equals(StringUtils.getFilenameExtension(original.getFilename()));
66+
}
67+
68+
}

spring-webmvc/src/test/resources/log4j.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
<level value="debug" />
2020
</logger>
2121

22+
<logger name="org.springframework.web.servlet.resource">
23+
<level value="trace" />
24+
</logger>
25+
2226
<!-- Root Logger -->
2327
<root>
2428
<priority value="warn" />

0 commit comments

Comments
 (0)