Source Code Cross Referenced for FlatConvert.java in  » Portal » Open-Portal » migration » modules » ldap » 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 » Portal » Open Portal » migration.modules.ldap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package migration.modules.ldap;
002:
003:        import java.util.*;
004:        import java.io.*;
005:        import org.xml.sax.SAXException;
006:
007:        import com.iplanet.portalserver.parser.*; //import com.sun.portal.profile.service.*;
008:        import com.iplanet.portalserver.profile.impl.*;
009:        import com.iplanet.portalserver.profile.share.ProfileBundle;
010:        import netscape.ldap.*;
011:
012:        public class FlatConvert extends CommonXml {
013:            private static ResourceBundle bundle = null;
014:            private static String DeployUri = "/portal";
015:
016:            public static void main(String[] args) {
017:                String ptypeToConvert, fromFile, outFile, dirname;
018:                String localeString = new String();
019:                Locale locale = Locale.getDefault();
020:
021:                localeString = null;
022:                if (System.getProperty("LOCALE_STRING") != null)
023:                    localeString = System.getProperty("LOCALE_STRING");
024:
025:                if (localeString == null)
026:                    locale = Locale.getDefault();
027:
028:                bundle = ResourceBundle.getBundle("psMigrationLdap", locale);
029:
030:                ptypeToConvert = args[0];
031:                fromFile = args[1];
032:                outFile = args[2];
033:
034:                getNamingAttributes(System.getProperty("IMPORT_DIR"));
035:                getAMConfigProperties();
036:
037:                //System.out.println("Conversion from  "+fromFile+" to file "+outFile);
038:                if (ptypeToConvert.equalsIgnoreCase("allRoles")) {
039:                    dirname = args[1];
040:                    convertAllRoles(dirname, outFile);
041:                }
042:
043:                try {
044:                    if (ptypeToConvert.equalsIgnoreCase("role"))
045:                        convertRoles(fromFile, outFile);
046:                } catch (Exception e) {
047:                    System.out.println("Error occured in conversion of role:"
048:                            + fromFile);
049:                    System.exit(1);
050:                }
051:
052:            }
053:
054:            static void convertRoles(String infile, String outfile) {
055:
056:                int idx = infile.indexOf("role");
057:                String orgname = infile.substring(idx + 5, infile.indexOf("/",
058:                        idx + 5));
059:                String rolename = getMangledRoleNameFromFilePath(infile,
060:                        orgname);
061:
062:                //System.out.println("role name:"+rolename);
063:
064:                try {
065:                    Component comp = GetComponent(infile);
066:                    comp._compname = rolename;
067:                    WriteToFile(outfile, rolename, orgname, comp);
068:                } catch (SAXException se) {
069:                    System.out.println(se.toString());
070:                    System.out.println(se.getMessage());
071:                } catch (Exception e) {
072:                    e.printStackTrace();
073:                }
074:            }
075:
076:            static void convertAllRoles(String dir, String outfile) {
077:                File currDir = new File(dir);
078:                OutputStreamWriter toWriteTo;
079:                int indent = 0;
080:                String[] orgsList;
081:
082:                if (currDir.isDirectory() == false) {
083:                    System.out
084:                            .println("Error: File name specified. Need to specify the name of the directory where the role files are located");
085:                    System.exit(1);
086:                }
087:                try {
088:                    try {
089:                        toWriteTo = new OutputStreamWriter(
090:                                new FileOutputStream(outfile), "UTF-8");
091:                    } catch (FileNotFoundException fe) {
092:
093:                        System.out
094:                                .println("Is thsi the dire..."
095:                                        + outfile.substring(0, outfile
096:                                                .lastIndexOf("/")));
097:
098:                        try {
099:                            File fl1 = new File(outfile.substring(0, outfile
100:                                    .lastIndexOf("/")));
101:
102:                            fl1.mkdirs();
103:                            toWriteTo = new OutputStreamWriter(
104:                                    new FileOutputStream(outfile), "UTF-8");
105:                        } catch (Exception ee) {
106:                            ee.printStackTrace();
107:                        }
108:                        toWriteTo = new OutputStreamWriter(
109:                                new FileOutputStream(outfile), "UTF-8");
110:                    }
111:                    printHeader(toWriteTo);
112:                    toWriteTo.write("\n<Requests>");
113:
114:                    indent++;
115:                    doIndent(toWriteTo, indent);
116:                    toWriteTo.write("<OrganizationRequests DN=\"" + rootsuffix
117:                            + "\">");
118:                    orgsList = currDir.list();
119:                    for (int i = 0; i < orgsList.length; ++i) {
120:                        //System.out.println("Filename:"+orgsList[i]);
121:                        indent++;
122:                        doIndent(toWriteTo, indent);
123:                        WriteRolesToFile(dir + "/" + orgsList[i], toWriteTo);
124:                    }
125:                    indent--;
126:                    doIndent(toWriteTo, indent);
127:                    toWriteTo.write("</OrganizationRequests>");
128:                    doIndent(toWriteTo, indent);
129:                    for (int i = 0; i < orgsList.length; ++i) {
130:                        //indent++;doIndent(toWriteTo,indent);
131:                        createRoleTemplates(dir + "/" + orgsList[i], toWriteTo);
132:                        //indent--;doIndent(toWriteTo,indent);
133:                    }
134:                    indent--;
135:                    doIndent(toWriteTo, indent);
136:                    toWriteTo.write("</Requests>\n");
137:                    toWriteTo.close();
138:                } catch (Exception e) {
139:                    System.out.println("Error listing the directory!");
140:                    e.printStackTrace();
141:                }
142:                /* catch(IOException ie){
143:                System.out.println("Error opening file :"+outfile);
144:                ie.printStackTrace();
145:                }*/
146:
147:            }
148:
149:            static void createRoleTemplates(String orgName,
150:                    OutputStreamWriter toWriteTo) throws Exception {
151:                Object[] roleList;
152:                File currOrg;
153:                int indent;
154:                String rolename;
155:
156:                currOrg = new File(orgName);
157:
158:                if (currOrg.isDirectory() == false) {
159:                    System.out.println("Ignoring " + orgName
160:                            + ": Not a directory");
161:                    return;
162:                }
163:
164:                roleList = getRecursiveFilelist(currOrg).toArray();
165:
166:                for (int i = 0; i < roleList.length; ++i) {
167:                    File roleFile = (File) roleList[i];
168:                    String roleFileName = roleFile.toString();
169:                    String trueOrgName = orgName.substring(orgName
170:                            .lastIndexOf("/") + 1, orgName.length());
171:                    indent = 2;
172:                    doIndent(toWriteTo, indent);
173:
174:                    rolename = roleFileName.substring(roleFileName
175:                            .lastIndexOf("/") + 1, roleFileName.length() - 4);
176:
177:                    toWriteTo
178:                            .write("<RoleRequests DN=\""
179:                                    + constructRoleDN(rolename, trueOrgName,
180:                                            rootsuffix) + "\">");
181:                    indent++;
182:                    doIndent(toWriteTo, indent);
183:                    toWriteTo
184:                            .write(getCreateServiceTemplate("SunPortalDesktopService"));
185:                    indent--;
186:                    doIndent(toWriteTo, indent);
187:                    toWriteTo.write("</RoleRequests>");
188:
189:                    toWriteTo
190:                            .write("<RoleRequests DN=\""
191:                                    + constructRoleDN(rolename, trueOrgName,
192:                                            rootsuffix) + "\">");
193:                    indent++;
194:                    doIndent(toWriteTo, indent);
195:
196:                    toWriteTo
197:                            .write("<ModifyServiceTemplate serviceName=\"SunPortalDesktopService\" schemaType=\"Dynamic\">");
198:                    indent++;
199:                    doIndent(toWriteTo, indent);
200:                    toWriteTo.write("<AttributeValuePair>");
201:                    indent++;
202:                    doIndent(toWriteTo, indent);
203:                    toWriteTo
204:                            .write("<Attribute name=\"sunPortalDesktopEditProviderContainerName\"/>");
205:                    doIndent(toWriteTo, indent);
206:                    toWriteTo.write("<Value>TemplateEditContainer</Value>");
207:                    indent--;
208:                    doIndent(toWriteTo, indent);
209:                    toWriteTo.write("</AttributeValuePair>");
210:
211:                    indent--;
212:                    doIndent(toWriteTo, indent);
213:                    toWriteTo.write("</ModifyServiceTemplate>");
214:
215:                    indent--;
216:                    doIndent(toWriteTo, indent);
217:                    toWriteTo.write("</RoleRequests>");
218:                }
219:
220:            }
221:
222:            static void WriteRolesToFile(String orgName,
223:                    OutputStreamWriter toWriteTo) {
224:                Object[] roleList;
225:                File currOrg;
226:                int indent;
227:                String rolename;
228:
229:                currOrg = new File(orgName);
230:
231:                if (currOrg.isDirectory() == false) {
232:                    System.out.println("Ignoring " + orgName
233:                            + ": Not a directory");
234:                    return;
235:                }
236:
237:                roleList = getRecursiveFilelist(currOrg).toArray();
238:                try {
239:                    for (int i = 0; i < roleList.length; ++i) {
240:                        File roleFile = (File) roleList[i];
241:                        String roleFileName = roleFile.toString();
242:                        String trueOrgName = orgName.substring(orgName
243:                                .lastIndexOf("/") + 1, orgName.length());
244:                        indent = 2;
245:                        doIndent(toWriteTo, indent);
246:
247:                        rolename = roleFileName.substring(roleFileName
248:                                .lastIndexOf("/") + 1,
249:                                roleFileName.length() - 4);
250:
251:                        toWriteTo.write("<CreateRole createDN=\"" + rolename
252:                                + "," + orgNaming + trueOrgName + "\">");
253:
254:                        Component comp = GetComponent(roleFileName);
255:                        comp._compname = rolename;
256:
257:                        Privilege tmpPr;
258:                        Vector tmpValues;
259:                        Enumeration keys;
260:                        Hashtable ht = new Hashtable();
261:                        for (int j = 0; j < (comp._privileges).size(); ++j) {
262:                            tmpPr = (Privilege) ((comp._privileges)
263:                                    .elementAt(j));
264:                            //System.out.println("Name is:"+tmpPr.name);
265:                            if ((tmpPr.name).startsWith("iwt"))
266:                                break; // Ignoring attributes as in iwtPlatform
267:                            // as they don't have equiv in hana...
268:                            keys = tmpPr._atts.keys();
269:                            while (keys.hasMoreElements()) {
270:
271:                                String key = (String) keys.nextElement();
272:                                if (Element.mapper.get(key) != null) {
273:                                    indent++;
274:                                    doIndent(toWriteTo, indent);
275:                                    ht.put(tmpPr.name + Element.PRIVPREFIX
276:                                            + Element.mapper.get(key),
277:                                            tmpPr._atts.get(key));
278:                                    toWriteTo.write("<AttributeValuePair>");
279:                                    indent++;
280:                                    doIndent(toWriteTo, indent);
281:                                    toWriteTo.write("<Attribute name=\""
282:                                            + tmpPr.name + "\"/>");
283:                                    toWriteTo.write("<Value>");
284:                                    //tmpValues=(Vector)tmpPr._atts.get(key);
285:                                    //System.out.println("Size is:"+(tmpPr._atts.get(key)).getClass());
286:
287:                                    if (((tmpPr._atts.get(key)).getClass()) == (new String())
288:                                            .getClass())
289:                                        toWriteTo.write(tmpPr._atts.get(key)
290:                                                .toString());
291:
292:                                    else {
293:                                        /* System.out.println((tmpPr._atts.get(key)).getClass());
294:                                         for(int m=0;m<((Vector)(tmpPr._atts.get(key))).size();++m)
295:                                        	System.out.print(((Vector)(tmpPr._atts.get(key))).elementAt(m));*/
296:
297:                                    }
298:                                    toWriteTo.write("</Value>");
299:                                    indent--;
300:                                    doIndent(toWriteTo, indent);
301:                                    toWriteTo.write("</AttributeValuePair>");
302:                                    indent--;
303:                                    doIndent(toWriteTo, indent);
304:                                }
305:                            }
306:                        }
307:                        indent--;
308:                        doIndent(toWriteTo, indent);
309:                        toWriteTo.write("</CreateRole>");
310:
311:                    }
312:                } catch (Exception e) {
313:                    e.printStackTrace();
314:                }
315:
316:                return;
317:            }
318:
319:            public static void printHeader(OutputStreamWriter fw)
320:                    throws IOException {
321:
322:                if (System.getProperty("DEPLOY_URI") != null)
323:                    DeployUri = System.getProperty("DEPLOY_URI");
324:
325:                fw.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
326:                fw
327:                        .write("\n<!--  PROPRIETARY/CONFIDENTIAL/ Use of this product is subject");
328:                fw
329:                        .write("\n to license terms. Copyright 2001 Sun Microsystems Inc.");
330:                fw.write("Some preexisting portions Copyright 2001 Netscape");
331:                fw.write("Communications Corp. All rights reserved. -->");
332:                fw
333:                        .write("\n<!DOCTYPE Requests PUBLIC \"-//Sun ONE//iDSAME 5.0 Admin CLI DTD//EN \" ");
334:                fw.write("\"file:" + IDSAMEBaseDir + "/dtd/amAdmin.dtd\">");
335:
336:                return;
337:            }
338:
339:            static void doIndent(OutputStreamWriter fw, int count)
340:                    throws IOException {
341:
342:                fw.write("\n");
343:                for (int i = 0; i < count; ++i)
344:                    fw.write("  ");
345:            }
346:
347:            static FileInputStream createTmpWithComponent(String infile)
348:                    throws Exception {
349:                try {
350:                    FileInputStream in = new FileInputStream(infile);
351:                    File tmp = File.createTempFile("wt1234", "xml", new File(
352:                            "/tmp"));
353:                    tmp.deleteOnExit();
354:                    FileOutputStream out = new FileOutputStream(tmp);
355:                    String compstuff = "<iwt:Component name=\"" + infile
356:                            + "\" >\n";
357:                    out.write(compstuff.getBytes());
358:                    byte[] bb = new byte[100];
359:                    int len = 0;
360:                    while ((len = in.read(bb)) != -1) {
361:                        out.write(bb, 0, len);
362:                    }
363:                    compstuff = "</iwt:Component>\n";
364:                    out.write("</iwt:Component>".getBytes());
365:                    in.close();
366:                    out.flush();
367:                    out.close();
368:                    return new FileInputStream(tmp);
369:                } catch (Exception e) {
370:                    throw (e);
371:                }
372:            }
373:
374:            /* Returns a vector of File objects which are all the files under the directory
375:             passed into the method. */
376:            static Vector getRecursiveFilelist(File directory) {
377:                Vector returnList = new Vector();
378:                try {
379:                    File[] currentList = directory.listFiles();
380:                    for (int i = 0; i < currentList.length; i++) {
381:                        if (currentList[i].isDirectory() == true) {
382:                            //            System.out.println("Getting recursive directory "+currentList[i].toString());
383:                            returnList
384:                                    .addAll(getRecursiveFilelist(currentList[i]));
385:                        } else if (currentList[i].isFile()) {
386:                            //            System.out.println("Adding file "+currentList[i].toString());
387:                            returnList.add(currentList[i]);
388:                        } else {
389:                            //            System.out.println("Unknown item "+currentList[i].toString());
390:                        }
391:                    }
392:
393:                } catch (SecurityException se) {
394:                    System.err.println("Unable to access directory within "
395:                            + directory.toString() + "\n");
396:                    se.printStackTrace();
397:                }
398:                return returnList;
399:            }
400:
401:            public static Component GetComponent(String filename)
402:                    throws Exception {
403:                WebtopParser wp = new WebtopParser();
404:                wp.register(Element.COMPONENT_E,
405:                        "migration.modules.ldap.Component");
406:
407:                wp.register(Element.ATT_E, "migration.modules.ldap.Attribute");
408:                wp.register(Element.PRIV_E, "migration.modules.ldap.Privilege");
409:                wp.register(Element.VALUELIST, "migration.modules.ldap.List");
410:                wp.register(Element.DENYLIST, "migration.modules.ldap.List");
411:                wp.register(Element.ALLOWLIST, "migration.modules.ldap.List");
412:                wp.register(Element.CHOICEVALUE, "migration.modules.ldap.List");
413:                wp.register(Element.READPERM, "migration.modules.ldap.List");
414:                wp.register(Element.WRITEPERM, "migration.modules.ldap.List");
415:                wp.register(Element.VALUELISTN, "migration.modules.ldap.List");
416:                wp.register(Element.DENYLISTN, "migration.modules.ldap.List");
417:                wp.register(Element.ALLOWLISTN, "migration.modules.ldap.List");
418:                wp
419:                        .register(Element.CHOICEVALUEN,
420:                                "migration.modules.ldap.List");
421:                wp.register(Element.READPERMN, "migration.modules.ldap.List");
422:                wp.register(Element.WRITEPERMN, "migration.modules.ldap.List");
423:                wp.register("Component", "com.sun.portal.psadmin.AppComponent");
424:                wp.register("Attributes",
425:                        "com.iplanet.portalserver.parser.GenericNode");
426:                wp.register("Privileges",
427:                        "com.iplanet.portalserver.parser.GenericNode");
428:                wp.register("Attribute", "com.sun.portal.psadmin.AppAttribute");
429:                wp.register("Privilege", "com.sun.portal.psadmin.AppPrivilege");
430:                return (Component) wp.parse(createTmpWithComponent(filename));
431:            }
432:
433:            static void WriteToFile(String outfile, String rolename,
434:                    String parent, Component comp) {
435:
436:                int indent = 0;
437:
438:                try {
439:                    OutputStreamWriter toWriteTo = new OutputStreamWriter(
440:                            new FileOutputStream(outfile), "UTF-8");
441:
442:                    printHeader(toWriteTo);
443:                    toWriteTo.write("\n<Requests>");
444:
445:                    indent++;
446:                    doIndent(toWriteTo, indent);
447:                    toWriteTo.write("<OrganizationRequests DN=\"" + rootsuffix
448:                            + "\">");
449:                    indent++;
450:                    doIndent(toWriteTo, indent);
451:                    toWriteTo.write("<CreateRole createDN=\"" + rolename + ","
452:                            + orgNaming + parent + "\">");
453:                    toWriteTo.write("</CreateRole>");
454:                    indent--;
455:                    doIndent(toWriteTo, indent);
456:                    toWriteTo.write("</OrganizationRequests>");
457:                    indent--;
458:                    doIndent(toWriteTo, indent);
459:
460:                    toWriteTo.write("<RoleRequests DN=\""
461:                            + constructRoleDN(rolename, parent, rootsuffix)
462:                            + "\">");
463:                    indent++;
464:                    doIndent(toWriteTo, indent);
465:                    toWriteTo
466:                            .write(getCreateServiceTemplate("SunPortalDesktopService"));
467:                    indent--;
468:                    doIndent(toWriteTo, indent);
469:                    toWriteTo.write("</RoleRequests>");
470:
471:                    toWriteTo.write("<RoleRequests DN=\""
472:                            + constructRoleDN(rolename, parent, rootsuffix)
473:                            + "\">");
474:                    indent++;
475:                    doIndent(toWriteTo, indent);
476:
477:                    toWriteTo
478:                            .write("<ModifyServiceTemplate serviceName=\"SunPortalDesktopService\" schemaType=\"Dynamic\">");
479:                    indent++;
480:                    doIndent(toWriteTo, indent);
481:                    toWriteTo.write("<AttributeValuePair>");
482:                    indent++;
483:                    doIndent(toWriteTo, indent);
484:                    toWriteTo
485:                            .write("<Attribute name=\"sunPortalDesktopEditProviderContainerName\"/>");
486:                    doIndent(toWriteTo, indent);
487:                    toWriteTo.write("<Value>TemplateEditContainer</Value>");
488:                    indent--;
489:                    doIndent(toWriteTo, indent);
490:                    toWriteTo.write("</AttributeValuePair>");
491:
492:                    indent--;
493:                    doIndent(toWriteTo, indent);
494:                    toWriteTo.write("</ModifyServiceTemplate>");
495:                    indent--;
496:                    doIndent(toWriteTo, indent);
497:                    toWriteTo.write("</RoleRequests>");
498:
499:                    toWriteTo.write("</Requests>\n");
500:
501:                    toWriteTo.close();
502:
503:                } catch (IOException ie) {
504:                    System.out.println("Error opening file:" + outfile);
505:                    ie.printStackTrace();
506:
507:                }
508:            }
509:
510:            public static String getMangledRoleNameFromFilePath(
511:                    String rolepath, String orgname) {
512:
513:                int idx = ((rolepath.indexOf("role") + 5) + (orgname.length() + 1));
514:                String roles = rolepath.substring(idx, rolepath.length() - 4);
515:                String rolename = "";
516:
517:                StringTokenizer tokenizer = new StringTokenizer(roles, "/");
518:
519:                while (tokenizer.hasMoreTokens()) {
520:                    rolename += "_" + tokenizer.nextToken();
521:                }
522:
523:                if (rolename.startsWith("_")) {
524:                    rolename = rolename.substring(1, rolename.length());
525:                }
526:
527:                return rolename;
528:            }
529:
530:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.