KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > jet > JETScriptletGenerator


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: JETScriptletGenerator.java,v 1.2 2005/06/08 06:15:56 nickb Exp $
16  */

17 package org.eclipse.emf.codegen.jet;
18
19
20 import java.io.CharArrayWriter JavaDoc;
21
22
23 /**
24  * Generator for <% .... %> stuff.
25  *
26  */

27 public class JETScriptletGenerator
28     implements JETGenerator
29 {
30   protected char[] chars;
31
32   public JETScriptletGenerator(char[] chars)
33   {
34     this.chars = chars;
35   }
36
37   public String JavaDoc generate()
38   {
39     return new String JavaDoc(removeQuotes(chars));
40   }
41
42   public static char[] removeQuotes(char [] characters)
43   {
44     CharArrayWriter JavaDoc writer = new CharArrayWriter JavaDoc();
45     for (int i = 0; i < characters.length; ++i)
46     {
47       if (characters[i] == '%' && characters[i + 1] == '\\' && characters[i + 2] == '\\' && characters[i + 3] == '>')
48       {
49         writer.write('%');
50         writer.write('>');
51         i += 3;
52       }
53       else
54       {
55         writer.write(characters[i]);
56       }
57     }
58
59     return writer.toCharArray();
60   }
61 }
62
Popular Tags