private void parse(String template) {

		int offs = 0;
		int lastOffs = 0;

		while ((offs=template.indexOf('$', lastOffs))>-1 && offs<template.length()-1) {

			char next = template.charAt(offs+1);
			switch (next) {
				case '$': // "$$" => escaped single dollar sign
					addTemplatePiece(new TemplatePiece.Text(
							template.substring(lastOffs, offs+1)));
					lastOffs = offs + 2;
					break;
				case '{': // "${...}" => variable
					int closingCurly = template.indexOf('}', offs+2);
					if (closingCurly>-1) {
						addTemplatePiece(new TemplatePiece.Text(
								template.substring(lastOffs, offs)));
						String varName = template.substring(offs+2, closingCurly);
						if (!"cursor".equals(varName) && isParamDefined(varName)) {
							addTemplatePiece(new TemplatePiece.ParamCopy(varName));
						}
						else {
							addTemplatePiece(new TemplatePiece.Param(varName));
						}
						lastOffs = closingCurly + 1;
					}
					break;
			}

		}

		if (lastOffs<template.length()) {
			String text = template.substring(lastOffs);
			addTemplatePiece(new TemplatePiece.Text(text));
		}

	}