KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > internal > URIContextFactory


1 /*
2  * Copyright 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  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow.internal;
19
20 import org.apache.beehive.netui.core.urls.MutableURI;
21 import org.apache.beehive.netui.core.urls.URIContext;
22 import org.apache.beehive.netui.util.config.ConfigUtil;
23 import org.apache.beehive.netui.util.config.bean.UrlConfig;
24
25 /**
26  * Factory for the {@link URIContext} with the data needed to write out
27  * a string form of a {@link MutableURI}.
28  */

29 public final class URIContextFactory
30 {
31
32     /* do not construct */
33     private URIContextFactory()
34     {
35     }
36
37     /**
38      * Get a URIContext. The context has data used to write a MutableURI
39      * as a string. For example, it will indicate that the URI should be
40      * written using the "&" entity, rather than the
41      * character, '&'. This returns the default context, but also
42      * checks for any overriding setting in the NetUI config.
43      *
44      * @return the URIContext
45      */

46     public static final URIContext getInstance()
47     {
48         URIContext uriContext = MutableURI.getDefaultContext();
49         UrlConfig urlConfig = ConfigUtil.getConfig().getUrlConfig();
50
51         if ( urlConfig != null && urlConfig.isSetHtmlAmpEntity() )
52         {
53             uriContext.setUseAmpEntity( urlConfig.getHtmlAmpEntity() );
54         }
55
56         return uriContext;
57     }
58
59     /**
60      * Get a URIContext. If it's for an XML document type, the context
61      * will indicate that the URI should be written using the
62      * "&" entity, rather than the character, '&'.
63      * If it's not for an XML doc type, then use the default context,
64      * but check for any overriding setting in the NetUI config.
65      *
66      * @param forXML flag indicating that the URI is for an XML doc type
67      * @return the URIContext
68      */

69     public static final URIContext getInstance( boolean forXML )
70     {
71         URIContext uriContext = null;
72
73         if ( forXML )
74         {
75             uriContext = new URIContext();
76             uriContext.setUseAmpEntity( true );
77         }
78         else
79         {
80             uriContext = getInstance();
81         }
82
83         return uriContext;
84     }
85 }
86
Popular Tags