KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > sitemap > XSLTFactoryLoader


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.sitemap;
17
18 import org.w3c.dom.NodeList JavaDoc;
19
20 /**
21  * This class is used as a XSLT extension class.
22  *
23  * @deprecated This class has been used by the old sitemap engine
24  *
25  * @author <a HREF="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
26  * @author <a HREF="mailto:bloritsch@apache.org">Berin Loritsch</a>
27  * @version CVS $Id: XSLTFactoryLoader.java 30932 2004-07-29 17:35:38Z vgritsenko $
28  */

29 public class XSLTFactoryLoader {
30
31     public String JavaDoc getClassSource(String JavaDoc className, String JavaDoc prefix, String JavaDoc pattern, NodeList JavaDoc conf) throws ClassNotFoundException JavaDoc,
32         InstantiationException JavaDoc, IllegalAccessException JavaDoc, Exception JavaDoc {
33
34         throw new UnsupportedOperationException JavaDoc("CodeFactory is no longer supported.");
35     }
36
37     public String JavaDoc getParameterSource(String JavaDoc className, NodeList JavaDoc conf) throws ClassNotFoundException JavaDoc, InstantiationException JavaDoc,
38         IllegalAccessException JavaDoc, Exception JavaDoc {
39
40         throw new UnsupportedOperationException JavaDoc("CodeFactory is no longer supported.");
41     }
42
43     public String JavaDoc getMethodSource(String JavaDoc className, NodeList JavaDoc conf) throws ClassNotFoundException JavaDoc, InstantiationException JavaDoc,
44         IllegalAccessException JavaDoc, Exception JavaDoc {
45
46         throw new UnsupportedOperationException JavaDoc("CodeFactory is no longer supported.");
47     }
48
49     public boolean isFactory(String JavaDoc className) {
50
51         throw new UnsupportedOperationException JavaDoc("Factories are no longer supported.");
52     }
53
54     /**
55      * Escapes '"' and '\' characters in a String (add a '\' before them) so that it can
56      * be inserted in java source.
57      */

58     public String JavaDoc escape(String JavaDoc string) {
59         if (string.indexOf('\\') == -1 && string.indexOf('"') == -1) {
60             // Nothing to escape
61
return string;
62         }
63
64         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
65         for (int i = 0; i < string.length(); i++) {
66             char ch = string.charAt(i);
67             if (ch == '\\' || ch == '"') {
68                 buf.append('\\');
69             }
70             buf.append(ch);
71         }
72         return buf.toString();
73     }
74
75     /**
76      * Escapes like {@link #escape(String)} after having removed any '\' preceding a '{'.
77      * This is used to insert a pattern with escaped subsitution syntax in Java source.
78      */

79     public String JavaDoc escapeBraces(String JavaDoc string) {
80         if (string.indexOf("\\{") == -1)
81         {
82             return escape(string);
83         }
84
85         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
86         for (int i = 0; i < string.length(); i++) {
87             char ch = string.charAt(i);
88             if (ch != '\\' || i >= (string.length() - 1) || string.charAt(i+1) != '{') {
89                 buf.append(ch);
90             }
91         }
92         return escape(buf.toString());
93     }
94
95     public boolean hasSubstitutions(String JavaDoc pattern) {
96         if (pattern.length() == 0) {
97             return false;
98         }
99         // Does it start by a substitution ?
100
if (pattern.charAt(0) == '{') {
101             return true;
102         }
103
104         // Search for an unescaped '{'
105
int i = 1;
106         while ((i = pattern.indexOf('{', i)) != -1) {
107             if (pattern.charAt(i-1) != '\\') {
108                 return true;
109             }
110             i++; // Pass '{'
111
}
112
113         return false;
114     }
115 }
116
Popular Tags