KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > Err


1 package net.sf.saxon;
2
3 /**
4  * Class containing utility methods for handling error messages
5  */

6
7 public class Err {
8
9     public static final int ELEMENT = 1;
10     public static final int ATTRIBUTE = 2;
11     public static final int FUNCTION = 3;
12     public static final int VALUE = 4;
13     public static final int VARIABLE = 5;
14     public static final int GENERAL = 6;
15
16     /**
17      * Add delimiters to represent variable information within an error message
18      * @param cs the variable information to be delimited
19      * @return the delimited variable information
20      */

21     public static String JavaDoc wrap(CharSequence JavaDoc cs) {
22         return wrap(cs, GENERAL);
23     }
24
25     /**
26      * Add delimiters to represent variable information within an error message
27      * @param cs the variable information to be delimited
28      * @param valueType the type of value, e.g. element name or attribute name
29      * @return the delimited variable information
30      */

31     public static String JavaDoc wrap(CharSequence JavaDoc cs, int valueType) {
32         if (cs == null) {
33             return "(NULL)";
34         }
35         String JavaDoc s = cs.toString();
36         s = s.replace('\n', ' ');
37         s = s.replace('\t', ' ');
38         s = s.replace('\r', ' ');
39         if (s.length() > 30) {
40             s = s.substring(0, 30) + "...";
41         }
42         switch (valueType) {
43             case ELEMENT:
44                 return "<" + s + ">";
45             case ATTRIBUTE:
46                 return "@" + s;
47             case FUNCTION:
48                 return s + "()";
49             case VARIABLE:
50                 return "$" + s;
51             case VALUE:
52                 return "\"" + s + "\"";
53             default:
54                 return "{" + s + "}";
55         }
56     }
57
58 }
59 //
60
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
61
// you may not use this file except in compliance with the License. You may obtain a copy of the
62
// License at http://www.mozilla.org/MPL/
63
//
64
// Software distributed under the License is distributed on an "AS IS" basis,
65
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
66
// See the License for the specific language governing rights and limitations under the License.
67
//
68
// The Original Code is: all this file.
69
//
70
// The Initial Developer of the Original Code is Michael H. Kay.
71
//
72
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
73
//
74
// Contributor(s): none.
75
//
Popular Tags