Index: _dev/v2template/convert.html
===================================================================
--- _dev/v2template/convert.html	(revision 0)
+++ _dev/v2template/convert.html	(revision 0)
@@ -0,0 +1,229 @@
+﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!--
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
+For licensing, see LICENSE.html or http://ckeditor.com/license
+-->
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+	<title></title>
+	<style type="text/css">
+		textarea
+		{
+			border: 1px solid #ddd;
+		}
+		
+		#error
+		{
+			border: red 1px solid;
+			background-color: #ffffcc;
+			padding: 10px;
+			visibility: hidden;
+		}
+	</style>
+	<script type="text/javascript" src="../../_source/core/loader.js"></script>
+	<script type="text/javascript">
+
+CKEDITOR.loader.load( 'core/xml' );
+	
+	</script>
+	<script type="text/javascript">
+
+function convert( xml )
+{
+	if ( !xml )
+	{
+		hideError();
+		return;
+	}
+	// Initialize the output.
+	var output = '';
+
+	var v3 = document.getElementById( 'v3' );
+	v3.value = '';
+
+	xml = new CKEDITOR.xml( xml );
+
+	var templatesNode = xml.selectSingleNode( '/Templates' );
+
+	if ( !templatesNode )
+	{
+		throwParsingError( 'The <Templates> node was not found' );
+		return ;
+	}
+
+	// Get the imagesBasePath attribute value.
+	var imagesBasePath = templatesNode.getAttribute( 'imagesBasePath' );
+
+	output +=
+'// Register a templates definition set named "default".\n' +
+'CKEDITOR.addTemplates( \'default\',\n' +
+'{\n';
+
+	if ( imagesBasePath )
+	{
+		// If using the default v2 path, use the default v3 as well.
+		if ( imagesBasePath == 'fck_template/images/' )
+			imagesBasePath = 'CKEDITOR.plugins.getPath( \'templates\' ) + \'templates/images/\'';
+		else
+			imagesBasePath = "'" + imagesBasePath + "'";
+
+		output +=
+'	// The name of sub folder which holds the shortcut preview images of the templates.\n' +
+'	imagesPath : CKEDITOR.getUrl( ' + imagesBasePath + ' ),\n' +
+'\n';
+	}
+
+	output +=
+'	// The templates definitions.\n' +
+'	templates :\n' +
+'		[';
+
+	// Retrieve all <Template> nodes.
+	var templateNodes = xml.selectNodes( 'Template', templatesNode );
+
+	for ( var i = 0 ; i < templateNodes.length ; i++ )
+	{
+		var templateNode = templateNodes[ i ];
+			title = fixJsString( templateNode.getAttribute( 'title' ) ),
+			image = fixJsString( templateNode.getAttribute( 'image' ) ),
+			description = fixJsString( xml.getInnerXml( 'Description', templateNode ) ),
+			html = convertHtmlCData( xml.getInnerXml( 'Html', templateNode ) );
+
+		if ( i > 0 )
+			output += ',';
+
+		output +=
+'\n			{\n';
+
+		title && ( output +=
+'				title: \'' + title + '\',\n' );
+
+		image && ( output +=
+'				image: \'' + image + '\',\n' );
+
+		description && ( output +=
+'				description: \'' + description + '\',\n' );
+
+		output +=
+'				html:\n' +
+html + '\n' +
+'			}';
+	}
+
+	output +=
+'\n		]\n' +
+'});\n';
+
+	v3.value = output;
+
+	hideError();
+}
+
+function fixJsString( str )
+{
+	return str && str.replace( /'/g, "\\'" );
+}
+
+function convertHtmlCData( html )
+{
+	if ( !html )
+		return "					''";
+
+	var output = '';
+
+	// Remove the CDATA tag.
+	html = html.replace( /^\s*<!\[CDATA\[/, '' );
+	html = html.replace( /\]\]>\s*$/, '' );
+
+	// Break the HTML lines.
+	var lines = html.split( /(?:\r\n)|\n|\r/ );
+
+	if ( lines.length && /^\s*$/.test( lines[ 0 ] ) )
+		lines.shift();
+
+	if ( lines.length && /^\s*$/.test( lines[ lines.length - 1 ] ) )
+		lines.pop();
+
+	// Find out how many tabs we must remove from the lines to remove the indentation.
+	var indentSize = 0;
+	for ( var i = 0 ; i < lines.length ; i++ )
+	{
+		var tabs = lines[ i ].match( /^\t*/ )[0].length;
+
+		if ( !i || tabs < indentSize )
+			indentSize = tabs;
+	}
+
+	// Now remove the indentation and output the line.
+	for ( var i = 0 ; i < lines.length ; i++ )
+	{
+		var line = lines[ i ];
+
+		if ( indentSize )
+			line = line.substr( indentSize );
+
+		if ( i )
+			output += ' +\n';
+
+		line = line.replace( /^\t+/, function( match )
+			{
+				output += match;
+				return '';
+			});
+
+		line = line.replace( /\u00A0/g, '&nbsp;' );
+
+		output += '					\'' + line + '\'';
+	}
+
+	return output;
+}
+
+function throwParsingError( extraMessage )
+{
+	document.getElementById( 'extraError' ).innerHTML = extraMessage.replace( /</g, '&lt;' );
+	document.getElementById( 'error' ).style.visibility = 'visible';
+}
+
+function hideError()
+{
+	document.getElementById( 'error' ).style.visibility = 'hidden';
+}
+
+window.onload = function()
+{
+	var v2 = document.getElementById( 'v2' );
+	v2.onchange = v2.onkeyup = v2.onpaste = function()
+		{
+			setTimeout( function()
+				{
+					convert( v2.value );
+				}, 0 );
+		};
+}
+
+	</script>
+</head>
+<body>
+	<h1>
+		FCKeditor 2 Template Converter for CKEditor 3</h1>
+	<table style="width: 100%" cellspacing="10">
+		<tr>
+			<td style="width: 50%">
+				<p>
+					Paste the original FCKeditor 2 XML template here:<br />
+					<textarea id="v2" style="width: 100%; height: 400px" wrap="off" spellcheck="false"></textarea></p>
+			</td>
+			<td style="width: 50%">
+				<p>
+					Converted output for CKEditor 3 (double-click to select all):<br />
+					<textarea id="v3" style="width: 100%; height: 400px" wrap="off" ondblclick="this.focus; this.select();"
+						readonly="readonly"></textarea></p>
+			</td>
+		</tr>
+	</table>
+	<p id="error">
+		ERROR: It's not possible to parse the inputted template. <span id="extraError"></span>
+	</p>
+</body>
+</html>
