KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freemarker > eclipse > editors > PartitionScanner


1 /*
2  * Copyright (c) 2003 The Visigoth Software Society. All rights
3  * reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowledgement:
19  * "This product includes software developed by the
20  * Visigoth Software Society (http://www.visigoths.org/)."
21  * Alternately, this acknowledgement may appear in the software
22  * itself, if and wherever such third-party acknowledgements
23  * normally appear.
24  *
25  * 4. Neither the name "FreeMarker", "Visigoth", nor any of the names
26  * of the project contributors may be used to endorse or promote
27  * products derived from this software without prior written
28  * permission. For written permission, please contact
29  * visigoths@visigoths.org.
30  *
31  * 5. Products derived from this software may not be called
32  * "FreeMarker" or "Visigoth" nor may "FreeMarker" or "Visigoth"
33  * appear in their names without prior written permission of the
34  * Visigoth Software Society.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE VISIGOTH SOFTWARE SOCIETY OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Visigoth Software Society. For more
52  * information on the Visigoth Software Society, please see
53  * http://www.visigoths.org/
54  */

55
56 package freemarker.eclipse.editors;
57
58 import java.util.ArrayList JavaDoc;
59 import java.util.List JavaDoc;
60
61 import org.eclipse.jface.text.IDocument;
62 import org.eclipse.jface.text.rules.IPredicateRule;
63 import org.eclipse.jface.text.rules.IToken;
64 import org.eclipse.jface.text.rules.MultiLineRule;
65 import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
66 import org.eclipse.jface.text.rules.Token;
67
68 /**
69  * The FreeMarker template partition scanner. This class separates
70  * the text in the template into a number of non-overlapping
71  * partitions. Each of the partitions can then apply their own
72  * scanners and damage-repair policies within thier boundaries. This
73  * two-stage scanning is done to simplify the scanning in each stage,
74  * and also to minimize repetitive parsing.
75  *
76  * @version $Id: PartitionScanner.java,v 1.9 2003/12/01 00:57:31 cederberg Exp $
77  * @author <a HREF="mailto:stephan@chaquotay.net">Stephan Mueller</a>
78  */

79 public class PartitionScanner extends RuleBasedPartitionScanner {
80
81     public final static String JavaDoc FTL_COMMENT = "__ftl_comment";
82     public final static String JavaDoc FTL_DIRECTIVE = "__ftl_directive";
83     public final static String JavaDoc FTL_INTERPOLATION = "__ftl_interpolation";
84     public final static String JavaDoc XML_TAG = "__xml_tag";
85     public final static String JavaDoc XML_COMMENT = "__xml_comment";
86
87     /**
88      * The array of partitions used.
89      */

90     public final static String JavaDoc[] PARTITIONS = {
91         IDocument.DEFAULT_CONTENT_TYPE,
92         FTL_COMMENT,
93         FTL_DIRECTIVE,
94         FTL_INTERPOLATION,
95         XML_TAG,
96         XML_COMMENT
97     };
98
99     /**
100      * Creates a new partition scanner.
101      */

102     public PartitionScanner() {
103         List JavaDoc rules = new ArrayList JavaDoc();
104
105         IToken ftlComment = new Token(FTL_COMMENT);
106         IToken ftlDirective = new Token(FTL_DIRECTIVE);
107         IToken ftlInterpolation = new Token(FTL_INTERPOLATION);
108         IToken xmlComment = new Token(XML_COMMENT);
109         IToken xmlTag = new Token(XML_TAG);
110
111         rules.add(new MultiLineRule("<#--", "-->", ftlComment));
112         rules.add(new DirectiveRule(ftlDirective));
113         rules.add(new InterpolationRule(ftlInterpolation));
114         rules.add(new XmlCommentRule(xmlComment));
115         rules.add(new XmlRule(xmlTag));
116
117         IPredicateRule[] result= new IPredicateRule[rules.size()];
118         rules.toArray(result);
119         setPredicateRules(result);
120     }
121 }
122
Popular Tags