Skip to content

Commit 3eaec64

Browse files
committed
Fixed source location of setEncoding method
1 parent ff9c695 commit 3eaec64

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

spring-context/src/main/java/org/springframework/scripting/support/ResourceScriptSource.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323

2424
import org.apache.commons.logging.Log;
2525
import org.apache.commons.logging.LogFactory;
26+
2627
import org.springframework.core.io.Resource;
2728
import org.springframework.scripting.ScriptSource;
2829
import org.springframework.util.Assert;
@@ -51,11 +52,12 @@ public class ResourceScriptSource implements ScriptSource {
5152

5253
private final Resource resource;
5354

55+
private String encoding = "UTF-8";
56+
5457
private long lastModified = -1;
5558

5659
private final Object lastModifiedMonitor = new Object();
5760

58-
private String encoding = "UTF-8";
5961

6062
/**
6163
* Create a new ResourceScriptSource for the given resource.
@@ -74,15 +76,23 @@ public final Resource getResource() {
7476
return this.resource;
7577
}
7678

79+
/**
80+
* Set the encoding used for reading the script resource.
81+
* <p>The default value for regular Resources is "UTF-8".
82+
* A {@code null} value implies the platform default.
83+
*/
84+
public void setEncoding(String encoding) {
85+
this.encoding = encoding;
86+
}
87+
88+
7789
public String getScriptAsString() throws IOException {
7890
synchronized (this.lastModifiedMonitor) {
7991
this.lastModified = retrieveLastModifiedTime();
8092
}
81-
8293
InputStream stream = this.resource.getInputStream();
83-
Reader reader = (StringUtils.hasText(encoding) ? new InputStreamReader(stream, encoding)
84-
: new InputStreamReader(stream));
85-
94+
Reader reader = (StringUtils.hasText(this.encoding) ? new InputStreamReader(stream, this.encoding) :
95+
new InputStreamReader(stream));
8696
return FileCopyUtils.copyToString(reader);
8797
}
8898

@@ -99,10 +109,11 @@ public boolean isModified() {
99109
protected long retrieveLastModifiedTime() {
100110
try {
101111
return getResource().lastModified();
102-
} catch (IOException ex) {
112+
}
113+
catch (IOException ex) {
103114
if (logger.isDebugEnabled()) {
104-
logger.debug(getResource() + " could not be resolved in the file system - "
105-
+ "current timestamp not available for script modification check", ex);
115+
logger.debug(getResource() + " could not be resolved in the file system - " +
116+
"current timestamp not available for script modification check", ex);
106117
}
107118
return 0;
108119
}
@@ -112,18 +123,9 @@ public String suggestedClassName() {
112123
return StringUtils.stripFilenameExtension(getResource().getFilename());
113124
}
114125

115-
/**
116-
* Sets the encoding used for reading the script resource. The default value is "UTF-8".
117-
* A null value, implies the platform default.
118-
*
119-
* @param encoding charset encoding used for reading the script.
120-
*/
121-
public void setEncoding(String encoding) {
122-
this.encoding = encoding;
123-
}
124-
125126
@Override
126127
public String toString() {
127128
return this.resource.toString();
128129
}
130+
129131
}

0 commit comments

Comments
 (0)