Source Code Cross Referenced for RegionManager.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » content » webapp » region » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » SourceTap CRM » org.ofbiz.content.webapp.region 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: RegionManager.java,v 1.2 2003/09/14 05:36:48 jonesde Exp $
003:         *
004:         * Copyright (c) 2002-2003 The Open For Business Project - www.ofbiz.org
005:         *
006:         * Permission is hereby granted, free of charge, to any person obtaining a
007:         * copy of this software and associated documentation files (the "Software"),
008:         * to deal in the Software without restriction, including without limitation
009:         * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         * and/or sell copies of the Software, and to permit persons to whom the
011:         * Software is furnished to do so, subject to the following conditions:
012:         *
013:         * The above copyright notice and this permission notice shall be included
014:         * in all copies or substantial portions of the Software.
015:         *
016:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         *
024:         */
025:        package org.ofbiz.content.webapp.region;
026:
027:        import java.net.URL;
028:        import java.util.HashMap;
029:        import java.util.Iterator;
030:        import java.util.List;
031:        import java.util.Map;
032:
033:        import org.ofbiz.base.util.Debug;
034:        import org.ofbiz.base.util.UtilCache;
035:        import org.ofbiz.base.util.UtilValidate;
036:        import org.ofbiz.base.util.UtilXml;
037:        import org.w3c.dom.Document;
038:        import org.w3c.dom.Element;
039:
040:        /**
041:         * A class to manage the region cache and read a region XML file
042:         *
043:         * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
044:         * @version    $Revision: 1.2 $
045:         * @since      2.0
046:         */
047:        public class RegionManager {
048:
049:            public static final String module = RegionManager.class.getName();
050:
051:            protected static UtilCache regionCache = new UtilCache(
052:                    "webapp.Regions.Config", 0, 0);
053:
054:            protected URL regionFile = null;
055:
056:            public RegionManager(URL regionFile) {
057:                this .regionFile = regionFile;
058:                if (regionFile == null)
059:                    throw new IllegalArgumentException(
060:                            "regionFile cannot be null");
061:
062:                //This may seem a bit funny, but we want to keep it in the cache so that it can be reloaded easily
063:                // Also note that we do not check to see if it is already there, in all cases we want to re-load the definition
064:                regionCache.put(regionFile, readRegionXml(regionFile));
065:            }
066:
067:            public Map getRegions() {
068:                Map regions = (Map) regionCache.get(regionFile);
069:                if (regions == null) {
070:                    synchronized (this ) {
071:                        regions = (Map) regionCache.get(regionFile);
072:                        if (regions == null) {
073:                            if (Debug.verboseOn())
074:                                Debug.logVerbose("Regions not loaded for "
075:                                        + regionFile + ", loading now", module);
076:                            regions = readRegionXml(regionFile);
077:                            regionCache.put(regionFile, regions);
078:                        }
079:                    }
080:                }
081:                return regions;
082:            }
083:
084:            public Region getRegion(String regionName) {
085:                if (regionFile == null)
086:                    return null;
087:                return (Region) getRegions().get(regionName);
088:            }
089:
090:            public void putRegion(Region region) {
091:                getRegions().put(region.getId(), region);
092:            }
093:
094:            public Map readRegionXml(URL regionFile) {
095:                Map regions = new HashMap();
096:
097:                Document document = null;
098:
099:                try {
100:                    document = UtilXml.readXmlDocument(regionFile, true);
101:                } catch (java.io.IOException e) {
102:                    Debug.logError(e, module);
103:                } catch (org.xml.sax.SAXException e) {
104:                    Debug.logError(e, module);
105:                } catch (javax.xml.parsers.ParserConfigurationException e) {
106:                    Debug.logError(e, module);
107:                }
108:
109:                if (document == null)
110:                    return regions;
111:
112:                Element rootElement = document.getDocumentElement();
113:
114:                List defineElements = UtilXml.childElementList(rootElement,
115:                        "define");
116:                Iterator defineIter = defineElements.iterator();
117:
118:                while (defineIter.hasNext()) {
119:                    Element defineElement = (Element) defineIter.next();
120:
121:                    addRegion(defineElement, regions);
122:                }
123:
124:                return regions;
125:            }
126:
127:            protected void addRegion(Element defineElement, Map regions) {
128:                Region newRegion = null;
129:
130:                String idAttr = defineElement.getAttribute("id");
131:                String templateAttr = defineElement.getAttribute("template");
132:                String regionAttr = defineElement.getAttribute("region");
133:
134:                if (UtilValidate.isNotEmpty(templateAttr)
135:                        && UtilValidate.isNotEmpty(regionAttr)) {
136:                    throw new IllegalArgumentException(
137:                            "Cannot use both template and region attributes");
138:                }
139:
140:                if (UtilValidate.isNotEmpty(templateAttr)) {
141:                    newRegion = new Region(idAttr, templateAttr, null);
142:                } else {
143:                    if (UtilValidate.isNotEmpty(regionAttr)) {
144:                        Region parentRegion = (Region) regions.get(regionAttr);
145:
146:                        if (parentRegion == null) {
147:                            throw new IllegalArgumentException(
148:                                    "can't find page definition attribute with this key: "
149:                                            + regionAttr);
150:                        }
151:                        newRegion = new Region(idAttr, parentRegion
152:                                .getContent(), parentRegion.getSections());
153:                    } else {
154:                        throw new IllegalArgumentException(
155:                                "Must specify either the template or the region attribute");
156:                    }
157:                }
158:
159:                regions.put(idAttr, newRegion);
160:
161:                List putElements = UtilXml.childElementList(defineElement,
162:                        "put");
163:                Iterator putIter = putElements.iterator();
164:
165:                while (putIter.hasNext()) {
166:                    Element putElement = (Element) putIter.next();
167:
168:                    newRegion.put(makeSection(putElement));
169:                }
170:            }
171:
172:            protected Section makeSection(Element putElement) {
173:                String bodyContent = UtilXml.elementValue(putElement);
174:                String section = putElement.getAttribute("section");
175:                String info = putElement.getAttribute("info");
176:                String content = putElement.getAttribute("content");
177:                String type = putElement.getAttribute("type");
178:
179:                if (UtilValidate.isEmpty(type))
180:                    type = "default";
181:
182:                if (UtilValidate.isNotEmpty(bodyContent)
183:                        && UtilValidate.isNotEmpty(content)) {
184:                    throw new IllegalArgumentException(
185:                            "Cannot use both content attribute and tag body text");
186:                }
187:
188:                if (UtilValidate.isNotEmpty(bodyContent)) {
189:                    content = bodyContent;
190:                    type = "direct";
191:                }
192:
193:                return new Section(section, info, content, type, this );
194:            }
195:
196:            public static Region getRegion(URL regionFile, String regionName) {
197:                if (regionFile == null)
198:                    return null;
199:                Map regions = (Map) regionCache.get(regionFile);
200:                if (regions == null)
201:                    return null;
202:                return (Region) regions.get(regionName);
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.