Skip to content
Snippets Groups Projects
Commit 0739a8d3 authored by srosse's avatar srosse
Browse files

OO-967: remove the mess between g_encoding and contentEncoding variables

parent 1afdf45b
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,6 @@ public class IFrameDeliveryMapper implements Mapper, Serializable {
private boolean enableTextmarking;
private boolean adjusteightAutomatically;
private String g_encoding;
private String jsEncoding;
private String contentEncoding;
......@@ -93,7 +92,6 @@ public class IFrameDeliveryMapper implements Mapper, Serializable {
}
public IFrameDeliveryMapper(VFSItem rootDir, boolean rawContent, boolean enableTextmarking, boolean adjusteightAutomatically,
String g_encoding, String jsEncoding, String contentEncoding,
String frameId, String customCssURL, String themeBaseUri, String customHeaderContent) {
this.rootDir = rootDir;
......@@ -102,10 +100,6 @@ public class IFrameDeliveryMapper implements Mapper, Serializable {
this.enableTextmarking = enableTextmarking;
this.adjusteightAutomatically = adjusteightAutomatically;
this.g_encoding = g_encoding;
this.jsEncoding = jsEncoding;
this.contentEncoding = contentEncoding;
this.frameId = frameId;
this.customCssURL = customCssURL;
this.themeBaseUri = themeBaseUri;
......@@ -121,7 +115,7 @@ public class IFrameDeliveryMapper implements Mapper, Serializable {
}
openolatCss = config.getOpenolatCss();
if(config.getContentEncoding() != null) {
g_encoding = config.getContentEncoding();
contentEncoding = config.getContentEncoding();
}
if(config.getJavascriptEncoding() != null) {
jsEncoding = config.getJavascriptEncoding();
......@@ -202,13 +196,16 @@ public class IFrameDeliveryMapper implements Mapper, Serializable {
if (path.toLowerCase().lastIndexOf(FILE_SUFFIX_HTM) >= (path.length()-4)) {
// set the http content-type and the encoding
Page page = loadPageWithGuess(vfsLeaf);
g_encoding = page.getEncoding();
String pageEncoding = page.getEncoding();
if (page.isUseLoadedPageString()) {
mr = prepareMediaResource(httpRequest, page.getPage(), g_encoding, page.getContentType(), isPopUp);
mr = prepareMediaResource(httpRequest, page.getPage(), pageEncoding, page.getContentType(), isPopUp);
} else {
// found a new charset other than iso-8859-1, load string with proper encoding
String content = FileUtils.load(vfsLeaf.getInputStream(), g_encoding);
mr = prepareMediaResource(httpRequest, content, g_encoding, page.getContentType(), isPopUp);
String content = FileUtils.load(vfsLeaf.getInputStream(), pageEncoding);
mr = prepareMediaResource(httpRequest, content, pageEncoding, page.getContentType(), isPopUp);
}
if(contentEncoding == null) {
contentEncoding = pageEncoding;
}
} else if (path.endsWith(FILE_SUFFIX_JS)) { // a javascript library
VFSMediaResource vmr = new VFSMediaResource(vfsLeaf);
......@@ -218,8 +215,11 @@ public class IFrameDeliveryMapper implements Mapper, Serializable {
// together with the mime-type, which is wrong.
// so we assume the .js file has the same encoding as the html file
// that loads the .js file
if (jsEncoding != null) vmr.setEncoding(jsEncoding);
else if (g_encoding != null) vmr.setEncoding(g_encoding);
if (jsEncoding != null) {
vmr.setEncoding(jsEncoding);
} else if (contentEncoding != null) {
vmr.setEncoding(contentEncoding);
}
mr = vmr;
} else {
// binary data: not .html, not .htm, not .js -> treated as is
......@@ -505,7 +505,7 @@ public class IFrameDeliveryMapper implements Mapper, Serializable {
return cType;
}
private String guessEncoding(String content) {
protected String guessEncoding(String content) {
Matcher m = PATTERN_ENCTYPE.matcher(content);
if (m.find()) {
// use found char set
......
......@@ -157,7 +157,6 @@ public class IFrameDisplayController extends BasicController implements GenericE
//TODO:gs may use the same contentMapper if users clicks again on the same singlePage, now each time a new Mapper gets created and
//therefore the browser can not reuse the cached elements
contentMapper = new IFrameDeliveryMapper(rootDir, false, enableTextmarking, adjusteightAutomatically,
null /*g_encoding*/, null /*jsEncoding*/, null /*contentEncoding*/,
frameId, null /*customCssURL*/, themeBaseUri, null /*customHeaderContent*/);
contentMapper.setDeliveryOptions(options);
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.gui.control.generic.iframe;
import junit.framework.Assert;
import org.junit.Test;
/**
*
* Initial date: 03.02.2014<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class IFrameDeliveryMapperTest {
@Test
public void testPatternRegex() {
IFrameDeliveryMapper mapper = new IFrameDeliveryMapper();
String encoding1 = mapper.guessEncoding("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
Assert.assertEquals("utf-8", encoding1);
String encoding2 = mapper.guessEncoding("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
Assert.assertEquals("UTF-8", encoding2);
}
}
......@@ -66,6 +66,7 @@ import org.junit.runners.Suite;
org.olat.core.id.context.HistoryManagerTest.class,
org.olat.core.id.IdentityEnvironmentTest.class,
org.olat.core.gui.render.VelocityTemplateTest.class,
org.olat.core.gui.control.generic.iframe.IFrameDeliveryMapperTest.class,
org.olat.note.NoteTest.class,//ok
org.olat.user.UserPropertiesPerformanceTest.class,//ok
org.olat.user.EmailCheckPerformanceTest.class,//fail
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment