Source Code Cross Referenced for ImportMetadataServiceImpl.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » archive » impl » 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 » sakai » org.sakaiproject.archive.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/archive/tags/sakai_2-4-1/archive-impl/impl/src/java/org/sakaiproject/archive/impl/ImportMetadataServiceImpl.java $
003:         * $Id: ImportMetadataServiceImpl.java 10228 2006-06-06 14:10:27Z cwen@iupui.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.archive.impl;
021:
022:        import java.util.ArrayList;
023:        import java.util.List;
024:
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:        import org.sakaiproject.archive.api.ImportMetadata;
028:        import org.sakaiproject.archive.api.ImportMetadataService;
029:        import org.w3c.dom.Document;
030:        import org.w3c.dom.Element;
031:        import org.w3c.dom.Node;
032:        import org.w3c.dom.NodeList;
033:
034:        /**
035:         * @author rshastri <a href="mailto:rshastri@iupui.edu ">Rashmi Shastri </a>
036:         * @version $Id: ImportMetadataServiceImpl.java 10228 2006-06-06 14:10:27Z cwen@iupui.edu $
037:         *  
038:         */
039:
040:        public class ImportMetadataServiceImpl implements  ImportMetadataService {
041:            private static final Log LOG = LogFactory
042:                    .getLog(ImportMetadataImpl.class);
043:
044:            private static final String ROOT = "importConfiguration";
045:            private static final String MAPPINGS = "mappings";
046:            private static final String MAP = "map";
047:            private static final String LEGACY_TOOL = "legacyTool";
048:            private static final String SAKAI_TOOL = "sakaiTool";
049:            private static final String SERVICE_NAME = "serviceName";
050:            private static final String FILE_NAME = "filename";
051:            private static final String MANDATORY = "mandatory";
052:
053:            // For Site.xml
054:            private static final String SITE_ROOT = "archive";
055:            private static final String SITE_SERVICE = "org.sakaiproject.site.api.SiteService";
056:            private static final String SITE_APPLICATION_ID = "sakai:site";
057:            private static final String SITE = "site";
058:            private static final String SITE_ROLES = "roles";
059:            private static final String SITE_ROLE_MAINTAIN = "maintain";
060:            private static final String SITE_ROLE_ABILITY = "ability";
061:            private static final String SITE_ROLE_MAINTAIN_USERID = "userId";
062:            private static final String SITE_ROLE_ID = "roleId";
063:            private static final String ID = "id";
064:
065:            private Document document = null;
066:
067:            /* (non-Javadoc)
068:             * @see org.sakaiproject.service.legacy.archive.ImportMetadataService#getImportMetadataElements(org.w3c.dom.Document)
069:             */
070:            public List getImportMetadataElements(Document doc) {
071:                if (LOG.isDebugEnabled()) {
072:                    LOG.debug("getImportMetadataElements(Document" + doc + ")");
073:                }
074:                if (doc == null) {
075:                    throw new IllegalArgumentException(
076:                            "Illegal document argument!");
077:                } else {
078:                    this .document = doc;
079:                    //TODO: Validate the Doc against DTD
080:                    Element root = doc.getDocumentElement();
081:                    if (root.getTagName().equals(ROOT)) {
082:                        NodeList rootNodeList = root.getChildNodes();
083:                        final int length = rootNodeList.getLength();
084:                        for (int i = 0; i < length; i++) {
085:                            Node mapping = rootNodeList.item(i);
086:                            if (mapping.getNodeType() != Node.ELEMENT_NODE) {
087:                                continue;
088:                            }
089:                            Element mappingElement = (Element) mapping;
090:                            if (mappingElement.getTagName().equals(MAPPINGS)) {
091:                                List maps = new ArrayList();
092:                                NodeList mapNode = mappingElement
093:                                        .getChildNodes();
094:                                final int mapLength = mapNode.getLength();
095:                                for (int j = 0; j < mapLength; j++) {
096:                                    Node mapNodes = mapNode.item(j);
097:                                    if (mapNodes.getNodeType() != Node.ELEMENT_NODE) {
098:                                        continue;
099:                                    }
100:                                    Element mapElement = (Element) mapNodes;
101:                                    if (mapElement.getTagName().equals(MAP)) {
102:                                        ImportMetadataImpl importMetadataMap = new ImportMetadataImpl();
103:                                        importMetadataMap.setId(mapElement
104:                                                .getAttribute(ID));
105:                                        importMetadataMap
106:                                                .setFileName(mapElement
107:                                                        .getAttribute(FILE_NAME));
108:                                        importMetadataMap
109:                                                .setLegacyTool(mapElement
110:                                                        .getAttribute(LEGACY_TOOL));
111:
112:                                        importMetadataMap
113:                                                .setSakaiTool(mapElement
114:                                                        .getAttribute(SAKAI_TOOL));
115:                                        importMetadataMap
116:                                                .setSakaiServiceName(mapElement
117:                                                        .getAttribute(SERVICE_NAME));
118:                                        if (mapElement.getAttribute(MANDATORY) != null
119:                                                && mapElement.getAttribute(
120:                                                        MANDATORY).length() > 0
121:                                                && mapElement.getAttribute(
122:                                                        MANDATORY).endsWith(
123:                                                        "true")) {
124:                                            importMetadataMap
125:                                                    .setMandatory(true);
126:                                        }
127:                                        maps.add(importMetadataMap);
128:                                    }
129:                                }
130:                                // import_mapping shall contain only one mapping element, after the
131:                                // first one is done return
132:                                return maps;
133:                            }
134:                        }
135:                    }
136:                }
137:
138:                return null;
139:            }
140:
141:            /* (non-Javadoc)
142:             * @see org.sakaiproject.service.legacy.archive.ImportMetadataService#getImportMapById(java.lang.String)
143:             */
144:            public ImportMetadata getImportMapById(String id) {
145:                if (LOG.isDebugEnabled()) {
146:                    LOG.debug("getImportMapById(String" + id + ")");
147:                }
148:                if (id == null || id.length() < 1) {
149:                    throw new IllegalArgumentException("Illegal id argument!");
150:                }
151:                if (this .document == null) {
152:                    LOG.error("No valid document found");
153:                    return null;
154:                }
155:                Element root = document.getDocumentElement();
156:                if (root.getTagName().equals(ROOT)) {
157:                    NodeList rootNodeList = root.getChildNodes();
158:                    final int length = rootNodeList.getLength();
159:                    for (int i = 0; i < length; i++) {
160:                        Node mapping = rootNodeList.item(i);
161:                        if (mapping.getNodeType() != Node.ELEMENT_NODE) {
162:                            continue;
163:                        }
164:                        Element mappingElement = (Element) mapping;
165:                        if (mappingElement.getTagName().equals(MAPPINGS)) {
166:                            List maps = new ArrayList();
167:                            NodeList mapNode = mappingElement.getChildNodes();
168:                            final int mapLength = mapNode.getLength();
169:                            for (int j = 0; j < mapLength; j++) {
170:                                Node mapNodes = mapNode.item(j);
171:                                if (mapNodes.getNodeType() != Node.ELEMENT_NODE) {
172:                                    continue;
173:                                }
174:                                Element mapElement = (Element) mapNodes;
175:                                if (mapElement.getTagName().equals(MAP)
176:                                        && mapElement.getAttribute(ID) != null
177:                                        && mapElement.getAttribute(ID).equals(
178:                                                id)) {
179:                                    ImportMetadataImpl importMetadataMap = new ImportMetadataImpl();
180:                                    importMetadataMap.setId(mapElement
181:                                            .getAttribute(ID));
182:
183:                                    importMetadataMap.setFileName(mapElement
184:                                            .getAttribute(FILE_NAME));
185:                                    importMetadataMap.setLegacyTool(mapElement
186:                                            .getAttribute(LEGACY_TOOL));
187:
188:                                    importMetadataMap.setSakaiTool(mapElement
189:                                            .getAttribute(SAKAI_TOOL));
190:                                    importMetadataMap
191:                                            .setSakaiServiceName(mapElement
192:                                                    .getAttribute(SERVICE_NAME));
193:                                    if (mapElement.getAttribute(MANDATORY) != null
194:                                            && mapElement.getAttribute(
195:                                                    MANDATORY).length() > 0
196:                                            && mapElement.getAttribute(
197:                                                    MANDATORY).endsWith("true")) {
198:                                        importMetadataMap.setMandatory(true);
199:                                    }
200:                                    return importMetadataMap;
201:                                }
202:                            }
203:                        }
204:                    }
205:                }
206:
207:                return null;
208:            }
209:
210:            /* (non-Javadoc)
211:             * @see org.sakaiproject.service.legacy.archive.ImportMetadataService#hasMaintainRole(java.lang.String, org.w3c.dom.Document)
212:             */
213:            public boolean hasMaintainRole(String username, Document siteDoc) {
214:                if (LOG.isDebugEnabled()) {
215:                    LOG.debug("hasMaintainRole(Document" + siteDoc + ")");
216:                }
217:                if (username == null || username.length() < 1) {
218:                    throw new IllegalArgumentException(
219:                            "Illegal username argument!");
220:                }
221:                if (siteDoc == null) {
222:                    throw new IllegalArgumentException(
223:                            "Illegal document argument!");
224:                } else {
225:                    //TODO: Validate the Doc against Site DTD
226:                    Element root = siteDoc.getDocumentElement();
227:                    if (root.getTagName().equals(SITE_ROOT)) {
228:                        NodeList rootNodeList = root.getChildNodes();
229:                        final int length = rootNodeList.getLength();
230:                        for (int i = 0; i < length; i++) {
231:                            Node service = rootNodeList.item(i);
232:                            if (service.getNodeType() != Node.ELEMENT_NODE) {
233:                                continue;
234:                            }
235:                            Element serviceElement = (Element) service;
236:                            if (serviceElement.getTagName()
237:                                    .equals(SITE_SERVICE)
238:                                    || serviceElement.getTagName().equals(
239:                                            SITE_APPLICATION_ID)) {
240:                                NodeList siteNodes = serviceElement
241:                                        .getChildNodes();
242:                                final int siteNodeLength = siteNodes
243:                                        .getLength();
244:                                for (int j = 0; j < siteNodeLength; j++) {
245:                                    Node siteNode = siteNodes.item(j);
246:                                    if (siteNode.getNodeType() != Node.ELEMENT_NODE) {
247:                                        continue;
248:                                    }
249:                                    Element siteElement = (Element) siteNode;
250:                                    if (siteElement.getTagName().equals(SITE)) {
251:
252:                                        NodeList rolesNodes = siteElement
253:                                                .getChildNodes();
254:                                        final int rolesNodeLength = rolesNodes
255:                                                .getLength();
256:                                        for (int k = 0; k < rolesNodeLength; k++) {
257:                                            Node rolesNode = rolesNodes.item(k);
258:                                            if (rolesNode.getNodeType() != Node.ELEMENT_NODE) {
259:                                                continue;
260:                                            }
261:                                            Element roleElement = (Element) rolesNode;
262:                                            if (roleElement.getTagName()
263:                                                    .equals(SITE_ROLES)) {
264:
265:                                                NodeList mtNodes = roleElement
266:                                                        .getChildNodes();
267:                                                final int mtLength = mtNodes
268:                                                        .getLength();
269:                                                for (int l = 0; l < mtLength; l++) {
270:                                                    Node mtNode = mtNodes
271:                                                            .item(l);
272:                                                    if (mtNode.getNodeType() != Node.ELEMENT_NODE) {
273:                                                        continue;
274:                                                    }
275:                                                    Element mtElement = (Element) mtNode;
276:                                                    if (mtElement
277:                                                            .getTagName()
278:                                                            .equals(
279:                                                                    SITE_ROLE_MAINTAIN)) {
280:                                                        NodeList abNodes = mtElement
281:                                                                .getChildNodes();
282:                                                        final int abLength = abNodes
283:                                                                .getLength();
284:                                                        for (int m = 0; m < abLength; m++) {
285:                                                            Node abNode = abNodes
286:                                                                    .item(m);
287:                                                            if (abNode
288:                                                                    .getNodeType() != Node.ELEMENT_NODE) {
289:                                                                continue;
290:                                                            }
291:                                                            Element abElement = (Element) abNode;
292:                                                            if (abElement
293:                                                                    .getTagName()
294:                                                                    .equals(
295:                                                                            SITE_ROLE_ABILITY)) {
296:                                                                String siteUserID = abElement
297:                                                                        .getAttribute(SITE_ROLE_MAINTAIN_USERID);
298:                                                                String userRole = abElement
299:                                                                        .getAttribute(SITE_ROLE_ID);
300:                                                                if (siteUserID != null
301:                                                                        && siteUserID
302:                                                                                .trim()
303:                                                                                .length() > 0
304:                                                                        && siteUserID
305:                                                                                .equals(username)
306:                                                                        && userRole
307:                                                                                .equals(SITE_ROLE_MAINTAIN)) {
308:                                                                    return true;
309:                                                                }
310:
311:                                                            }
312:                                                        }
313:
314:                                                    }
315:                                                }
316:
317:                                            }
318:                                        }
319:
320:                                    }
321:                                }
322:
323:                            }
324:                        }
325:                    }
326:                }
327:                return false;
328:            }
329:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.