Skip to content
Snippets Groups Projects
Commit cda84104 authored by Christian Wulf's avatar Christian Wulf
Browse files

fixed BOM bug

parent 18da53d6
No related branches found
No related tags found
No related merge requests found
Showing
with 1133 additions and 25 deletions
/*
TEMPLATE
PRODUCTLINE fm
VARIABLE rootContext
"FMcockpit"
PRODUCTLINE bm
VARIABLE rootContext
"Benchmark-Cockpit"
PRODUCTLINE default
VARIABLE rootContext
"defaultCockpit"
TEMPLATE END
*/
/*
Copyright (c) 2009 Mikael Söderström.
Contact: vimpyboy@msn.com
Feel free to use this script as long as you don't remove this comment.
*/
(function($) {
var rootContext = /* rootContext */
var isLoaded;
var isClosed;
$.fn.Ribbon = function(ribbonSettings) {
var settings = $.extend({
theme : 'windows7'
}, ribbonSettings || {});
if (!isLoaded) {
SetupMenu(settings);
}
function SetupMenu(settings) {
$('.menu li a:first').addClass('active');
$('.menu li ul').hide();
$('.menu li a:first').parent().children('ul:first').show();
$('.menu li a:first').parent().children('ul:first').addClass(
'submenu');
$('.menu li > a').click(function() {
ShowSubMenu(this);
});
$('.orb').click(function() {
ShowMenu();
});
$('.orb ul').hide();
$('.orb ul ul').hide();
$('.orb li ul li ul').show();
$('.orb li li ul')
.each(
function() {
$(this)
.prepend(
'<div style="background-color: #EBF2F7; height: 25px; line-height: 25px; width: 292px; padding-left: 9px; border-bottom: 1px solid #CFDBEB;">'
+ $(this)
.parent()
.children(
'a:first')
.text()
+ '</div>');
});
$('.orb li li a').each(function() {
if ($(this).parent().children('ul').length > 0) {
$(this).addClass('arrow')
}
});
// $('.ribbon-list div').each(function() {
// $(this).parent().width($(this).parent().width()); });
$('.ribbon-list div').click(
function(e) {
var elwidth = $(this).parent().width();
var insideX = e.pageX > $(this).offset().left
&& e.pageX < $(this).offset().left
+ $(this).width();
var insideY = e.pageY > $(this).offset().top
&& e.pageY < $(this).offset().top
+ $(this).height();
$('.ribbon-list div ul').fadeOut('fast');
if (insideX && insideY) {
$(this).attr(
'style',
'background-image: '
+ $(this).css('background-image'));
$(this).parent().width(elwidth);
$(this).children('ul').width(elwidth - 4);
$(this).children('ul').fadeIn('fast');
}
});
$('.ribbon-list div')
.parents()
.click(
function(e) {
if ($('.ribbon-list div ul:visible').parent()
.offset()) {
var outsideX = e.pageX < $(
'.ribbon-list div ul:visible')
.parent().offset().left
|| e.pageX > $(
'.ribbon-list div ul:visible')
.parent().offset().left
+ $(
'.ribbon-list div ul:visible')
.parent().width();
var outsideY = e.pageY < $(
'.ribbon-list div ul:visible')
.parent().offset().top
|| e.pageY > $(
'.ribbon-list div ul:visible')
.parent().offset().top
+ $(
'.ribbon-list div ul:visible')
.parent().height();
if (outsideX || outsideY) {
$('.ribbon-list div ul:visible').each(
function() {
$(this).fadeOut('fast');
});
$('.ribbon-list div').css(
'background-image', '');
}
}
});
$('.orb li li a').mouseover(function() {
ShowOrbChildren(this);
});
}
$('.ribbon').parents().click(
function(e) {
var outsideX = e.pageX < $('.orb ul:first').offset().left
|| e.pageX > $('.orb ul:first').offset().left
+ $('.orb ul:first').width();
var outsideY = e.pageY < $('.orb ul:first img:first')
.offset().top
|| e.pageY > $('.orb ul:first').offset().top
+ $('.orb ul:first').height();
if (outsideX || outsideY)
$('.orb ul').fadeOut('fast');
});
if (isLoaded) {
$('.orb li:first ul:first img:first').remove();
$('.orb li:first ul:first img:last').remove();
$('.ribbon-list div img[src*="/'+rootContext+'/images/ribbon/arrow_down.png"]').remove();
}
$('.orb li:first ul:first')
.prepend(
'<img src="/'+rootContext+'/images/ribbon/menu_top.png" style="margin-left: -10px; margin-top: -22px;" />');
$('.orb li:first ul:first')
.append(
'<img src="/'+rootContext+'/images/ribbon/menu_bottom.png" style="margin-left: -10px; margin-bottom: -22px;" />');
$('.ribbon-list div')
.each(
function() {
if ($(this).children('ul').length > 0) {
$(this).append('<img src="/'+rootContext+'/images/ribbon/arrow_down.png" style="float: right; margin-top: 5px;" />')
}
});
// Hack for IE 7.
if (navigator.appVersion.indexOf('MSIE 6.0') > -1
|| navigator.appVersion.indexOf('MSIE 7.0') > -1) {
$('ul.menu li li div').css('width', '90px');
$('ul.menu').css('width', '500px');
$('ul.menu').css('float', 'left');
$('ul.menu .submenu li div.ribbon-list').css('width', '100px');
$('ul.menu .submenu li div.ribbon-list div').css('width', '100px');
}
$('a[href=' + window.location.hash + ']').click();
isLoaded = true;
function ResetSubMenu() {
$('.menu li a').removeClass('active');
$('.menu ul').removeClass('submenu');
$('.menu li ul').hide();
}
function ShowSubMenu(e) {
var isActive = $(e).next().css('display') == 'block';
ResetSubMenu();
$(e).addClass('active');
$(e).parent().children('ul:first').addClass('submenu');
$(e).parent().children('ul:first').show();
$('body').css('padding-top', '120px');
isClosed = false;
}
function ShowOrbChildren(e) {
if (($(e).parent().children('ul').css('display') == 'none' || $(e)
.parent().children('ul').length == 0)
&& $(e).parent().parent().parent().parent().hasClass('orb')) {
$('.orb li li ul').fadeOut('fast');
$(e).parent().children('ul').fadeIn('fast');
}
}
function ShowMenu() {
$('.orb ul').animate({
opacity : 'toggle'
}, 'fast');
}
}
})(jQuery);
\ No newline at end of file
/*
Copyright (c) 2009 Mikael Söderström.
Contact: vimpyboy@msn.com
Feel free to use this script as long as you don't remove this comment.
*/
(function($) {
var rootContext = /* rootContext */
var isLoaded;
var isClosed;
$.fn.Ribbon = function(ribbonSettings) {
var settings = $.extend({
theme : 'windows7'
}, ribbonSettings || {});
if (!isLoaded) {
SetupMenu(settings);
}
function SetupMenu(settings) {
$('.menu li a:first').addClass('active');
$('.menu li ul').hide();
$('.menu li a:first').parent().children('ul:first').show();
$('.menu li a:first').parent().children('ul:first').addClass(
'submenu');
$('.menu li > a').click(function() {
ShowSubMenu(this);
});
$('.orb').click(function() {
ShowMenu();
});
$('.orb ul').hide();
$('.orb ul ul').hide();
$('.orb li ul li ul').show();
$('.orb li li ul')
.each(
function() {
$(this)
.prepend(
'<div style="background-color: #EBF2F7; height: 25px; line-height: 25px; width: 292px; padding-left: 9px; border-bottom: 1px solid #CFDBEB;">'
+ $(this)
.parent()
.children(
'a:first')
.text()
+ '</div>');
});
$('.orb li li a').each(function() {
if ($(this).parent().children('ul').length > 0) {
$(this).addClass('arrow')
}
});
// $('.ribbon-list div').each(function() {
// $(this).parent().width($(this).parent().width()); });
$('.ribbon-list div').click(
function(e) {
var elwidth = $(this).parent().width();
var insideX = e.pageX > $(this).offset().left
&& e.pageX < $(this).offset().left
+ $(this).width();
var insideY = e.pageY > $(this).offset().top
&& e.pageY < $(this).offset().top
+ $(this).height();
$('.ribbon-list div ul').fadeOut('fast');
if (insideX && insideY) {
$(this).attr(
'style',
'background-image: '
+ $(this).css('background-image'));
$(this).parent().width(elwidth);
$(this).children('ul').width(elwidth - 4);
$(this).children('ul').fadeIn('fast');
}
});
$('.ribbon-list div')
.parents()
.click(
function(e) {
if ($('.ribbon-list div ul:visible').parent()
.offset()) {
var outsideX = e.pageX < $(
'.ribbon-list div ul:visible')
.parent().offset().left
|| e.pageX > $(
'.ribbon-list div ul:visible')
.parent().offset().left
+ $(
'.ribbon-list div ul:visible')
.parent().width();
var outsideY = e.pageY < $(
'.ribbon-list div ul:visible')
.parent().offset().top
|| e.pageY > $(
'.ribbon-list div ul:visible')
.parent().offset().top
+ $(
'.ribbon-list div ul:visible')
.parent().height();
if (outsideX || outsideY) {
$('.ribbon-list div ul:visible').each(
function() {
$(this).fadeOut('fast');
});
$('.ribbon-list div').css(
'background-image', '');
}
}
});
$('.orb li li a').mouseover(function() {
ShowOrbChildren(this);
});
}
$('.ribbon').parents().click(
function(e) {
var outsideX = e.pageX < $('.orb ul:first').offset().left
|| e.pageX > $('.orb ul:first').offset().left
+ $('.orb ul:first').width();
var outsideY = e.pageY < $('.orb ul:first img:first')
.offset().top
|| e.pageY > $('.orb ul:first').offset().top
+ $('.orb ul:first').height();
if (outsideX || outsideY)
$('.orb ul').fadeOut('fast');
});
if (isLoaded) {
$('.orb li:first ul:first img:first').remove();
$('.orb li:first ul:first img:last').remove();
$('.ribbon-list div img[src*="/'+rootContext+'/images/ribbon/arrow_down.png"]').remove();
}
$('.orb li:first ul:first')
.prepend(
'<img src="/'+rootContext+'/images/ribbon/menu_top.png" style="margin-left: -10px; margin-top: -22px;" />');
$('.orb li:first ul:first')
.append(
'<img src="/'+rootContext+'/images/ribbon/menu_bottom.png" style="margin-left: -10px; margin-bottom: -22px;" />');
$('.ribbon-list div')
.each(
function() {
if ($(this).children('ul').length > 0) {
$(this).append('<img src="/'+rootContext+'/images/ribbon/arrow_down.png" style="float: right; margin-top: 5px;" />')
}
});
// Hack for IE 7.
if (navigator.appVersion.indexOf('MSIE 6.0') > -1
|| navigator.appVersion.indexOf('MSIE 7.0') > -1) {
$('ul.menu li li div').css('width', '90px');
$('ul.menu').css('width', '500px');
$('ul.menu').css('float', 'left');
$('ul.menu .submenu li div.ribbon-list').css('width', '100px');
$('ul.menu .submenu li div.ribbon-list div').css('width', '100px');
}
$('a[href=' + window.location.hash + ']').click();
isLoaded = true;
function ResetSubMenu() {
$('.menu li a').removeClass('active');
$('.menu ul').removeClass('submenu');
$('.menu li ul').hide();
}
function ShowSubMenu(e) {
var isActive = $(e).next().css('display') == 'block';
ResetSubMenu();
$(e).addClass('active');
$(e).parent().children('ul:first').addClass('submenu');
$(e).parent().children('ul:first').show();
$('body').css('padding-top', '120px');
isClosed = false;
}
function ShowOrbChildren(e) {
if (($(e).parent().children('ul').css('display') == 'none' || $(e)
.parent().children('ul').length == 0)
&& $(e).parent().parent().parent().parent().hasClass('orb')) {
$('.orb li li ul').fadeOut('fast');
$(e).parent().children('ul').fadeIn('fast');
}
}
function ShowMenu() {
$('.orb ul').animate({
opacity : 'toggle'
}, 'fast');
}
}
})(jQuery);
\ No newline at end of file
/*
Copyright (c) 2009 Mikael Söderström.
Contact: vimpyboy@msn.com
Feel free to use this script as long as you don't remove this comment.
*/
(function($) {
var rootContext = "FMcockpit"
var isLoaded;
var isClosed;
$.fn.Ribbon = function(ribbonSettings) {
var settings = $.extend({
theme : 'windows7'
}, ribbonSettings || {});
if (!isLoaded) {
SetupMenu(settings);
}
function SetupMenu(settings) {
$('.menu li a:first').addClass('active');
$('.menu li ul').hide();
$('.menu li a:first').parent().children('ul:first').show();
$('.menu li a:first').parent().children('ul:first').addClass(
'submenu');
$('.menu li > a').click(function() {
ShowSubMenu(this);
});
$('.orb').click(function() {
ShowMenu();
});
$('.orb ul').hide();
$('.orb ul ul').hide();
$('.orb li ul li ul').show();
$('.orb li li ul')
.each(
function() {
$(this)
.prepend(
'<div style="background-color: #EBF2F7; height: 25px; line-height: 25px; width: 292px; padding-left: 9px; border-bottom: 1px solid #CFDBEB;">'
+ $(this)
.parent()
.children(
'a:first')
.text()
+ '</div>');
});
$('.orb li li a').each(function() {
if ($(this).parent().children('ul').length > 0) {
$(this).addClass('arrow')
}
});
// $('.ribbon-list div').each(function() {
// $(this).parent().width($(this).parent().width()); });
$('.ribbon-list div').click(
function(e) {
var elwidth = $(this).parent().width();
var insideX = e.pageX > $(this).offset().left
&& e.pageX < $(this).offset().left
+ $(this).width();
var insideY = e.pageY > $(this).offset().top
&& e.pageY < $(this).offset().top
+ $(this).height();
$('.ribbon-list div ul').fadeOut('fast');
if (insideX && insideY) {
$(this).attr(
'style',
'background-image: '
+ $(this).css('background-image'));
$(this).parent().width(elwidth);
$(this).children('ul').width(elwidth - 4);
$(this).children('ul').fadeIn('fast');
}
});
$('.ribbon-list div')
.parents()
.click(
function(e) {
if ($('.ribbon-list div ul:visible').parent()
.offset()) {
var outsideX = e.pageX < $(
'.ribbon-list div ul:visible')
.parent().offset().left
|| e.pageX > $(
'.ribbon-list div ul:visible')
.parent().offset().left
+ $(
'.ribbon-list div ul:visible')
.parent().width();
var outsideY = e.pageY < $(
'.ribbon-list div ul:visible')
.parent().offset().top
|| e.pageY > $(
'.ribbon-list div ul:visible')
.parent().offset().top
+ $(
'.ribbon-list div ul:visible')
.parent().height();
if (outsideX || outsideY) {
$('.ribbon-list div ul:visible').each(
function() {
$(this).fadeOut('fast');
});
$('.ribbon-list div').css(
'background-image', '');
}
}
});
$('.orb li li a').mouseover(function() {
ShowOrbChildren(this);
});
}
$('.ribbon').parents().click(
function(e) {
var outsideX = e.pageX < $('.orb ul:first').offset().left
|| e.pageX > $('.orb ul:first').offset().left
+ $('.orb ul:first').width();
var outsideY = e.pageY < $('.orb ul:first img:first')
.offset().top
|| e.pageY > $('.orb ul:first').offset().top
+ $('.orb ul:first').height();
if (outsideX || outsideY)
$('.orb ul').fadeOut('fast');
});
if (isLoaded) {
$('.orb li:first ul:first img:first').remove();
$('.orb li:first ul:first img:last').remove();
$('.ribbon-list div img[src*="/'+rootContext+'/images/ribbon/arrow_down.png"]').remove();
}
$('.orb li:first ul:first')
.prepend(
'<img src="/'+rootContext+'/images/ribbon/menu_top.png" style="margin-left: -10px; margin-top: -22px;" />');
$('.orb li:first ul:first')
.append(
'<img src="/'+rootContext+'/images/ribbon/menu_bottom.png" style="margin-left: -10px; margin-bottom: -22px;" />');
$('.ribbon-list div')
.each(
function() {
if ($(this).children('ul').length > 0) {
$(this).append('<img src="/'+rootContext+'/images/ribbon/arrow_down.png" style="float: right; margin-top: 5px;" />')
}
});
// Hack for IE 7.
if (navigator.appVersion.indexOf('MSIE 6.0') > -1
|| navigator.appVersion.indexOf('MSIE 7.0') > -1) {
$('ul.menu li li div').css('width', '90px');
$('ul.menu').css('width', '500px');
$('ul.menu').css('float', 'left');
$('ul.menu .submenu li div.ribbon-list').css('width', '100px');
$('ul.menu .submenu li div.ribbon-list div').css('width', '100px');
}
$('a[href=' + window.location.hash + ']').click();
isLoaded = true;
function ResetSubMenu() {
$('.menu li a').removeClass('active');
$('.menu ul').removeClass('submenu');
$('.menu li ul').hide();
}
function ShowSubMenu(e) {
var isActive = $(e).next().css('display') == 'block';
ResetSubMenu();
$(e).addClass('active');
$(e).parent().children('ul:first').addClass('submenu');
$(e).parent().children('ul:first').show();
$('body').css('padding-top', '120px');
isClosed = false;
}
function ShowOrbChildren(e) {
if (($(e).parent().children('ul').css('display') == 'none' || $(e)
.parent().children('ul').length == 0)
&& $(e).parent().parent().parent().parent().hasClass('orb')) {
$('.orb li li ul').fadeOut('fast');
$(e).parent().children('ul').fadeIn('fast');
}
}
function ShowMenu() {
$('.orb ul').animate({
opacity : 'toggle'
}, 'fast');
}
}
})(jQuery);
\ No newline at end of file
......@@ -23,7 +23,7 @@ public class ProductLineTemplateEngine {
this.chosenProduct = chosenProduct;
}
private String generateFile(String templateFilename, String outputFilename) throws IOException {
private String generateFile_intern(String templateFilename, String outputFilename) throws IOException {
LOG.debug("Generating '" + outputFilename + "' from '" + templateFilename + "'");
ProductLineTemplateReader reader = new ProductLineTemplateReader(templateFilename, chosenProduct);
ProductLineGenerator generator = new ProductLineGenerator(reader.getContent(), reader.getVariables());
......@@ -77,18 +77,11 @@ public class ProductLineTemplateEngine {
}
}
public String generateCss(File file) throws IOException {
public String generateFile(File file) throws IOException {
String templateFilename = file.getAbsolutePath();
String outputFilename = templateFilename.replaceFirst("_template\\.css\\z", ".css");
String outputFilename = templateFilename.replaceFirst("_template\\.(\\p{Alnum}+)\\z", ".$1");
return generateFile(templateFilename, outputFilename);
}
public String generateGroovy(File file) throws IOException {
String templateFilename = file.getAbsolutePath();
String outputFilename = templateFilename.replaceFirst("_template\\.groovy\\z", ".groovy");
return generateFile(templateFilename, outputFilename);
return generateFile_intern(templateFilename, outputFilename);
}
private void renameClassInGroovyFile(final File groovyTemplateFile, final File generatedFile) throws IOException {
......@@ -110,11 +103,4 @@ public class ProductLineTemplateEngine {
generatedFile.setReadOnly();
}
public String generateGsp(File file) throws IOException {
String templateFilename = file.getAbsolutePath();
String outputFilename = templateFilename.replaceFirst("_template\\.gsp\\z", ".gsp");
return generateFile(templateFilename, outputFilename);
}
}
......@@ -5,13 +5,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import de.chw.util.unicode.ANTLRFileStreamWithBOM;
public class ProductLineTemplateReader {
private static final Logger LOG = LogManager.getLogger(ProductLineTemplateReader.class);
......@@ -26,7 +27,7 @@ public class ProductLineTemplateReader {
this.chosenProduct = chosenProduct;
this.variables.put("default", new HashMap<String, String>());
CssTemplateEngineLexer lexer = new CssTemplateEngineLexer(new ANTLRFileStream(filename));
CssTemplateEngineLexer lexer = new CssTemplateEngineLexer(new ANTLRFileStreamWithBOM(filename));
CssTemplateEngineParser parser = new CssTemplateEngineParser(new CommonTokenStream(lexer));
try {
......
/***************************************************************************
* Copyright 2012 by
* + Christian-Albrechts-University of Kiel
* + Department of Computer Science
* + Software Engineering Group
* and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package de.chw.util.unicode;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.BufferOverflowException;
import org.antlr.runtime.ANTLRStringStream;
/**
* Java's InputStream implementations do not support the Byte Order Marker at the beginning of a
* UTF-8/16/32 file. They throw an exception instead. Thus, we need an own implementation that is
* able to detect and skip those BOM characters.
*
* @author chw
*/
public class ANTLRFileStreamWithBOM extends ANTLRStringStream {
protected String fileName;
public ANTLRFileStreamWithBOM(final String fileName, final String encoding) throws IOException {
this.fileName = fileName;
load(encoding);
}
public ANTLRFileStreamWithBOM(final String fileName) throws IOException {
this(fileName, null);
}
protected void load(final String encoding) throws IOException {
if (fileName == null) {
return;
}
File f = new File(fileName);
long length = f.length();
if (length > Integer.MAX_VALUE) {
throw new BufferOverflowException();
}
int size = (int) length;
InputStreamReader isr;
FileInputStream fis = new FileInputStream(fileName);
UnicodeBOMInputStream bomInputStream = new UnicodeBOMInputStream(fis);
bomInputStream.skipBOM();
if (encoding != null) {
isr = new InputStreamReader(bomInputStream, encoding);
} else {
isr = new InputStreamReader(bomInputStream);
}
// bug in ANTLR: what if size is > Integer.MAX_VALUE
// solution: read content within a loop and with a StringBuilder
try {
data = new char[size];
super.n = isr.read(data);
} finally {
isr.close();
}
}
@Override
public String getSourceName() {
return fileName;
}
}
/***************************************************************************
* Copyright 2012 by
* + Christian-Albrechts-University of Kiel
* + Department of Computer Science
* + Software Engineering Group
* and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package de.chw.util.unicode;
/*
* ____________________________________________________________________________
* File: UnicodeBOMInputStream.java
* Author: Gregory Pakosz.
* Date: 02 - November - 2005
* ____________________________________________________________________________
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
/**
* The <code>UnicodeBOMInputStream</code> class wraps any <code>InputStream</code> and detects the
* presence of any Unicode BOM
* (Byte Order Mark) at its beginning, as defined by
* <a href="http://www.faqs.org/rfcs/rfc3629.html">RFC 3629 - UTF-8, a transformation format of ISO
* 10646</a>
* <p>
* The <a href="http://www.unicode.org/unicode/faq/utf_bom.html">Unicode FAQ</a> defines 5 types of
* BOMs:
* <ul>
* <li>
*
* <pre>
* 00 00 FE FF = UTF-32, big-endian
* </pre>
*
* </li>
* <li>
*
* <pre>
* FF FE 00 00 = UTF-32, little-endian
* </pre>
*
* </li>
* <li>
*
* <pre>
* FE FF = UTF-16, big-endian
* </pre>
*
* </li>
* <li>
*
* <pre>
* FF FE = UTF-16, little-endian
* </pre>
*
* </li>
* <li>
*
* <pre>
* EF BB BF = UTF-8
* </pre>
*
* </li>
* </ul>
* </p>
* <p>
* Use the {@link #getBOM()} method to know whether a BOM has been detected or not.
* </p>
* <p>
* Use the {@link #skipBOM()} method to remove the detected BOM from the wrapped
* <code>InputStream</code> object.
* </p>
*/
class UnicodeBOMInputStream extends InputStream {
/**
* Type safe enumeration class that describes the different types of Unicode
* BOMs.
*/
public static final class BOM {
/**
* NONE.
*/
public static final BOM NONE = new BOM(new byte[] {}, "NONE");
/**
* UTF-8 BOM (EF BB BF).
*/
public static final BOM UTF_8 = new BOM(new byte[] { (byte) 0xEF, (byte) 0xBB,
(byte) 0xBF }, "UTF-8");
/**
* UTF-16, little-endian (FF FE).
*/
public static final BOM UTF_16_LE = new BOM(new byte[] { (byte) 0xFF, (byte) 0xFE },
"UTF-16 little-endian");
/**
* UTF-16, big-endian (FE FF).
*/
public static final BOM UTF_16_BE = new BOM(new byte[] { (byte) 0xFE, (byte) 0xFF },
"UTF-16 big-endian");
/**
* UTF-32, little-endian (FF FE 00 00).
*/
public static final BOM UTF_32_LE = new BOM(new byte[] { (byte) 0xFF, (byte) 0xFE,
(byte) 0x00, (byte) 0x00 },
"UTF-32 little-endian");
/**
* UTF-32, big-endian (00 00 FE FF).
*/
public static final BOM UTF_32_BE = new BOM(new byte[] { (byte) 0x00, (byte) 0x00,
(byte) 0xFE, (byte) 0xFF }, "UTF-32 big-endian");
/**
* Returns a <code>String</code> representation of this <code>BOM</code> value.
*/
@Override
public final String toString() {
return description;
}
/**
* Returns the bytes corresponding to this <code>BOM</code> value.
*/
public final byte[] getBytes() {
final int length = bytes.length;
final byte[] result = new byte[length];
// Make a defensive copy
System.arraycopy(bytes, 0, result, 0, length);
return result;
}
private BOM(final byte bom[], final String description) {
assert (bom != null) : "invalid BOM: null is not allowed";
assert (description != null) : "invalid description: null is not allowed";
assert (description.length() != 0) : "invalid description: empty string is not allowed";
this.bytes = bom;
this.description = description;
}
final byte bytes[];
private final String description;
} // BOM
/**
* Constructs a new <code>UnicodeBOMInputStream</code> that wraps the
* specified <code>InputStream</code>.
*
* @param inputStream
* an <code>InputStream</code>.
* @throws IOException
* on reading from the specified <code>InputStream</code> when trying to detect the
* Unicode BOM.
*/
public UnicodeBOMInputStream(final InputStream inputStream) throws IOException
{
if (inputStream == null) {
throw new NullPointerException("invalid input stream: null is not allowed");
}
in = new PushbackInputStream(inputStream, 4);
final byte bom[] = new byte[4];
final int read = in.read(bom);
switch (read) {
case 4:
if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00)
&& (bom[3] == (byte) 0x00)) {
this.bom = BOM.UTF_32_LE;
break;
} else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00)
&& (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
this.bom = BOM.UTF_32_BE;
break;
}
//$FALL-THROUGH$
case 3:
if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
this.bom = BOM.UTF_8;
break;
}
//$FALL-THROUGH$
case 2:
if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
this.bom = BOM.UTF_16_LE;
break;
} else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
this.bom = BOM.UTF_16_BE;
break;
}
//$FALL-THROUGH$
default:
this.bom = BOM.NONE;
break;
}
if (read > 0) {
in.unread(bom, 0, read);
}
}
/**
* Returns the <code>BOM</code> that was detected in the wrapped <code>InputStream</code>
* object.
*
* @return a <code>BOM</code> value.
*/
public final BOM getBOM() {
// BOM type is immutable.
return bom;
}
/**
* Skips the <code>BOM</code> that was found in the wrapped <code>InputStream</code> object.
*
* @return this <code>UnicodeBOMInputStream</code>.
* @throws IOException
* when trying to skip the BOM from the wrapped <code>InputStream</code> object.
*/
public final synchronized UnicodeBOMInputStream skipBOM() throws IOException {
if (!skipped) {
in.skip(bom.bytes.length);
skipped = true;
}
return this;
}
/**
* {@inheritDoc}
*/
@Override
public int read() throws IOException {
return in.read();
}
/**
* {@inheritDoc}
*/
@Override
public int read(final byte b[]) throws IOException, NullPointerException {
return in.read(b, 0, b.length);
}
/**
* {@inheritDoc}
*/
@Override
public int read(final byte b[], final int off, final int len) throws IOException,
NullPointerException {
return in.read(b, off, len);
}
/**
* {@inheritDoc}
*/
@Override
public long skip(final long n) throws IOException {
return in.skip(n);
}
/**
* {@inheritDoc}
*/
@Override
public int available() throws IOException {
return in.available();
}
/**
* {@inheritDoc}
*/
@Override
public void close() throws IOException {
in.close();
}
/**
* {@inheritDoc}
*/
@Override
public synchronized void mark(final int readlimit) {
in.mark(readlimit);
}
/**
* {@inheritDoc}
*/
@Override
public synchronized void reset() throws IOException {
in.reset();
}
/**
* {@inheritDoc}
*/
@Override
public boolean markSupported() {
return in.markSupported();
}
private final PushbackInputStream in;
private final BOM bom;
private boolean skipped = false;
} // UnicodeBOMInputStream
\ No newline at end of file
/***************************************************************************
* Copyright 2012 by
* + Christian-Albrechts-University of Kiel
* + Department of Computer Science
* + Software Engineering Group
* and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package de.chw.util.unicode;
public class UnknownDatatypeException extends RuntimeException {
private static final long serialVersionUID = 4395476105914018790L;
public UnknownDatatypeException(final String message) {
super(message);
}
}
......@@ -35,6 +35,11 @@ public class ProductLineGeneratorTest {
testProductLineGenerator("resource/standard", "css");
}
@Test
public void testStandardJavascript() throws IOException {
testProductLineGenerator("resource/jquery.ribbon_template", "js");
}
@Test
public void testTemplateCss() throws Exception {
testProductLineGenerator("resource/template", "css");
......
......@@ -47,7 +47,8 @@ public class ProductLineTemplateEngineTest {
@Test
public void testGenerateImageFileWithFallback() throws IOException {
testGenerateBinaryFile("resource/logo_template_default.png", "missingProduct", "resource/logo_template_default.png");
testGenerateBinaryFile("resource/logo_template_default.png", "missingProduct",
"resource/logo_template_default.png");
}
@Test
......@@ -68,7 +69,7 @@ public class ProductLineTemplateEngineTest {
File file = new File("resource/dashboard_template.css");
ProductLineTemplateEngine engine = new ProductLineTemplateEngine("fm");
engine.generateCss(file);
engine.generateFile(file);
File generatedFile = new File("resource/dashboard.css");
assertTrue(generatedFile.exists());
......@@ -81,7 +82,7 @@ public class ProductLineTemplateEngineTest {
File file = new File("resource/BuildConfig_template.groovy");
ProductLineTemplateEngine engine = new ProductLineTemplateEngine("fm");
engine.generateGroovy(file);
engine.generateFile(file);
File generatedFile = new File("resource/BuildConfig.groovy");
assertTrue(generatedFile.exists());
......@@ -89,6 +90,19 @@ public class ProductLineTemplateEngineTest {
generatedFile.delete();
}
@Test
public void testGenerateJavascript() throws IOException {
File file = new File("resource/jquery.ribbon_template.js");
ProductLineTemplateEngine engine = new ProductLineTemplateEngine("bm");
engine.generateFile(file);
File generatedFile = new File("resource/jquery.ribbon.js");
assertTrue(generatedFile.exists());
// clean up
generatedFile.delete();
}
@Test
public void testRenameGroovyWithClass() throws IOException {
File templateFile = new File("resource/BootStrap_template_default.groovy");
......
......@@ -25,6 +25,19 @@ public class ProductLineTemplateReaderTest {
assertEquals(expected, reader.getContent());
}
@Test
public void testReadingContentWithBOMCorrectly() throws IOException {
final String filenamePrefix = "jquery.ribbon_template";
final String ext = "js";
String filename = "resource/" + filenamePrefix + "." + ext;
String chosenProduct = "bm";
ProductLineTemplateReader reader = new ProductLineTemplateReader(filename, chosenProduct);
String expected = FileHelper.readTextFile("resource/" + filenamePrefix + "_content_expected" + "." + ext);
assertEquals(expected, reader.getContent());
}
@Test
public void testDefaultFallback() throws IOException {
final String filenamePrefix = "main_template";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment