Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 62e494eefa11fb15f0203b1f465bb59817d296a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*******************************************************************************
 * Copyright (c) 2010, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/
package org.eclipse.equinox.bidi;

import org.eclipse.equinox.bidi.advanced.StructuredTextEnvironment;
import org.eclipse.equinox.bidi.advanced.StructuredTextExpertFactory;
import org.eclipse.equinox.bidi.custom.StructuredTextTypeHandler;
import org.eclipse.equinox.bidi.internal.StructuredTextTypesCollector;

/**
 * Provides access to registered structured text handlers.
 * <p>
 * A structured text handler is a subclass of {@link StructuredTextTypeHandler}
 * adapted for a given type of structured text.
 * <p>
 * The constants in this class are identifiers for structured text
 * handlers which are defined and supported "out of the box" by this package.
 * Text handler identifiers can be used when invoking {@link StructuredTextProcessor#processTyped(String, String)},
 * or when invoking <code>getExpert</code> methods in {@link StructuredTextExpertFactory}.
 * <p>
 * The {@link #getHandler} method in this class can be used to get a 
 * structured text handler reference for one of the handlers defined in this
 * package or for additional structured text handlers registered by plug-ins via
 * the <code>org.eclipse.equinox.bidi.bidiTypes</code> extension point.
 * Text handler references can be used when invoking 
 * {@link StructuredTextExpertFactory#getStatefulExpert(StructuredTextTypeHandler, StructuredTextEnvironment)}.
 * <p>
 * This class can be used without OSGi running, but only the structured text types declared
 * in {@link StructuredTextTypeHandlerFactory} and as string constants in this class are available in that mode.
 * </p>
 *  
 * @noinstantiate This class is not intended to be instantiated by clients.
 */
public final class StructuredTextTypeHandlerFactory {

	/**
	 * Structured text handler identifier for comma-delimited lists, such as:
	 * <pre>
	 *  part1,part2,part3
	 * </pre>
	 */
	public static final String COMMA_DELIMITED = "comma"; //$NON-NLS-1$

	/**
	 * Structured text handler identifier for e-mail addresses.
	 */
	public static final String EMAIL = "email"; //$NON-NLS-1$

	/**
	 * Structured text handler identifier for directory and file paths.
	 */
	public static final String FILE = "file"; //$NON-NLS-1$

	/**
	 * Structured text handler identifier for Java code, 
	 * possibly spanning multiple lines.
	 */
	public static final String JAVA = "java"; //$NON-NLS-1$

	/**
	 *  Structured text handler identifier for basic arithmetic expressions.
	 *  <p>
	 *  Currently supported operators are: <code>+-/*()=</code>
	 *  </p></p>
	 *  This set my be extended in the future.
	 *  <p>
	 */
	public static final String MATH = "math"; //$NON-NLS-1$

	/**
	 * Structured text handler identifier for property file statements. It expects the following format:
	 * <pre>
	 *  name=value
	 * </pre>
	 */
	public static final String PROPERTY = "property"; //$NON-NLS-1$

	/**
	 * Structured text handler identifier for regular expressions, 
	 * possibly spanning multiple lines.
	 */
	public static final String REGEXP = "regex"; //$NON-NLS-1$

	/**
	 * Structured text handler identifier for SQL statements, 
	 * possibly spanning multiple lines.
	 */
	public static final String SQL = "sql"; //$NON-NLS-1$

	/**
	 * Structured text handler identifier for strings with the following format:
	 * <pre>
	 *  system(user)
	 * </pre>
	 */
	public static final String SYSTEM_USER = "system"; //$NON-NLS-1$

	/**
	 * Structured text handler identifier for compound names. It expects text to be made of one or more 
	 * parts separated by underscores:
	 * <pre>
	 *  part1_part2_part3
	 * </pre>
	 */
	public static final String UNDERSCORE = "underscore"; //$NON-NLS-1$

	/**
	 * Structured text handler identifier for URLs.
	 */
	public static final String URL = "url"; //$NON-NLS-1$

	/**
	 * Structured text handler identifier for XPath expressions.
	 */
	public static final String XPATH = "xpath"; //$NON-NLS-1$

	// *** New types must be added to StructuredTextTypesCollector#getDefaultTypeHandlers()! 

	/**
	 * Prevents instantiation
	 */
	private StructuredTextTypeHandlerFactory() {
		// placeholder
	}

	/**
	 *  Obtains a structured text handler of a given type.
	 *  
	 *  @param id the string identifying a structured text handler.
	 *  
	 *  @return a handler of the required type, or <code>null</code> 
	 *          if the type is unknown.
	 */
	static public StructuredTextTypeHandler getHandler(String id) {
		return StructuredTextTypesCollector.getInstance().getHandler(id);
	}

}

Back to the top