01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.pageflow.internal;
20:
21: import org.apache.beehive.netui.core.urls.MutableURI;
22: import org.apache.beehive.netui.core.urls.URIContext;
23: import org.apache.beehive.netui.util.config.ConfigUtil;
24: import org.apache.beehive.netui.util.config.bean.UrlConfig;
25:
26: /**
27: * Factory for the {@link URIContext} with the data needed to write out
28: * a string form of a {@link MutableURI}.
29: */
30: public final class URIContextFactory {
31:
32: /* do not construct */
33: private URIContextFactory() {
34: }
35:
36: /**
37: * Get a URIContext. The context has data used to write a MutableURI
38: * as a string. For example, it will indicate that the URI should be
39: * written using the "&" entity, rather than the
40: * character, '&'. This returns the default context, but also
41: * checks for any overriding setting in the NetUI config.
42: *
43: * @return the URIContext
44: */
45: public static URIContext getInstance() {
46: URIContext uriContext = MutableURI.getDefaultContext();
47: UrlConfig urlConfig = ConfigUtil.getConfig().getUrlConfig();
48:
49: if (urlConfig != null) {
50: uriContext.setUseAmpEntity(urlConfig.isHtmlAmpEntity());
51: }
52:
53: return uriContext;
54: }
55:
56: /**
57: * Get a URIContext. If it's for an XML document type, the context
58: * will indicate that the URI should be written using the
59: * "&" entity, rather than the character, '&'.
60: * If it's not for an XML doc type, then use the default context,
61: * but check for any overriding setting in the NetUI config.
62: *
63: * @param forXML flag indicating that the URI is for an XML doc type
64: * @return the URIContext
65: */
66: public static URIContext getInstance(boolean forXML) {
67: URIContext uriContext = null;
68:
69: if (forXML) {
70: uriContext = new URIContext();
71: uriContext.setUseAmpEntity(true);
72: } else {
73: uriContext = getInstance();
74: }
75:
76: return uriContext;
77: }
78: }
|