Source Code Cross Referenced for UnixUsers.java in  » Installer » IzPack » com » izforge » izpack » util » os » unix » 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 » Installer » IzPack » com.izforge.izpack.util.os.unix 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003:         *
004:         * http://izpack.org/
005:         * http://izpack.codehaus.org/
006:         *
007:         * Copyright 2006 Marc Eppelmann@reddot.de
008:         *
009:         * Licensed under the Apache License, Version 2.0 (the "License");
010:         * you may not use this file except in compliance with the License.
011:         * You may obtain a copy of the License at
012:         *
013:         *     http://www.apache.org/licenses/LICENSE-2.0
014:         *
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         */
021:        package com.izforge.izpack.util.os.unix;
022:
023:        import com.izforge.izpack.util.StringTool;
024:
025:        import java.io.File;
026:
027:        import java.util.ArrayList;
028:
029:        /**
030:         * Unix Users Collection Class and related static Helper Methods
031:         * 
032:         * @author marc.eppelmann@reddot.de
033:         */
034:        public class UnixUsers extends ArrayList {
035:
036:            // ~ Static fields/initializers *********************************************************
037:
038:            /** serialVersionUID = -4804842346742194981L; */
039:            private static final long serialVersionUID = -4804842346742194981L;
040:
041:            // ~ Constructors ***********************************************************************
042:
043:            /**
044:             * Creates a new UnixUsers object.
045:             */
046:            public UnixUsers() {
047:                fromUsersArrayList(getEtcPasswdUsersAsArrayList());
048:                fromUsersArrayList(getYpPasswdUsersAsArrayList());
049:            }
050:
051:            // ~ Methods ****************************************************************************
052:            /**
053:             * Gets all known users with valid shells
054:             * 
055:             * @return an UnixUsers arraylist of these users
056:             */
057:            public ArrayList<UnixUser> getUsersWithValidShells() {
058:                ArrayList<UnixUser> result = new ArrayList<UnixUser>();
059:
060:                for (int idx = 0; idx < size(); idx++) {
061:                    UnixUser user = (UnixUser) get(idx);
062:
063:                    if ((user.getShell() != null)
064:                            && user.getShell().trim().endsWith("sh")) {
065:                        result.add(user);
066:                    }
067:                }
068:
069:                return result;
070:            }
071:
072:            /**
073:             * Gets all known users with valid shells and really existing (not dummy) Homefolders.
074:             * 
075:             * @return an UnixUsers Arraylist of these users
076:             */
077:            public ArrayList<UnixUser> getUsersWithValidShellsAndExistingHomes() {
078:                ArrayList<UnixUser> result = new ArrayList<UnixUser>();
079:
080:                ArrayList<UnixUser> usersWithValidShells = getUsersWithValidShells();
081:
082:                for (int idx = 0; idx < usersWithValidShells.size(); idx++) {
083:                    UnixUser user = usersWithValidShells.get(idx);
084:
085:                    if ((user.getHome() != null)
086:                            && new File(user.getHome().trim()).exists()) {
087:                        result.add(user);
088:                    }
089:                }
090:
091:                return result;
092:            }
093:
094:            /**
095:             * Gets all known users with valid shells and really existing (not dummy) Home And!
096:             * freedesktop.org/RFC-based "Desktop" folders.
097:             * 
098:             * @return an UnixUsers Arraylist of these users
099:             */
100:            public ArrayList _getUsersWithValidShellsExistingHomesAndDesktops() {
101:                ArrayList result = new ArrayList();
102:
103:                ArrayList<UnixUser> usersWithValidShellsAndExistingHomes = getUsersWithValidShellsAndExistingHomes();
104:
105:                for (int idx = 0; idx < usersWithValidShellsAndExistingHomes
106:                        .size(); idx++) {
107:                    UnixUser user = usersWithValidShellsAndExistingHomes
108:                            .get(idx);
109:
110:                    if ((user.getHome() != null)
111:                            && new File(user.getHome().trim() + File.separator
112:                                    + "Desktop").exists()) {
113:                        result.add(user);
114:                    }
115:                }
116:
117:                return result;
118:            }
119:
120:            /**
121:             * An StringArray of the existing Desktop folders of all valid users.
122:             * 
123:             * @return the Stringlist of ValidUsersDesktopFolders
124:             */
125:            public ArrayList<String> getValidUsersDesktopFolders() {
126:                ArrayList<String> result = new ArrayList<String>();
127:
128:                ArrayList validUserDesktops = getUsersWithValidShellsExistingHomesAndDesktops();
129:
130:                for (int idx = 0; idx < validUserDesktops.size(); idx++) {
131:                    UnixUser user = (UnixUser) validUserDesktops.get(idx);
132:                    new File(user.getHome().trim() + File.separator + "Desktop");
133:
134:                    if (user.getHome() != null) {
135:                        File DesktopFolder = new File(user.getHome().trim()
136:                                + File.separator + "Desktop");
137:
138:                        if (DesktopFolder.exists()
139:                                && DesktopFolder.isDirectory()) {
140:                            result.add(DesktopFolder.toString());
141:                        }
142:                    }
143:                }
144:
145:                return result;
146:            }
147:
148:            /**
149:             * Gets all known users with valid shells and really existing (not dummy) Home And!
150:             * freedesktop.org/RFC-based "Desktop" folders.
151:             * 
152:             * @return an UnixUsers Arraylist of these users
153:             */
154:            public static ArrayList getUsersWithValidShellsExistingHomesAndDesktops() {
155:                UnixUsers users = new UnixUsers();
156:
157:                return users._getUsersWithValidShellsExistingHomesAndDesktops();
158:            }
159:
160:            /**
161:             * Builds the internal Array from the given UsersArrayList
162:             * 
163:             * @param anUsersArrayList an Users ArrayList reded from /etc/passwd
164:             */
165:            private void fromUsersArrayList(ArrayList<String> anUsersArrayList) {
166:                for (int idx = 0; idx < anUsersArrayList.size(); idx++) {
167:                    add(new UnixUser().fromEtcPasswdLine(anUsersArrayList
168:                            .get(idx)));
169:                }
170:            }
171:
172:            /**
173:             * Gets all Users from /etc/passwd as StringList
174:             * 
175:             * @return the UserNames extracted from the getEtcPasswdArray()
176:             */
177:            public static ArrayList<String> getEtcPasswdUsersAsArrayList() {
178:                ArrayList<String> result = new ArrayList<String>();
179:                ArrayList<String> etcPasswdArray = UnixHelper
180:                        .getEtcPasswdArray();
181:
182:                for (int idx = 0; idx < etcPasswdArray.size(); idx++) {
183:                    String line = etcPasswdArray.get(idx);
184:                    result.add(line);
185:                }
186:
187:                return result;
188:            }
189:
190:            /**
191:             * Gets all Users from /etc/passwd as StringList
192:             * 
193:             * @return the UserNames extracted from the getEtcPasswdArray()
194:             */
195:            public static ArrayList<String> getYpPasswdUsersAsArrayList() {
196:                return UnixHelper.getYpPasswdArray();
197:            }
198:
199:            /**
200:             * Returns all Users as ColonSeparated String
201:             * 
202:             * @return "asterisk:at:avahi:beagleindex:bin:daemon:dhcpd:ftp:games:gdm:haldaemon:icecream:irc:ldap:lp:mail:mailman:man:...."
203:             */
204:            public static String getUsersColonString() {
205:                ArrayList<String> usersArrayList = getEtcPasswdUsersAsArrayList();
206:
207:                String retValue = "";
208:
209:                for (int user = 0; user < usersArrayList.size(); user++) {
210:                    String userline = usersArrayList.get(user);
211:                    retValue += (userline.substring(0, userline.indexOf(":")) + ":");
212:                }
213:
214:                if (retValue.endsWith(":")) {
215:                    retValue = retValue.substring(0, retValue.length() - 1);
216:                }
217:
218:                return retValue;
219:            }
220:
221:            /**
222:             * Test main Method
223:             * 
224:             * @param args from Commandline
225:             */
226:            public static void main(String[] args) {
227:                System.out.println("UnixUsers:");
228:
229:                UnixUsers users = new UnixUsers();
230:
231:                // users.fromUsersArrayList();
232:                for (int idx = 0; idx < users.size(); idx++) {
233:                    System.out.println(((UnixUser) users.get(idx)).getName());
234:                }
235:
236:                System.out
237:                        .println(StringTool
238:                                .stringArrayListToString(getUsersWithValidShellsExistingHomesAndDesktops()));
239:
240:                // getUsersWithValidShellsAndExistingHomes();
241:            }
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.