Source Code Cross Referenced for Convert.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) 


0001:        package migration.modules.ldap;
0002:
0003:        import java.util.*;
0004:        import java.io.*;
0005:        import org.xml.sax.SAXException;
0006:
0007:        import com.iplanet.portalserver.parser.*;
0008:        import com.iplanet.portalserver.profile.impl.*;
0009:        import com.iplanet.portalserver.profile.share.ProfileBundle;
0010:        import netscape.ldap.*;
0011:
0012:        public class Convert extends CommonXml {
0013:            private static ResourceBundle bundle = null;
0014:            private static String DeployUri = "/portal";
0015:            private static String version;
0016:
0017:            /* General syntax:
0018:
0019:            java migration.modules.ldap.Convert component infile outfile
0020:            java migration.modules.ldap.Convert role infile outfile
0021:            java migration.modules.ldap.Convert domain infile outfile
0022:            java migration.modules.ldap.Convert user infile outfile [rolefile]
0023:
0024:            java migration.modules.ldap.Convert allRoles dirname outputfile
0025:            java migration.modules.ldap.Convert allDomains dirname outputfile
0026:
0027:             */
0028:            static public void main(String[] args) {
0029:                String ptypeToConvert, fromFile, outFile, dirname;
0030:                String typeConv;
0031:                String localeString = new String();
0032:                Locale locale;
0033:
0034:                localeString = null;
0035:                if (System.getProperty("LOCALE_STRING") != null)
0036:                    localeString = System.getProperty("LOCALE_STRING");
0037:
0038:                if (localeString == null)
0039:                    locale = Locale.getDefault();
0040:                else
0041:                    locale = getLocale(localeString);
0042:
0043:                bundle = ResourceBundle.getBundle("psMigrationLdap", locale);
0044:
0045:                ptypeToConvert = args[0];
0046:                fromFile = args[1];
0047:                outFile = args[2];
0048:
0049:                getNamingAttributes(System.getProperty("IMPORT_DIR"));
0050:                getAMConfigProperties();
0051:
0052:                if (System.getProperty("PVERSION") != null)
0053:                    version = System.getProperty("PVERSION");
0054:
0055:                //System.out.println("Conversion from  "+fromFile+" to file "+outFile);
0056:                if (ptypeToConvert.equalsIgnoreCase("role"))
0057:                    convertRoles(fromFile, outFile);
0058:
0059:                if (ptypeToConvert.equalsIgnoreCase("domain"))
0060:                    convertDomains(fromFile, outFile);
0061:
0062:                if (ptypeToConvert.equalsIgnoreCase("allRoles")) {
0063:                    dirname = args[1];
0064:                    convertAllRoles(dirname, outFile);
0065:                }
0066:                if (ptypeToConvert.equalsIgnoreCase("allDomains")) {
0067:                    dirname = args[1];
0068:                    convertAllDomains(dirname, outFile);
0069:                }
0070:                try {
0071:                    if (ptypeToConvert.equalsIgnoreCase("component"))
0072:                        convertComponents(fromFile, outFile);
0073:
0074:                } catch (Exception e) {
0075:                    System.out
0076:                            .println("Specified file is not a valid file...!!!!");
0077:                    System.out.println("Error being:" + e.getMessage());
0078:                    e.printStackTrace();
0079:                }
0080:                if (ptypeToConvert.equalsIgnoreCase("user")) {
0081:                    if (args[3] != null) {
0082:                        convertUsers(fromFile, outFile, args[3]);
0083:                    } else {
0084:                        convertUsers(fromFile, outFile);
0085:                    }
0086:                }
0087:
0088:            }
0089:
0090:            static java.util.Locale getLocale(String stringformat) {
0091:                if (stringformat == null)
0092:                    return java.util.Locale.getDefault();
0093:
0094:                StringTokenizer tk = new StringTokenizer(stringformat, "_");
0095:                String lang = "";
0096:                String country = "";
0097:                String variant = "";
0098:
0099:                if (tk.hasMoreTokens())
0100:                    lang = tk.nextToken();
0101:                if (tk.hasMoreTokens())
0102:                    country = tk.nextToken();
0103:                if (tk.hasMoreTokens())
0104:                    variant = tk.nextToken();
0105:
0106:                return new java.util.Locale(lang, country, variant);
0107:            }
0108:
0109:            static void convertComponents(String inFile, String outFile)
0110:                    throws Exception {
0111:
0112:                WebtopParser wp = new WebtopParser();
0113:                wp.register(Element.COMPONENT_E,
0114:                        "migration.modules.ldap.Component");
0115:                wp.register(Element.ATT_E, "migration.modules.ldap.Attribute");
0116:                wp.register(Element.PRIV_E, "migration.modules.ldap.Privilege");
0117:                wp.register(Element.VALUELIST, "migration.modules.ldap.List");
0118:                wp.register(Element.DENYLIST, "migration.modules.ldap.List");
0119:                wp.register(Element.ALLOWLIST, "migration.modules.ldap.List");
0120:                wp.register(Element.CHOICEVALUE, "migration.modules.ldap.List");
0121:                wp.register(Element.READPERM, "migration.modules.ldap.List");
0122:                wp.register(Element.WRITEPERM, "migration.modules.ldap.List");
0123:                wp.register(Element.VALUELISTN, "migration.modules.ldap.List");
0124:                wp.register(Element.DENYLISTN, "migration.modules.ldap.List");
0125:                wp.register(Element.ALLOWLISTN, "migration.modules.ldap.List");
0126:                wp
0127:                        .register(Element.CHOICEVALUEN,
0128:                                "migration.modules.ldap.List");
0129:                wp.register(Element.READPERMN, "migration.modules.ldap.List");
0130:                wp.register(Element.WRITEPERMN, "migration.modules.ldap.List");
0131:                wp.register("Component", "com.sun.portal.psadmin.AppComponent");
0132:                wp.register("Attributes",
0133:                        "com.iplanet.portalserver.parser.GenericNode");
0134:                wp.register("Privileges",
0135:                        "com.iplanet.portalserver.parser.GenericNode");
0136:                wp.register("Attribute", "com.sun.portal.psadmin.AppAttribute");
0137:                wp.register("Privilege", "com.sun.portal.psadmin.AppPrivilege");
0138:
0139:                if (inFile.equalsIgnoreCase("iwtNetMail.xml")
0140:                        || inFile.equalsIgnoreCase("iwtNetlet.xml")
0141:                        || inFile.equalsIgnoreCase("iwtNetFile.xml")
0142:                        || inFile.equalsIgnoreCase("iwtGateway.xml")
0143:                        || inFile.equalsIgnoreCase("iwtSession.xml")
0144:                        || inFile.equalsIgnoreCase("iwtLogging.xml"))
0145:                    return;
0146:                if (inFile.equalsIgnoreCase("iwtExtLdap.xml")) {
0147:                    System.out
0148:                            .println("COMPONENT iwtExtLdap.xml HAS NO EQUIVALENT IN "
0149:                                    + version + ". IT NEEDS CUSTOM MIGRATION");
0150:                    return;
0151:                }
0152:                if (inFile.equalsIgnoreCase("iwtDefaultGroup.xml")) {
0153:                    System.out
0154:                            .println("COMPONENT iwtDefaultGroup.xml IS A SAMPLE COMPONENT. NO CORRESPONDING EQUIVALENT IN "
0155:                                    + version);
0156:                    return;
0157:                }
0158:
0159:                Component comp = (Component) wp.parse(new FileInputStream(
0160:                        inFile));
0161:                //	System.out.println("here...***"+comp.toString());
0162:                comp.convertProfile("component", outFile);
0163:                //       System.out.println("Finished parse.....!!!");
0164:
0165:            }
0166:
0167:            static void convertDomains(String infile, String outfile) {
0168:                Privilege tmp;
0169:
0170:                String dn, org;
0171:                String domainname = infile.substring(
0172:                        infile.lastIndexOf("/") + 1, (infile.length() - 4));
0173:                String desktopTypesFileName = outfile.substring(0, outfile
0174:                        .lastIndexOf("/") + 1)
0175:                        + ".desktypes_orgs";
0176:
0177:                try {
0178:
0179:                    SetServiceValues.initHashTable(desktopTypesFileName);
0180:                    Component comp = GetComponent(infile);
0181:                    comp._compname = domainname;//.substring(idx+1,domainname.length());
0182:                    WriteDomain(outfile, domainname, comp);
0183:                    SetServiceValues.writeHashTable(desktopTypesFileName);
0184:
0185:                } catch (SAXException se) {
0186:                    System.out.println(se.toString());
0187:                    System.out.println(se.getMessage());
0188:                } catch (Exception e) {
0189:                    System.out.println("Error in opening specifed file!!");
0190:                    e.printStackTrace();
0191:                }
0192:            }
0193:
0194:            static void convertUsers(String inFile, String outFile) {
0195:                convertUsers(inFile, outFile, null);
0196:            }
0197:
0198:            static void convertUsers(String inFile, String outFile,
0199:                    String roleFile) {
0200:                Users u = new Users();
0201:
0202:                if (roleFile != null) {
0203:                    u.doConvertWithDelegatedAdmin(inFile, outFile, roleFile);
0204:                } else {
0205:                    //System.out.println("Infile...."+inFile+".....Outfile...."+outFile);
0206:                    u.doConvert(inFile, outFile);
0207:                }
0208:
0209:            }
0210:
0211:            static void convertRoles(String infile, String outfile) {
0212:
0213:                Privilege tmpPr;
0214:                int idx = infile.indexOf("role");
0215:                //System.out.println("Index;"+idx);
0216:                String orgname = infile.substring(idx + 5, infile.indexOf("/",
0217:                        idx + 5));
0218:                String rolename = infile.substring(infile.lastIndexOf("/") + 1,
0219:                        (infile.length()) - 4);
0220:
0221:                //System.out.println("role name:"+rolename+"orgname"+orgname);
0222:                try {
0223:
0224:                    Component comp = GetComponent(infile);
0225:                    comp._compname = rolename;
0226:
0227:                    //System.out.println("Converting roles:"+infile+"Size of prive:"+(comp._privileges).size());
0228:                    WriteToFile(outfile, rolename, orgname, comp);
0229:                    /* for(int i=0; i<(comp._privileges).size();++i){
0230:                    	tmpPr=(Privilege)((comp._privileges).elementAt(i));
0231:                    	if((tmpPr.denylist).size() > 0)
0232:                    		System.out.println((tmpPr.denylist).toString());
0233:
0234:                    	if((tmpPr.allowlist).size() > 0)
0235:                    		System.out.println((tmpPr.allowlist).toString());
0236:                    }*/
0237:                } catch (SAXException se) {
0238:                    System.out.println(se.toString());
0239:                    System.out.println(se.getMessage());
0240:                } catch (Exception e) {
0241:                    //	System.out.println("Error in opening specifed file!!");
0242:                    e.printStackTrace();
0243:                }
0244:            }
0245:
0246:            static void convertAllRoles(String dir, String outfile) {
0247:                File currDir = new File(dir);
0248:                OutputStreamWriter toWriteTo;
0249:                int indent = 0;
0250:                String[] orgsList;
0251:
0252:                if (currDir.isDirectory() == false) {
0253:                    System.out
0254:                            .println("Error: File name specified. Need to specify the name of the directory where the role files are located");
0255:                    System.exit(1);
0256:                }
0257:                try {
0258:                    try {
0259:                        toWriteTo = new OutputStreamWriter(
0260:                                new FileOutputStream(outfile), "UTF-8");
0261:                    } catch (FileNotFoundException fe) {
0262:
0263:                        System.out
0264:                                .println("Is thsi the dire..."
0265:                                        + outfile.substring(0, outfile
0266:                                                .lastIndexOf("/")));
0267:
0268:                        try {
0269:                            File fl1 = new File(outfile.substring(0, outfile
0270:                                    .lastIndexOf("/")));
0271:
0272:                            fl1.mkdirs();
0273:                            toWriteTo = new OutputStreamWriter(
0274:                                    new FileOutputStream(outfile), "UTF-8");
0275:                        } catch (Exception ee) {
0276:                            ee.printStackTrace();
0277:                        }
0278:                        toWriteTo = new OutputStreamWriter(
0279:                                new FileOutputStream(outfile), "UTF-8");
0280:                    }
0281:                    printHeader(toWriteTo);
0282:                    toWriteTo.write("\n<Requests>");
0283:
0284:                    indent++;
0285:                    doIndent(toWriteTo, indent);
0286:                    toWriteTo.write("<OrganizationRequests DN=\"" + rootsuffix
0287:                            + "\">");
0288:                    orgsList = currDir.list();
0289:                    for (int i = 0; i < orgsList.length; ++i) {
0290:                        //System.out.println("Filename:"+orgsList[i]);
0291:                        indent++;
0292:                        doIndent(toWriteTo, indent);
0293:                        WriteRolesToFile(dir + "/" + orgsList[i], toWriteTo);
0294:                    }
0295:                    indent--;
0296:                    doIndent(toWriteTo, indent);
0297:                    toWriteTo.write("</OrganizationRequests>");
0298:                    doIndent(toWriteTo, indent);
0299:                    for (int i = 0; i < orgsList.length; ++i) {
0300:                        //indent++;doIndent(toWriteTo,indent);
0301:                        createRoleTemplates(dir + "/" + orgsList[i], toWriteTo);
0302:                        //indent--;doIndent(toWriteTo,indent);
0303:                    }
0304:                    indent--;
0305:                    doIndent(toWriteTo, indent);
0306:                    toWriteTo.write("</Requests>\n");
0307:                    toWriteTo.close();
0308:                } catch (Exception e) {
0309:                    System.out.println("Error listing the directory!");
0310:                    e.printStackTrace();
0311:                }
0312:                /* catch(IOException ie){
0313:                System.out.println("Error opening file :"+outfile);
0314:                ie.printStackTrace();
0315:                }*/
0316:
0317:            }
0318:
0319:            static void createRoleTemplates(String orgName,
0320:                    OutputStreamWriter toWriteTo) throws Exception {
0321:                Object[] roleList;
0322:                File currOrg;
0323:                int indent;
0324:                String rolename;
0325:
0326:                currOrg = new File(orgName);
0327:
0328:                if (currOrg.isDirectory() == false) {
0329:                    System.out.println("Ignoring " + orgName
0330:                            + ": Not a directory");
0331:                    return;
0332:                }
0333:
0334:                roleList = getRecursiveFilelist(currOrg).toArray();
0335:
0336:                for (int i = 0; i < roleList.length; ++i) {
0337:                    File roleFile = (File) roleList[i];
0338:                    String roleFileName = roleFile.toString();
0339:                    String trueOrgName = orgName.substring(orgName
0340:                            .lastIndexOf("/") + 1, orgName.length());
0341:                    indent = 2;
0342:                    doIndent(toWriteTo, indent);
0343:
0344:                    rolename = roleFileName.substring(roleFileName
0345:                            .lastIndexOf("/") + 1, roleFileName.length() - 4);
0346:
0347:                    toWriteTo
0348:                            .write("<RoleRequests DN=\""
0349:                                    + constructRoleDN(rolename, trueOrgName,
0350:                                            rootsuffix) + "\">");
0351:                    indent++;
0352:                    doIndent(toWriteTo, indent);
0353:                    toWriteTo
0354:                            .write(getCreateServiceTemplate("SunPortalDesktopService"));
0355:                    indent--;
0356:                    doIndent(toWriteTo, indent);
0357:                    toWriteTo.write("</RoleRequests>");
0358:                }
0359:
0360:            }
0361:
0362:            static void WriteRolesToFile(String orgName,
0363:                    OutputStreamWriter toWriteTo) {
0364:                Object[] roleList;
0365:                File currOrg;
0366:                int indent;
0367:                String rolename;
0368:
0369:                currOrg = new File(orgName);
0370:
0371:                if (currOrg.isDirectory() == false) {
0372:                    System.out.println("Ignoring " + orgName
0373:                            + ": Not a directory");
0374:                    return;
0375:                }
0376:
0377:                roleList = getRecursiveFilelist(currOrg).toArray();
0378:                try {
0379:                    for (int i = 0; i < roleList.length; ++i) {
0380:                        File roleFile = (File) roleList[i];
0381:                        String roleFileName = roleFile.toString();
0382:                        String trueOrgName = orgName.substring(orgName
0383:                                .lastIndexOf("/") + 1, orgName.length());
0384:                        indent = 2;
0385:                        doIndent(toWriteTo, indent);
0386:
0387:                        rolename = roleFileName.substring(roleFileName
0388:                                .lastIndexOf("/") + 1,
0389:                                roleFileName.length() - 4);
0390:
0391:                        toWriteTo.write("<CreateRole createDN=\""
0392:                                + constructRoleDN(rolename, trueOrgName)
0393:                                + "\">");
0394:
0395:                        Component comp = GetComponent(roleFileName);
0396:                        comp._compname = rolename;
0397:
0398:                        Privilege tmpPr;
0399:                        Vector tmpValues;
0400:                        Enumeration keys;
0401:                        Hashtable ht = new Hashtable();
0402:                        for (int j = 0; j < (comp._privileges).size(); ++j) {
0403:                            tmpPr = (Privilege) ((comp._privileges)
0404:                                    .elementAt(j));
0405:                            //System.out.println("Name is:"+tmpPr.name);
0406:                            if ((tmpPr.name).startsWith("iwt"))
0407:                                break; // Ignoring attributes as in iwtPlatform
0408:                            // as they don't have equiv in hana...
0409:                            keys = tmpPr._atts.keys();
0410:                            while (keys.hasMoreElements()) {
0411:
0412:                                String key = (String) keys.nextElement();
0413:                                if (Element.mapper.get(key) != null) {
0414:                                    indent++;
0415:                                    doIndent(toWriteTo, indent);
0416:                                    ht.put(tmpPr.name + Element.PRIVPREFIX
0417:                                            + Element.mapper.get(key),
0418:                                            tmpPr._atts.get(key));
0419:                                    toWriteTo.write("<AttributeValuePair>");
0420:                                    indent++;
0421:                                    doIndent(toWriteTo, indent);
0422:                                    toWriteTo.write("<Attribute name=\""
0423:                                            + tmpPr.name + "\"/>");
0424:                                    toWriteTo.write("<Value>");
0425:                                    //tmpValues=(Vector)tmpPr._atts.get(key);
0426:                                    //System.out.println("Size is:"+(tmpPr._atts.get(key)).getClass());
0427:
0428:                                    if (((tmpPr._atts.get(key)).getClass()) == (new String())
0429:                                            .getClass())
0430:                                        toWriteTo.write(tmpPr._atts.get(key)
0431:                                                .toString());
0432:
0433:                                    else {
0434:                                        /* System.out.println((tmpPr._atts.get(key)).getClass());
0435:                                         for(int m=0;m<((Vector)(tmpPr._atts.get(key))).size();++m)
0436:                                        	System.out.print(((Vector)(tmpPr._atts.get(key))).elementAt(m));*/
0437:
0438:                                    }
0439:                                    toWriteTo.write("</Value>");
0440:                                    indent--;
0441:                                    doIndent(toWriteTo, indent);
0442:                                    toWriteTo.write("</AttributeValuePair>");
0443:                                    indent--;
0444:                                    doIndent(toWriteTo, indent);
0445:                                }
0446:                            }
0447:                        }
0448:                        indent--;
0449:                        doIndent(toWriteTo, indent);
0450:                        toWriteTo.write("</CreateRole>");
0451:
0452:                    }
0453:                } catch (Exception e) {
0454:                    e.printStackTrace();
0455:                }
0456:
0457:                return;
0458:            }
0459:
0460:            static void convertAllDomains(String dir, String outfile) {
0461:                File currDir = new File(dir);
0462:                File tmp;
0463:                OutputStreamWriter toWriteTo;
0464:                int indent = 1;
0465:
0466:                String[] orgsList;
0467:                if (currDir.isDirectory() == false) {
0468:                    System.out
0469:                            .println("Error: File name specified. Need to specify the name of the directory where the domain files are located");
0470:                    System.exit(1);
0471:                }
0472:                try {
0473:                    try {
0474:                        toWriteTo = new OutputStreamWriter(
0475:                                new FileOutputStream(outfile), "UTF-8");
0476:                    } catch (FileNotFoundException fe) {
0477:
0478:                        try {
0479:                            File fl1 = new File(outfile.substring(0, outfile
0480:                                    .lastIndexOf("/")));
0481:
0482:                            fl1.mkdirs();
0483:                            toWriteTo = new OutputStreamWriter(
0484:                                    new FileOutputStream(outfile), "UTF-8");
0485:                        } catch (Exception ee) {
0486:                            ee.printStackTrace();
0487:                        }
0488:                        toWriteTo = new OutputStreamWriter(
0489:                                new FileOutputStream(outfile), "UTF-8");
0490:                    }
0491:                    printHeader(toWriteTo);
0492:                    toWriteTo.write("\n<Requests>");
0493:
0494:                    orgsList = currDir.list();
0495:                    for (int i = 0; i < orgsList.length; ++i) {
0496:                        tmp = new File(dir + "/" + orgsList[i]);
0497:                        if (tmp.isDirectory() == true) {
0498:                            System.out.println("Ignoring " + orgsList[i]
0499:                                    + " as it is a directory");
0500:
0501:                        } else {
0502:                            Component comp = GetComponent(dir + "/"
0503:                                    + orgsList[i]);
0504:                            comp._compname = orgsList[i];
0505:                            WriteDomainToFile(toWriteTo, comp, orgsList[i]);
0506:                        }
0507:                    }
0508:                    indent--;
0509:                    doIndent(toWriteTo, indent);
0510:                    toWriteTo.write("</Requests>\n");
0511:                    toWriteTo.close();
0512:                } catch (Exception e) {
0513:                    System.out.println("Error listing the directory!");
0514:                    e.printStackTrace();
0515:                }
0516:            }
0517:
0518:            static void WriteDomainToFile(OutputStreamWriter toWriteTo,
0519:                    Component comp, String orgname) throws Exception {
0520:
0521:                int indent;
0522:
0523:                indent = 1;
0524:                String localOrgname = orgname.substring(0,
0525:                        (orgname.length()) - 4);
0526:
0527:                indent++;
0528:                doIndent(toWriteTo, indent);
0529:                toWriteTo.write("<OrganizationRequests DN=\"" + rootsuffix
0530:                        + "\">");
0531:                indent++;
0532:                doIndent(toWriteTo, indent);
0533:
0534:                toWriteTo.write("<CreateSubOrganization createDN=\""
0535:                        + localOrgname + "\">");
0536:
0537:                /*Attribute tmpAttr;
0538:                Enumeration keys;
0539:                Hashtable ht=new Hashtable();
0540:                for(int i=0; i<(comp._attributes).size();++i){
0541:                	tmpAttr=(Attribute)((comp._attributes).elementAt(i));
0542:                	//System.out.println("Name is:"+tmpAttr.name);
0543:                	if((tmpAttr.name).startsWith("iwt"))
0544:                		 break; // Ignoring attributes as in iwtPlatform
0545:                			// as they don't have equiv in hana...
0546:                	keys= tmpAttr._atts.keys();
0547:                	while (keys.hasMoreElements()) {
0548:                		String key = (String) keys.nextElement();
0549:                		if (Element.mapper.get(key) != null){
0550:                			indent++;doIndent(toWriteTo,indent);
0551:                			ht.put(tmpAttr.name+Element.PRIVPREFIX+Element.mapper.get(key),tmpAttr._atts.get(key));
0552:                			toWriteTo.write("<AttributeValuePair>");
0553:                			indent++;doIndent(toWriteTo,indent);
0554:                			toWriteTo.write("<Attribute name=\""+tmpAttr.name+"\"/>");
0555:                			toWriteTo.write("<Value>");
0556:                			if(((tmpAttr._atts.get(key)).getClass())==(new String()).getClass())
0557:                				toWriteTo.write(tmpAttr._atts.get(key).toString());
0558:                 */
0559:                /*else
0560:                	 for(int k=0;k<(tmpAttr._atts.get(key)).size();++k)
0561:                	tmpAttr._atts.get(key)+"</Value>");	*/
0562:
0563:                /*					toWriteTo.write("</Value>");
0564:                 indent--;doIndent(toWriteTo,indent);
0565:                 toWriteTo.write("</AttributeValuePair>");
0566:                 indent--;doIndent(toWriteTo,indent);
0567:                 }
0568:                 }
0569:                 }*/
0570:                doIndent(toWriteTo, indent);
0571:                toWriteTo.write("</CreateSubOrganization>");
0572:                indent--;
0573:                doIndent(toWriteTo, indent);
0574:                toWriteTo.write("</OrganizationRequests>");
0575:                appendDesktopService(toWriteTo, localOrgname);
0576:
0577:                toWriteTo.write(SetServiceValues.setAuthAttrs(comp,
0578:                        localOrgname, rootsuffix));
0579:                toWriteTo.write(SetServiceValues.setLdapAuthAttrs(hostname,
0580:                        comp, localOrgname, rootsuffix));
0581:                toWriteTo.write(SetServiceValues.setRadiusAuthAttrs(comp,
0582:                        orgname, rootsuffix));
0583:                toWriteTo.write(SetServiceValues.setSafewordAuth(comp, orgname,
0584:                        rootsuffix));
0585:                toWriteTo.write(SetServiceValues.setAnonymousAuth(comp,
0586:                        orgname, rootsuffix));
0587:                toWriteTo.write(SetServiceValues.setAuthMembershipAttrs(comp,
0588:                        orgname, rootsuffix));
0589:                toWriteTo.write(SetServiceValues.setAuthCertAttrs(comp,
0590:                        orgname, rootsuffix));
0591:                toWriteTo.write(SetServiceValues.setAuthUnixAttrs(comp,
0592:                        orgname, rootsuffix));
0593:                toWriteTo.write(SetServiceValues.createAuthAdminModule(orgname,
0594:                        rootsuffix));
0595:                toWriteTo.write(SetServiceValues.setDesktopTypeAttrs(comp,
0596:                        orgname, rootsuffix));
0597:
0598:            }
0599:
0600:            static void appendDesktopService(OutputStreamWriter o, String org)
0601:                    throws IOException {
0602:                int indent;
0603:                int MAX_POSSIBLE_COS = 100;
0604:
0605:                indent = 2;
0606:                doIndent(o, indent);
0607:                o.write("<OrganizationRequests DN=\""
0608:                        + constructOrgDN(org, rootsuffix) + "\">");
0609:                indent++;
0610:                doIndent(o, indent);
0611:                o.write("<RegisterServices>");
0612:                indent++;
0613:                doIndent(o, indent);
0614:                o.write("<Service_Name>SunPortalDesktopService</Service_Name>");
0615:                doIndent(o, indent);
0616:                o.write("<Service_Name>SunPortalNetMailService</Service_Name>");
0617:                doIndent(o, indent);
0618:                o.write("<Service_Name>iPlanetAMAuthService</Service_Name>");
0619:                doIndent(o, indent);
0620:                o.write("<Service_Name>iPlanetAMUserService</Service_Name>");
0621:                indent--;
0622:                doIndent(o, indent);
0623:                o.write("</RegisterServices>");
0624:                indent--;
0625:                doIndent(o, indent);
0626:                o.write("</OrganizationRequests>");
0627:                doIndent(o, indent);
0628:                o.write("<OrganizationRequests DN=\""
0629:                        + constructOrgDN(org, rootsuffix) + "\">");
0630:                indent++;
0631:                doIndent(o, indent);
0632:                o.write(getCreateServiceTemplate("SunPortalDesktopService"));
0633:                indent--;
0634:                doIndent(o, indent);
0635:                o.write("</OrganizationRequests>");
0636:                doIndent(o, indent);
0637:                o.write("<OrganizationRequests DN=\""
0638:                        + constructOrgDN(org, rootsuffix) + "\">");
0639:                indent++;
0640:                doIndent(o, indent);
0641:                o.write(getCreateServiceTemplate("SunPortalNetMailService"));
0642:                indent--;
0643:                doIndent(o, indent);
0644:                o.write("</OrganizationRequests>");
0645:                doIndent(o, indent);
0646:                o.write("<OrganizationRequests DN=\""
0647:                        + constructOrgDN(org, rootsuffix) + "\">");
0648:                indent++;
0649:                doIndent(o, indent);
0650:                o.write(getCreateServiceTemplate("iPlanetAMAuthService"));
0651:                indent--;
0652:                doIndent(o, indent);
0653:                o.write("</OrganizationRequests>");
0654:                doIndent(o, indent);
0655:                o.write("<OrganizationRequests DN=\""
0656:                        + constructOrgDN(org, rootsuffix) + "\">");
0657:                indent++;
0658:                doIndent(o, indent);
0659:                o.write(getCreateServiceTemplate("iPlanetAMUserService"));
0660:                indent--;
0661:                doIndent(o, indent);
0662:                o.write("</OrganizationRequests>");
0663:                doIndent(o, indent);
0664:                //o.write("<RoleRequests DN=\"" + constructRoleDN("ContainerDefaultTemplateRole", org, rootsuffix) + "\">");
0665:                o.write("<OrganizationRequests DN=\""
0666:                        + constructOrgDN(org, rootsuffix) + "\">");
0667:                indent++;
0668:                doIndent(o, indent);
0669:                o
0670:                        .write("<ModifyServiceTemplate serviceName=\"SunPortalDesktopService\" schemaType=\"Dynamic\">");
0671:                indent++;
0672:                doIndent(o, indent);
0673:                o.write("<AttributeValuePair>");
0674:                indent++;
0675:                doIndent(o, indent);
0676:                o
0677:                        .write("<Attribute name=\"sunPortalDesktopDefaultChannelName\"/>");
0678:                doIndent(o, indent);
0679:                o.write("<Value>TemplateTableContainer</Value>");
0680:                indent--;
0681:                doIndent(o, indent);
0682:                o.write("</AttributeValuePair>");
0683:                doIndent(o, indent);
0684:                o.write("<AttributeValuePair>");
0685:                indent++;
0686:                doIndent(o, indent);
0687:                o
0688:                        .write("<Attribute name=\"sunPortalDesktopEditProviderContainerName\"/>");
0689:                doIndent(o, indent);
0690:                o.write("<Value>TemplateEditContainer</Value>");
0691:                indent--;
0692:                doIndent(o, indent);
0693:                o.write("</AttributeValuePair>");
0694:
0695:                //doIndent(o,indent);
0696:                //o.write("<AttributeValuePair>");
0697:                //indent++;doIndent(o,indent);
0698:                //o.write("<Attribute name=\"cospriority\"/>");
0699:                //doIndent(o,indent);
0700:                /* This part of the code generates the cospriority for the DESKTOP SERVICE TEMPLATE.
0701:                The service template of the organization at a higher level in the hierarchy will recieve a greate COS Priority so
0702:                that the user inherits from the suborganization at lower level, which would have lower value of cos priority and
0703:                hence would take precedance. */
0704:
0705:                /*int prev,Idx,orgAtLevel;
0706:                Idx=0;orgAtLevel=0;
0707:                while(Idx < org.length() && org.indexOf(orgNaming,Idx) != -1){
0708:                	orgAtLevel++;
0709:                	prev=Idx;
0710:                	Idx=org.indexOf(orgNaming,prev+1);
0711:                	if(Idx==-1) break;
0712:                }
0713:                o.write("<Value>"+(MAX_POSSIBLE_COS-orgAtLevel)+"</Value>");
0714:                indent--;doIndent(o,indent);
0715:                o.write("</AttributeValuePair>");
0716:                 */
0717:                indent--;
0718:                doIndent(o, indent);
0719:                o.write("</ModifyServiceTemplate>");
0720:                indent--;
0721:                doIndent(o, indent);
0722:                o.write("</OrganizationRequests>");
0723:
0724:                o.write("<OrganizationRequests DN=\""
0725:                        + constructOrgDN(org, rootsuffix) + "\">");
0726:                indent++;
0727:                doIndent(o, indent);
0728:                o
0729:                        .write("<ModifyServiceTemplate serviceName=\"iPlanetAMAuthService\" schemaType=\"Organization\">");
0730:                indent++;
0731:                doIndent(o, indent);
0732:                o.write("<AttributeValuePair>");
0733:                indent++;
0734:                doIndent(o, indent);
0735:                o
0736:                        .write("<Attribute name=\"iplanet-am-auth-login-success-url\"/>");
0737:                //o.write("<Attribute name=\"iplanet-am-success-redirect-url\"/>");
0738:                doIndent(o, indent);
0739:                //o.write("<Value>/portal/dt</Value>");
0740:                o.write("<Value>" + DeployUri + "/dt</Value>");
0741:                indent--;
0742:                doIndent(o, indent);
0743:                o.write("</AttributeValuePair>");
0744:
0745:                doIndent(o, indent);
0746:                o.write("<AttributeValuePair>");
0747:                indent++;
0748:                doIndent(o, indent);
0749:                o.write("<Attribute name=\"iplanet-am-auth-user-container\"/>");
0750:                doIndent(o, indent);
0751:                o.write("<Value>ou=People," + constructOrgDN(org, rootsuffix)
0752:                        + "</Value>");
0753:                indent--;
0754:                doIndent(o, indent);
0755:                o.write("</AttributeValuePair>");
0756:                indent--;
0757:                doIndent(o, indent);
0758:                o.write("</ModifyServiceTemplate>");
0759:                indent--;
0760:                doIndent(o, indent);
0761:                o.write("</OrganizationRequests>");
0762:                doIndent(o, indent);
0763:
0764:                /*	doIndent(o,indent);
0765:                 o.write("<OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
0766:                 indent++;doIndent(o,indent);
0767:                 o.write("<CreatePolicy createDN=\"" + constructOrgDN(org, rootsuffix) + "\">");
0768:                 indent++;doIndent(o,indent);
0769:                 o.write("<Policy name=\"Ability to execute Portal Server Desktop\" serviceName=\"SunPortalDesktopService\">");
0770:                 indent++;doIndent(o,indent);
0771:                 o.write("<Rule name=\"Ability to execute Portal Server Desktop\">");
0772:                 indent++;doIndent(o,indent);
0773:                 o.write("<ServiceName name=\"SunPortalDesktopService\"/>");
0774:                 o.write("<AttributeValuePair>");
0775:                 indent++;doIndent(o,indent);
0776:                 o.write("<Attribute name=\"sunPortalDesktopExecutable\"/>");
0777:                 o.write("<Value>true</Value>");
0778:                 indent--;doIndent(o,indent);
0779:                 o.write("</AttributeValuePair>");
0780:                 indent--;doIndent(o,indent);
0781:                 o.write("</Rule>");
0782:                 indent--;doIndent(o,indent);
0783:                 o.write("</Policy>");
0784:                 o.write("<Policy name=\"Ability to execute Portal Server Netmail\" serviceName=\"SunPortalNetMailService\">");
0785:                 indent++;doIndent(o,indent);
0786:                 o.write("<Rule name=\"Ability to execute Portal Server Netmail\">");
0787:                 indent++;doIndent(o,indent);
0788:                 o.write("<ServiceName name=\"SunPortalNetMailService\"/>");
0789:                 o.write("<AttributeValuePair>");
0790:                 indent++;doIndent(o,indent);
0791:                 o.write("<Attribute name=\"sunPortalNetmailExecutable\"/>");
0792:                 o.write("<Value>true</Value>");
0793:                 indent--;doIndent(o,indent);
0794:                 o.write("</AttributeValuePair>");
0795:                 indent--;doIndent(o,indent);
0796:                 o.write("</Rule>");
0797:                 indent--;doIndent(o,indent);
0798:                 o.write("</Policy>");
0799:                 indent--;doIndent(o,indent);
0800:                 o.write("</CreatePolicy>");
0801:                 indent--;doIndent(o,indent);
0802:                 o.write("</OrganizationRequests>");doIndent(o,indent);
0803:                 o.write("<OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
0804:                 indent++;doIndent(o,indent);
0805:                 o.write("<AssignPolicy policyDN=\"" + constructOrgDN(org, rootsuffix) + "\">");
0806:                 indent++;doIndent(o,indent);
0807:                 o.write("<PolicyName name=\"Ability to execute Portal Server Desktop\"/>");
0808:                 doIndent(o,indent);
0809:                 o.write("<PolicyName name=\"Ability to execute Portal Server Netmail\"/>");
0810:                 indent--;doIndent(o,indent);
0811:                 o.write("</AssignPolicy>");
0812:                 indent--;doIndent(o,indent);
0813:                 o.write("</OrganizationRequests>");
0814:                 */
0815:                doIndent(o, indent);
0816:                o.write("<!--OrganizationRequests DN=\""
0817:                        + constructOrgDN(org, rootsuffix) + "\">");
0818:                indent++;
0819:                doIndent(o, indent);
0820:                o.write("<CreatePolicy createDN=\""
0821:                        + constructOrgDN(org, rootsuffix) + "\">");
0822:                indent++;
0823:                doIndent(o, indent);
0824:                o
0825:                        .write("<Policy name=\"Ability to execute Portal Server Desktop\" referralPolicy=\"false\">");
0826:                indent++;
0827:                doIndent(o, indent);
0828:                o.write("<Rule name=\"ExecuteDesktop\">");
0829:                indent++;
0830:                doIndent(o, indent);
0831:                o.write("<ServiceName name=\"SunPortalDesktopService\"/>");
0832:                o.write("<AttributeValuePair>");
0833:                indent++;
0834:                doIndent(o, indent);
0835:                o.write("<Attribute name=\"sunPortalDesktopExecutable\"/>");
0836:                o.write("<Value>true</Value>");
0837:                indent--;
0838:                doIndent(o, indent);
0839:                o.write("</AttributeValuePair>");
0840:                indent--;
0841:                doIndent(o, indent);
0842:                o.write("</Rule>");
0843:                doIndent(o, indent);
0844:                o.write("<Subjects name=\"OrgExecDesktop\" description=\"\">");
0845:                indent++;
0846:                doIndent(o, indent);
0847:                o
0848:                        .write("<Subject name=\"OrgExecuteDesktop\" type=\"Organization\">");
0849:                indent++;
0850:                doIndent(o, indent);
0851:                o.write("<AttributeValuePair>");
0852:                indent++;
0853:                doIndent(o, indent);
0854:                o.write("<Attribute name=\"Values\"/>");
0855:                doIndent(o, indent);
0856:                o.write("<Value>" + constructOrgDN(org, rootsuffix)
0857:                        + "</Value>");
0858:                indent--;
0859:                doIndent(o, indent);
0860:                o.write("</AttributeValuePair>");
0861:                indent--;
0862:                doIndent(o, indent);
0863:                o.write("</Subject>");
0864:                indent--;
0865:                doIndent(o, indent);
0866:                o.write("</Subjects>");
0867:                indent--;
0868:                doIndent(o, indent);
0869:                o.write("</Policy>");
0870:                o
0871:                        .write("<Policy name=\"Ability to execute Portal Server Netmail\" referralPolicy=\"false\">");
0872:                indent++;
0873:                doIndent(o, indent);
0874:                o.write("<Rule name=\"ExecuteNetmail\">");
0875:                indent++;
0876:                doIndent(o, indent);
0877:                o.write("<ServiceName name=\"SunPortalNetMailService\"/>");
0878:                o.write("<AttributeValuePair>");
0879:                indent++;
0880:                doIndent(o, indent);
0881:                o.write("<Attribute name=\"sunPortalNetmailExecutable\"/>");
0882:                o.write("<Value>true</Value>");
0883:                indent--;
0884:                doIndent(o, indent);
0885:                o.write("</AttributeValuePair>");
0886:                indent--;
0887:                doIndent(o, indent);
0888:                o.write("</Rule>");
0889:                doIndent(o, indent);
0890:                o.write("<Subjects name=\"OrgExecNetmail\" description=\"\">");
0891:                indent++;
0892:                doIndent(o, indent);
0893:                o
0894:                        .write("<Subject name=\"OrgExecuteNetmail\" type=\"Organization\">");
0895:                indent++;
0896:                doIndent(o, indent);
0897:                o.write("<AttributeValuePair>");
0898:                indent++;
0899:                doIndent(o, indent);
0900:                o.write("<Attribute name=\"Values\"/>");
0901:                doIndent(o, indent);
0902:                o.write("<Value>" + constructOrgDN(org, rootsuffix)
0903:                        + "</Value>");
0904:                indent--;
0905:                doIndent(o, indent);
0906:                o.write("</AttributeValuePair>");
0907:                indent--;
0908:                doIndent(o, indent);
0909:                o.write("</Subject>");
0910:                indent--;
0911:                doIndent(o, indent);
0912:                o.write("</Subjects>");
0913:                indent--;
0914:                doIndent(o, indent);
0915:                o.write("</Policy>");
0916:                indent--;
0917:                doIndent(o, indent);
0918:                o.write("</CreatePolicy>");
0919:                indent--;
0920:                doIndent(o, indent);
0921:                o.write("</OrganizationRequests-->");
0922:                doIndent(o, indent);
0923:                o.write("<!--OrganizationRequests DN=\""
0924:                        + constructOrgDN(org, rootsuffix) + "\">");
0925:                indent++;
0926:                doIndent(o, indent);
0927:                o.write("<AssignPolicy policyDN=\""
0928:                        + constructOrgDN(org, rootsuffix) + "\">");
0929:                indent++;
0930:                doIndent(o, indent);
0931:                o
0932:                        .write("<PolicyName name=\"Ability to execute Portal Server Desktop\"/>");
0933:                doIndent(o, indent);
0934:                o
0935:                        .write("<PolicyName name=\"Ability to execute Portal Server Netmail\"/>");
0936:                indent--;
0937:                doIndent(o, indent);
0938:                o.write("</AssignPolicy>");
0939:                indent--;
0940:                doIndent(o, indent);
0941:                o.write("</OrganizationRequests-->");
0942:            }
0943:
0944:            static void WriteDomain(String outfile, String orgname,
0945:                    Component comp) {
0946:
0947:                int indent = 0;
0948:
0949:                OutputStreamWriter toWriteTo;
0950:
0951:                try {
0952:                    toWriteTo = new OutputStreamWriter(new FileOutputStream(
0953:                            outfile), "UTF-8");
0954:                    printHeader(toWriteTo);
0955:                    toWriteTo.write("\n<Requests>");
0956:
0957:                    indent++;
0958:                    doIndent(toWriteTo, indent);
0959:                    toWriteTo.write("<OrganizationRequests DN=\"" + rootsuffix
0960:                            + "\">");//"+parent+"\">");
0961:                    indent++;
0962:                    doIndent(toWriteTo, indent);
0963:                    toWriteTo.write("<CreateSubOrganization createDN=\""
0964:                            + orgname + "\">");
0965:
0966:                    Attribute tmpAttr;
0967:                    Enumeration keys;
0968:                    Hashtable ht = new Hashtable();
0969:                    /*for(int i=0; i<(comp._attributes).size();++i){
0970:                    	indent++;
0971:                    	tmpAttr=(Attribute)((comp._attributes).elementAt(i));
0972:                    	//System.out.println("key:"+tmpAttr.name);
0973:                    	if((tmpAttr.name).startsWith("iwt")) break; // Ignoring attributes as in iwtPlatform
0974:                    						// as they don't have equiv in hana...
0975:
0976:                    	keys= tmpAttr._atts.keys();
0977:                    	while (keys.hasMoreElements()) {
0978:                    		String key = (String) keys.nextElement();
0979:
0980:                    		if (Element.mapper.get(key) != null){
0981:                    			indent++;doIndent(toWriteTo,indent);
0982:                    			ht.put(tmpAttr.name+Element.PRIVPREFIX+Element.mapper.get(key),tmpAttr._atts.get(key));
0983:                    			toWriteTo.write("<AttributeValuePair>");
0984:                    			indent++;doIndent(toWriteTo,indent);
0985:                    			toWriteTo.write("<Attribute name=\""+tmpAttr.name+"\"/>");
0986:                    			toWriteTo.write("<Value>");
0987:                    			if(((tmpAttr._atts.get(key)).getClass())==(new String()).getClass())
0988:                    				toWriteTo.write(tmpAttr._atts.get(key).toString());
0989:                     */
0990:                    /*else
0991:                    	 for(int k=0;k<(tmpAttr._atts.get(key)).size();++k)
0992:                    	tmpAttr._atts.get(key)+"</Value>");	*/
0993:
0994:                    /*					toWriteTo.write("</Value>");
0995:                     indent--;doIndent(toWriteTo,indent);
0996:                     toWriteTo.write("</AttributeValuePair>");
0997:                     indent--;doIndent(toWriteTo,indent);
0998:                     }
0999:                     }
1000:                     }
1001:                     indent--;doIndent(toWriteTo,indent);*/
1002:                    toWriteTo.write("</CreateSubOrganization>");
1003:                    indent--;
1004:                    doIndent(toWriteTo, indent);
1005:                    toWriteTo.write("</OrganizationRequests>");
1006:                    appendDesktopService(toWriteTo, orgname);
1007:                    toWriteTo.write(SetServiceValues.setAuthAttrs(comp,
1008:                            orgname, rootsuffix));
1009:                    toWriteTo.write(SetServiceValues.setLdapAuthAttrs(hostname,
1010:                            comp, orgname, rootsuffix));
1011:                    toWriteTo.write(SetServiceValues.setRadiusAuthAttrs(comp,
1012:                            orgname, rootsuffix));
1013:                    toWriteTo.write(SetServiceValues.setSafewordAuth(comp,
1014:                            orgname, rootsuffix));
1015:                    toWriteTo.write(SetServiceValues.setAnonymousAuth(comp,
1016:                            orgname, rootsuffix));
1017:                    toWriteTo.write(SetServiceValues.setAuthMembershipAttrs(
1018:                            comp, orgname, rootsuffix));
1019:                    toWriteTo.write(SetServiceValues.setAuthCertAttrs(comp,
1020:                            orgname, rootsuffix));
1021:                    toWriteTo.write(SetServiceValues.setAuthUnixAttrs(comp,
1022:                            orgname, rootsuffix));
1023:                    toWriteTo.write(SetServiceValues.createAuthAdminModule(
1024:                            orgname, rootsuffix));
1025:                    toWriteTo.write(SetServiceValues.setDesktopTypeAttrs(comp,
1026:                            orgname, rootsuffix));
1027:
1028:                    indent--;
1029:                    doIndent(toWriteTo, indent);
1030:                    toWriteTo.write("</Requests>\n");
1031:                    toWriteTo.close();
1032:                } catch (IOException ie) {
1033:                    System.out.println("Error opening file:" + outfile);
1034:                    ie.printStackTrace();
1035:
1036:                }
1037:
1038:            }
1039:
1040:            public static Component GetComponent(String filename)
1041:                    throws Exception {
1042:                WebtopParser wp = new WebtopParser();
1043:                wp.register(Element.COMPONENT_E,
1044:                        "migration.modules.ldap.Component");
1045:
1046:                wp.register(Element.ATT_E, "migration.modules.ldap.Attribute");
1047:                wp.register(Element.PRIV_E, "migration.modules.ldap.Privilege");
1048:                wp.register(Element.VALUELIST, "migration.modules.ldap.List");
1049:                wp.register(Element.DENYLIST, "migration.modules.ldap.List");
1050:                wp.register(Element.ALLOWLIST, "migration.modules.ldap.List");
1051:                wp.register(Element.CHOICEVALUE, "migration.modules.ldap.List");
1052:                wp.register(Element.READPERM, "migration.modules.ldap.List");
1053:                wp.register(Element.WRITEPERM, "migration.modules.ldap.List");
1054:                wp.register(Element.VALUELISTN, "migration.modules.ldap.List");
1055:                wp.register(Element.DENYLISTN, "migration.modules.ldap.List");
1056:                wp.register(Element.ALLOWLISTN, "migration.modules.ldap.List");
1057:                wp
1058:                        .register(Element.CHOICEVALUEN,
1059:                                "migration.modules.ldap.List");
1060:                wp.register(Element.READPERMN, "migration.modules.ldap.List");
1061:                wp.register(Element.WRITEPERMN, "migration.modules.ldap.List");
1062:                wp.register("Component", "com.sun.portal.psadmin.AppComponent");
1063:                wp.register("Attributes",
1064:                        "com.iplanet.portalserver.parser.GenericNode");
1065:                wp.register("Privileges",
1066:                        "com.iplanet.portalserver.parser.GenericNode");
1067:                wp.register("Attribute", "com.sun.portal.psadmin.AppAttribute");
1068:                wp.register("Privilege", "com.sun.portal.psadmin.AppPrivilege");
1069:                return (Component) wp.parse(createTmpWithComponent(filename));
1070:            }
1071:
1072:            static void WriteToFile(String outfile, String rolename,
1073:                    String parent, Component comp) {
1074:
1075:                int indent = 0;
1076:
1077:                try {
1078:                    OutputStreamWriter toWriteTo = new OutputStreamWriter(
1079:                            new FileOutputStream(outfile), "UTF-8");
1080:
1081:                    printHeader(toWriteTo);
1082:                    toWriteTo.write("\n<Requests>");
1083:
1084:                    indent++;
1085:                    doIndent(toWriteTo, indent);
1086:                    toWriteTo.write("<OrganizationRequests DN=\"" + rootsuffix
1087:                            + "\">");
1088:                    indent++;
1089:                    doIndent(toWriteTo, indent);
1090:                    toWriteTo.write("<CreateRole createDN=\"" + rolename + ","
1091:                            + orgNaming + parent + "\">");
1092:                    toWriteTo.write("</CreateRole>");
1093:                    indent--;
1094:                    doIndent(toWriteTo, indent);
1095:                    toWriteTo.write("</OrganizationRequests>");
1096:                    indent--;
1097:                    doIndent(toWriteTo, indent);
1098:                    toWriteTo.write("</Requests>\n");
1099:
1100:                    toWriteTo.close();
1101:
1102:                } catch (IOException ie) {
1103:                    System.out.println("Error opening file:" + outfile);
1104:                    ie.printStackTrace();
1105:
1106:                }
1107:            }
1108:
1109:            public static void printHeader(OutputStreamWriter fw)
1110:                    throws IOException {
1111:
1112:                if (System.getProperty("DEPLOY_URI") != null)
1113:                    DeployUri = System.getProperty("DEPLOY_URI");
1114:
1115:                fw.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
1116:                fw
1117:                        .write("\n<!--  PROPRIETARY/CONFIDENTIAL/ Use of this product is subject");
1118:                fw
1119:                        .write("\n to license terms. Copyright 2001 Sun Microsystems Inc.");
1120:                fw.write("Some preexisting portions Copyright 2001 Netscape");
1121:                fw.write("Communications Corp. All rights reserved. -->");
1122:                fw
1123:                        .write("\n<!DOCTYPE Requests PUBLIC \"-//Sun ONE//iDSAME 5.0 Admin CLI DTD//EN \" ");
1124:                fw.write("\"file:" + IDSAMEBaseDir + "/dtd/amAdmin.dtd\">");
1125:
1126:                return;
1127:            }
1128:
1129:            static void doIndent(OutputStreamWriter fw, int count)
1130:                    throws IOException {
1131:
1132:                fw.write("\n");
1133:                for (int i = 0; i < count; ++i)
1134:                    fw.write("  ");
1135:            }
1136:
1137:            static FileInputStream createTmpWithComponent(String infile)
1138:                    throws Exception {
1139:                try {
1140:                    FileInputStream in = new FileInputStream(infile);
1141:                    File tmp = File.createTempFile("wt1234", "xml", new File(
1142:                            "/tmp"));
1143:                    tmp.deleteOnExit();
1144:                    FileOutputStream out = new FileOutputStream(tmp);
1145:                    String compstuff = "<iwt:Component name=\"" + infile
1146:                            + "\" >\n";
1147:                    out.write(compstuff.getBytes());
1148:                    byte[] bb = new byte[100];
1149:                    int len = 0;
1150:                    while ((len = in.read(bb)) != -1) {
1151:                        out.write(bb, 0, len);
1152:                    }
1153:                    compstuff = "</iwt:Component>\n";
1154:                    out.write("</iwt:Component>".getBytes());
1155:                    in.close();
1156:                    out.flush();
1157:                    out.close();
1158:                    return new FileInputStream(tmp);
1159:                } catch (Exception e) {
1160:                    throw (e);
1161:                }
1162:            }
1163:
1164:            /* Returns a vector of File objects which are all the files under the directory
1165:             passed into the method. */
1166:            static Vector getRecursiveFilelist(File directory) {
1167:                Vector returnList = new Vector();
1168:                try {
1169:                    File[] currentList = directory.listFiles();
1170:                    for (int i = 0; i < currentList.length; i++) {
1171:                        if (currentList[i].isDirectory() == true) {
1172:                            //            System.out.println("Getting recursive directory "+currentList[i].toString());
1173:                            returnList
1174:                                    .addAll(getRecursiveFilelist(currentList[i]));
1175:                        } else if (currentList[i].isFile()) {
1176:                            //            System.out.println("Adding file "+currentList[i].toString());
1177:                            returnList.add(currentList[i]);
1178:                        } else {
1179:                            //            System.out.println("Unknown item "+currentList[i].toString());
1180:                        }
1181:                    }
1182:
1183:                } catch (SecurityException se) {
1184:                    System.err.println("Unable to access directory within "
1185:                            + directory.toString() + "\n");
1186:                    se.printStackTrace();
1187:                }
1188:                return returnList;
1189:            }
1190:
1191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.