Source Code Cross Referenced for AbstractParams.java in  » GIS » geonetwork » org » fao » geonet » kernel » harvest » harvester » 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 » GIS » geonetwork » org.fao.geonet.kernel.harvest.harvester 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //=============================================================================
002:        //===	Copyright (C) 2001-2007 Food and Agriculture Organization of the
003:        //===	United Nations (FAO-UN), United Nations World Food Programme (WFP)
004:        //===	and United Nations Environment Programme (UNEP)
005:        //===
006:        //===	This program is free software; you can redistribute it and/or modify
007:        //===	it under the terms of the GNU General Public License as published by
008:        //===	the Free Software Foundation; either version 2 of the License, or (at
009:        //===	your option) any later version.
010:        //===
011:        //===	This program is distributed in the hope that it will be useful, but
012:        //===	WITHOUT ANY WARRANTY; without even the implied warranty of
013:        //===	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:        //===	General Public License for more details.
015:        //===
016:        //===	You should have received a copy of the GNU General Public License
017:        //===	along with this program; if not, write to the Free Software
018:        //===	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019:        //===
020:        //===	Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021:        //===	Rome - Italy. email: geonetwork@osgeo.org
022:        //==============================================================================
023:
024:        package org.fao.geonet.kernel.harvest.harvester;
025:
026:        import java.util.ArrayList;
027:        import java.util.Iterator;
028:        import java.util.UUID;
029:        import jeeves.exceptions.BadInputEx;
030:        import jeeves.exceptions.BadParameterEx;
031:        import jeeves.exceptions.MissingParameterEx;
032:        import jeeves.utils.Util;
033:        import org.fao.geonet.kernel.DataManager;
034:        import org.fao.geonet.kernel.harvest.harvester.Privileges;
035:        import org.fao.geonet.lib.Lib;
036:        import org.jdom.Element;
037:
038:        //=============================================================================
039:
040:        public abstract class AbstractParams {
041:            //---------------------------------------------------------------------------
042:            //---
043:            //--- Constructor
044:            //---
045:            //---------------------------------------------------------------------------
046:
047:            public AbstractParams(DataManager dm) {
048:                this .dm = dm;
049:            }
050:
051:            //---------------------------------------------------------------------------
052:            //---
053:            //--- API methods
054:            //---
055:            //---------------------------------------------------------------------------
056:
057:            public void create(Element node) throws BadInputEx {
058:                Element site = node.getChild("site");
059:                Element opt = node.getChild("options");
060:                Element account = (site == null) ? null : site
061:                        .getChild("account");
062:
063:                name = Util.getParam(site, "name", "");
064:                uuid = Util
065:                        .getParam(site, "uuid", UUID.randomUUID().toString());
066:
067:                useAccount = Util.getParam(account, "use", false);
068:                username = Util.getParam(account, "username", "");
069:                password = Util.getParam(account, "password", "");
070:
071:                every = Util.getParam(opt, "every", 90);
072:                oneRunOnly = Util.getParam(opt, "oneRunOnly", false);
073:
074:                checkEvery(every);
075:
076:                addPrivileges(node.getChild("privileges"));
077:                addCategories(node.getChild("categories"));
078:            }
079:
080:            //---------------------------------------------------------------------------
081:
082:            public void update(Element node) throws BadInputEx {
083:                Element site = node.getChild("site");
084:                Element opt = node.getChild("options");
085:                Element account = (site == null) ? null : site
086:                        .getChild("account");
087:                Element privil = node.getChild("privileges");
088:                Element categ = node.getChild("categories");
089:
090:                name = Util.getParam(site, "name", name);
091:
092:                useAccount = Util.getParam(account, "use", useAccount);
093:                username = Util.getParam(account, "username", username);
094:                password = Util.getParam(account, "password", password);
095:
096:                every = Util.getParam(opt, "every", every);
097:                oneRunOnly = Util.getParam(opt, "oneRunOnly", oneRunOnly);
098:
099:                checkEvery(every);
100:
101:                if (privil != null)
102:                    addPrivileges(privil);
103:
104:                if (categ != null)
105:                    addCategories(categ);
106:            }
107:
108:            //---------------------------------------------------------------------------
109:
110:            public Iterable<Privileges> getPrivileges() {
111:                return alPrivileges;
112:            }
113:
114:            public Iterable<String> getCategories() {
115:                return alCategories;
116:            }
117:
118:            //---------------------------------------------------------------------------
119:            //---
120:            //--- Protected methods
121:            //---
122:            //---------------------------------------------------------------------------
123:
124:            protected void copyTo(AbstractParams copy) {
125:                copy.name = name;
126:                copy.uuid = uuid;
127:
128:                copy.useAccount = useAccount;
129:                copy.username = username;
130:                copy.password = password;
131:
132:                copy.every = every;
133:                copy.oneRunOnly = oneRunOnly;
134:
135:                for (Privileges p : alPrivileges)
136:                    copy.alPrivileges.add(p.copy());
137:
138:                for (String s : alCategories)
139:                    copy.alCategories.add(s);
140:            }
141:
142:            //---------------------------------------------------------------------------
143:
144:            protected void checkEvery(int every) throws BadParameterEx {
145:                if (every < 1 || every > MAX_EVERY)
146:                    throw new BadParameterEx("every", every);
147:            }
148:
149:            //---------------------------------------------------------------------------
150:
151:            protected void checkPort(int port) throws BadParameterEx {
152:                if (port < 1 || port > 65535)
153:                    throw new BadParameterEx("port", port);
154:            }
155:
156:            //---------------------------------------------------------------------------
157:            //---
158:            //--- Privileges and categories API methods
159:            //---
160:            //---------------------------------------------------------------------------
161:
162:            /** Fills a list with Privileges that reflect the input 'privileges' element.
163:             * The 'privileges' element has this format:
164:             *
165:             *   <privileges>
166:             *      <group id="...">
167:             *         <operation name="...">
168:             *         ...
169:             *      </group>
170:             *      ...
171:             *   </privileges>
172:             *
173:             * Operation names are: view, download, edit, etc... User defined operations are
174:             * taken into account.
175:             */
176:
177:            private void addPrivileges(Element privil) throws BadInputEx {
178:                alPrivileges.clear();
179:
180:                if (privil == null)
181:                    return;
182:
183:                Iterator groupList = privil.getChildren("group").iterator();
184:
185:                while (groupList.hasNext()) {
186:                    Element group = (Element) groupList.next();
187:                    String groupID = group.getAttributeValue("id");
188:
189:                    if (groupID == null)
190:                        throw new MissingParameterEx("attribute:id", group);
191:
192:                    Privileges p = new Privileges(groupID);
193:
194:                    Iterator operList = group.getChildren("operation")
195:                            .iterator();
196:
197:                    while (operList.hasNext()) {
198:                        Element oper = (Element) operList.next();
199:                        int op = getOperationId(oper);
200:
201:                        p.add(op);
202:                    }
203:
204:                    alPrivileges.add(p);
205:                }
206:            }
207:
208:            //---------------------------------------------------------------------------
209:
210:            private int getOperationId(Element oper) throws BadInputEx {
211:                String operName = oper.getAttributeValue("name");
212:
213:                if (operName == null)
214:                    throw new MissingParameterEx("attribute:name", oper);
215:
216:                int operID = dm.getAccessManager().getPrivilegeId(operName);
217:
218:                if (operID == -1)
219:                    throw new BadParameterEx("attribute:name", operName);
220:
221:                if (operID == 2 || operID == 4)
222:                    throw new BadParameterEx("attribute:name", operName);
223:
224:                return operID;
225:            }
226:
227:            //---------------------------------------------------------------------------
228:            /** Fills a list with category identifiers that reflect the input 'categories' element.
229:             * The 'categories' element has this format:
230:             *
231:             *   <categories>
232:             *      <category id="..."/>
233:             *      ...
234:             *   </categories>
235:             */
236:
237:            private void addCategories(Element categ) throws BadInputEx {
238:                alCategories.clear();
239:
240:                if (categ == null)
241:                    return;
242:
243:                Iterator categList = categ.getChildren("category").iterator();
244:
245:                while (categList.hasNext()) {
246:                    Element categElem = (Element) categList.next();
247:                    String categId = categElem.getAttributeValue("id");
248:
249:                    if (categId == null)
250:                        throw new MissingParameterEx("attribute:id", categElem);
251:
252:                    if (!Lib.type.isInteger(categId))
253:                        throw new BadParameterEx("attribute:id", categElem);
254:
255:                    alCategories.add(categId);
256:                }
257:            }
258:
259:            //---------------------------------------------------------------------------
260:            //---
261:            //--- Variables
262:            //---
263:            //---------------------------------------------------------------------------
264:
265:            public String name;
266:            public String uuid;
267:
268:            public boolean useAccount;
269:            public String username;
270:            public String password;
271:
272:            public int every;
273:            public boolean oneRunOnly;
274:
275:            //---------------------------------------------------------------------------
276:
277:            protected DataManager dm;
278:
279:            private ArrayList<Privileges> alPrivileges = new ArrayList<Privileges>();
280:            private ArrayList<String> alCategories = new ArrayList<String>();
281:
282:            //---------------------------------------------------------------------------
283:
284:            private static final int MAX_EVERY = 1000000;
285:        }
286:
287:        //=============================================================================
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.