Source Code Cross Referenced for Utility.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » channels » groupsmanager » 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 » uPortal_rel 2 6 1 GA » org.jasig.portal.channels.groupsmanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2001 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.channels.groupsmanager;
007:
008:        import java.io.StringWriter;
009:        import java.util.Iterator;
010:
011:        import org.apache.commons.logging.Log;
012:        import org.apache.commons.logging.LogFactory;
013:
014:        import org.jasig.portal.groups.IEntityGroup;
015:        import org.jasig.portal.groups.IGroupMember;
016:        import org.w3c.dom.Document;
017:        import org.w3c.dom.Element;
018:
019:        import org.apache.xml.serialize.OutputFormat;
020:        import org.apache.xml.serialize.XMLSerializer;
021:
022:        /**
023:         * A class holding utility functions used by the Groups Manager channel.
024:         * @author Don Fracapane
025:         * @version $Revision: 36729 $
026:         */
027:        public class Utility implements  GroupsManagerConstants {
028:
029:            private static final Log log = LogFactory.getLog(Utility.class);
030:
031:            /** Creates new Utility */
032:            public Utility() {
033:            }
034:
035:            /**
036:             * Compares 2 strings to determine if they are functionally the same. For this
037:             * method null is the same as "".
038:             * @param one String
039:             * @param two String
040:             * @return an <code>boolean</code> object
041:             */
042:            public static boolean areEqual(String one, String two) {
043:                String str1 = (one == null ? "" : one).trim();
044:                String str2 = (two == null ? "" : two).trim();
045:                return str1.equals(str2);
046:            }
047:
048:            /**
049:             * Answers if testString has a value other that null and "".
050:             * @param aString String
051:             * @return an <code>boolean</code> object
052:             */
053:            public static boolean notEmpty(String aString) {
054:                String testString = (aString == null ? "" : aString).trim();
055:                return !testString.equals("");
056:            }
057:
058:            /**
059:             * This method will prints to the log when an exception is not passed.
060:             * @param msgTypeStr String
061:             * @param msg String
062:             */
063:            public static void logMessage(String msgTypeStr, String msg) {
064:                Utility.logMessage(msgTypeStr, msg, null);
065:                return;
066:            }
067:
068:            /**
069:             * An attempt to extract all calls to logger to expedite assumed future upgrades.
070:             * @param msgTypeStr String
071:             * @param msg String
072:             * @param th Throwable
073:             */
074:            public static void logMessage(String msgTypeStr, String msg,
075:                    Throwable th) {
076:
077:                if (msgTypeStr != null && msgTypeStr.equals("ERROR"))
078:                    log.error(msg, th);
079:                else if (msgTypeStr != null && msgTypeStr.equals("WARN"))
080:                    log.warn(msg, th);
081:                else if (msgTypeStr != null && msgTypeStr.equals("INFO"))
082:                    log.info(msg, th);
083:                else if (msgTypeStr != null && msgTypeStr.equals("FATAL"))
084:                    log.fatal(msg, th);
085:                else
086:                    log.debug(msg, th);
087:
088:                return;
089:            }
090:
091:            /**
092:             * Extracts the value of a key sandwiched by delimiters from a string.
093:             * @param fromDelim
094:             * @param source
095:             * @param toDelim
096:             * @return an <code>String</code> object
097:             */
098:            public static String parseStringDelimitedBy(String fromDelim,
099:                    String source, String toDelim) {
100:                Utility.logMessage("DEBUG",
101:                        "Utility::parseStringDelimitedBy(): fromDelim = "
102:                                + fromDelim + " source = " + source
103:                                + " toDelim = " + toDelim);
104:                String parsedString = null;
105:                String tagString = null;
106:                int idxFrom = source.indexOf(fromDelim);
107:                int idxTo;
108:                //Utility.logMessage("DEBUG", "Utility::parseStringDelimitedBy(): idxFrom = " + idxFrom);
109:                if (idxFrom > -1) {
110:                    tagString = source.substring(idxFrom);
111:                    //Utility.logMessage("DEBUG", "Utility::parseStringDelimitedBy(): tagString = " + tagString);
112:                    idxTo = tagString.indexOf(toDelim);
113:                    if (idxTo < 0) {
114:                        parsedString = tagString.substring(fromDelim.length());
115:                    } else {
116:                        parsedString = tagString.substring(fromDelim.length(),
117:                                tagString.indexOf(toDelim));
118:                    }
119:                }
120:                Utility.logMessage("DEBUG",
121:                        "Utility::parseStringDelimitedBy(): Returning parsedString = "
122:                                + parsedString);
123:                return parsedString;
124:            }
125:
126:            /**
127:             * Prints a Document. Used for debugging.
128:             * @param aDoc
129:             * @param aMessage
130:             */
131:            public static void printDoc(Document aDoc, String aMessage) {
132:                String aMsg = (aMessage != null ? aMessage : "");
133:                try {
134:                    Utility.logMessage("DEBUG",
135:                            "****************************************");
136:                    Utility.logMessage("DEBUG", aMsg + "\n" + toString(aDoc));
137:                    Utility.logMessage("DEBUG",
138:                            "########################################");
139:                } catch (Exception e) {
140:                    Utility.logMessage("ERROR", e.toString(), e);
141:                }
142:                return;
143:            }
144:
145:            /**
146:             * Prints an Element. Used for debugging.
147:             * @param anElem
148:             * @param aMessage
149:             */
150:            public static void printElement(Element anElem, String aMessage) {
151:                Document prtDoc = GroupsManagerXML.getNewDocument();
152:                //org.w3c.dom.Node cpy = anElem.cloneNode(true);
153:                //prtDoc.adoptNode(cpy);
154:                Element cpy = (Element) prtDoc.importNode(anElem, true);
155:                prtDoc.appendChild(cpy);
156:                Utility.printDoc(prtDoc, aMessage);
157:                return;
158:            }
159:
160:            /**
161:             * Retrieves a Group Member for the provided key and of the provided type.
162:             * @param key
163:             * @param type
164:             * @return an <code>IGroupMember</code> object
165:             */
166:            public static IGroupMember retrieveGroupMemberForKeyAndType(
167:                    String key, String type) {
168:                IGroupMember gm = null;
169:
170:                if (type.equals(GROUP_CLASSNAME)) {
171:                    gm = GroupsManagerXML.retrieveGroup(key);
172:                    Utility.logMessage("DEBUG",
173:                            "Utility::retrieveGroupMemberForKeyAndType(): Retrieved group for Type: = "
174:                                    + type + " and key: " + key);
175:                } else {
176:                    gm = GroupsManagerXML.retrieveEntity(key, type);
177:                    Utility.logMessage("DEBUG",
178:                            "Utility::retrieveGroupMemberForKeyAndType(): Retrieved entity for Type: = "
179:                                    + type + " and key: " + key);
180:                }
181:                return gm;
182:            }
183:
184:            /**
185:             * Represents a document as a string.
186:             * @param aDoc
187:             * @return the document serialized out as a human-readable String
188:             */
189:            public static String toString(Document aDoc) {
190:                StringWriter sw = new StringWriter();
191:                try {
192:                    /* TODO: This should be reviewed at some point to see if we can use the
193:                     * DOM3 LS capability and hence a standard way of doing this rather
194:                     * than using an internal implementation class.
195:                     */
196:                    OutputFormat format = new OutputFormat();
197:                    format.setOmitXMLDeclaration(true);
198:                    format.setIndenting(true);
199:                    XMLSerializer serial = new XMLSerializer(sw, format);
200:                    serial.serialize(aDoc);
201:                } catch (Exception e) {
202:                    Utility.logMessage("ERROR", "Utility::asString(): " + e, e);
203:                }
204:                return sw.toString();
205:            }
206:
207:            /**
208:             * given a group key, return an xml group id that matches it in the provided document
209:             *
210:             * @param grpKey String
211:             * @param sd CGroupsManagerUnrestrictedSessionData
212:             * @return an <code>String</code> object
213:             */
214:            public static String translateKeytoID(String grpKey,
215:                    CGroupsManagerUnrestrictedSessionData sd) {
216:                Document viewDoc = sd.model;
217:                String id = null;
218:                Element grpViewKeyElem;
219:                Iterator grpItr = GroupsManagerXML.getNodesByTagNameAndKey(
220:                        viewDoc, GROUP_TAGNAME, grpKey);
221:                IEntityGroup gm = GroupsManagerXML.retrieveGroup(grpKey);
222:                if (gm != null) {
223:                    if (!grpItr.hasNext()) {
224:                        grpViewKeyElem = GroupsManagerXML.getGroupMemberXml(gm,
225:                                true, null, sd);
226:                        Element rootElem = viewDoc.getDocumentElement();
227:                        rootElem.appendChild(grpViewKeyElem);
228:                    } else {
229:                        grpViewKeyElem = (Element) grpItr.next();
230:                        GroupsManagerXML.getGroupMemberXml(gm, true,
231:                                grpViewKeyElem, sd);
232:                    }
233:                    id = grpViewKeyElem.getAttribute("id");
234:                }
235:                return id;
236:            }
237:
238:            /**
239:             * Determines if an object has a value other than null or blank.
240:             * @param o Object
241:             * @return boolean
242:             */
243:            public static boolean hasValue(Object o) {
244:                boolean rval = false;
245:                if (o != null && !o.toString().trim().equals("")) {
246:                    rval = true;
247:                }
248:                return rval;
249:            }
250:
251:            /**
252:             * Determines if an object has a value other than null or blank and is equal to
253:             * the test parameter.
254:             * @param o Object
255:             * @param test String
256:             * @return boolean
257:             */
258:            public static boolean hasValue(Object o, String test) {
259:                boolean rval = false;
260:                if (hasValue(o)) {
261:                    if (String.valueOf(o).equals(test)) {
262:                        rval = true;
263:                    }
264:                }
265:                return rval;
266:            }
267:
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.