Source Code Cross Referenced for ContentHostingComparator.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » content » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.content.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/content/tags/sakai_2-4-1/content-impl/impl/src/java/org/sakaiproject/content/impl/ContentHostingComparator.java $
003:         * $Id: ContentHostingComparator.java 29157 2007-04-19 01:38:26Z ajpoland@iupui.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.content.impl;
021:
022:        import java.util.Comparator;
023:
024:        import org.sakaiproject.content.api.ContentCollection;
025:        import org.sakaiproject.content.api.ContentEntity;
026:        import org.sakaiproject.content.api.ContentHostingService;
027:        import org.sakaiproject.content.api.ContentResource;
028:        import org.sakaiproject.entity.api.Entity;
029:        import org.sakaiproject.entity.api.ResourceProperties;
030:        import org.sakaiproject.time.api.Time;
031:
032:        /**
033:         * <p>
034:         * ContentHostingComparator can be used to sort stuff (collections, resources) from the content hosting service.
035:         * </p>
036:         */
037:        public class ContentHostingComparator implements  Comparator {
038:            /** The property name used for the sort. */
039:            String m_property = null;
040:
041:            /** true if the sort is to be ascending (false for descending). */
042:            boolean m_ascending = true;
043:
044:            /**
045:             * Construct.
046:             * 
047:             * @param property
048:             *        The property name used for the sort.
049:             * @param asc
050:             *        true if the sort is to be ascending (false for descending).
051:             */
052:            public ContentHostingComparator(String property, boolean ascending) {
053:                m_property = property;
054:                m_ascending = ascending;
055:
056:            } // ContentHostingComparator
057:
058:            /**
059:             * Compare these objects based on my property and ascending settings. Collections sort lower than Resources.
060:             * 
061:             * @param o1
062:             *        The first object, ContentCollection or ContentResource
063:             * @param o2
064:             *        The second object, ContentCollection or ContentResource
065:             * @return The compare result: -1 if o1 < o2, 0 if they are equal, and 1 if o1 > o2
066:             */
067:            public int compare(Object o1, Object o2) {
068:                String property = m_property;
069:
070:                // PROP_CONTENT_PRIORITY is special because it allows 
071:                // intermixing folders and files. 
072:                if (property.equals(ResourceProperties.PROP_CONTENT_PRIORITY)) {
073:                    Entity entity1 = (Entity) o1;
074:                    Entity entity2 = (Entity) o2;
075:                    String str1 = entity1.getProperties().getProperty(property);
076:                    String str2 = entity2.getProperties().getProperty(property);
077:
078:                    if (str1 == null || str2 == null) {
079:                        // ignore -- default to a different sort
080:                    } else {
081:                        try {
082:                            Integer rank1 = new Integer(str1);
083:                            Integer rank2 = new Integer(str2);
084:                            return m_ascending ? rank1.compareTo(rank2) : rank2
085:                                    .compareTo(rank1);
086:                        } catch (NumberFormatException e) {
087:                            // ignore -- default to a different sort
088:                        }
089:                    }
090:                    // if unable to do a priority sort, sort by title
091:                    property = ResourceProperties.PROP_DISPLAY_NAME;
092:                }
093:
094:                // collections sort lower than resources
095:                if ((o1 instanceof  ContentCollection)
096:                        && (o2 instanceof  ContentResource)) {
097:                    return (m_ascending ? -1 : 1);
098:                }
099:                if ((o1 instanceof  ContentResource)
100:                        && (o2 instanceof  ContentCollection)) {
101:                    return (m_ascending ? 1 : -1);
102:                }
103:
104:                if (property.equals(ResourceProperties.PROP_CONTENT_LENGTH)
105:                        && o1 instanceof  ContentCollection) {
106:                    int size1 = ((ContentCollection) o1).getMemberCount();
107:                    int size2 = ((ContentCollection) o2).getMemberCount();
108:                    int rv = ((size1 < size2) ? -1 : ((size1 > size2) ? 1 : 0));
109:                    if (!m_ascending)
110:                        rv = -rv;
111:                    return rv;
112:                }
113:
114:                // ok, they are both the same: resources or collections
115:
116:                // try a numeric interpretation
117:                try {
118:                    long l1 = ((Entity) o1).getProperties().getLongProperty(
119:                            property);
120:                    long l2 = ((Entity) o2).getProperties().getLongProperty(
121:                            property);
122:                    int rv = ((l1 < l2) ? -1 : ((l1 > l2) ? 1 : 0));
123:                    if (!m_ascending)
124:                        rv = -rv;
125:                    return rv;
126:                } catch (Exception ignore) {
127:                }
128:
129:                // try a Time interpretation
130:                try {
131:                    Time t1 = ((Entity) o1).getProperties().getTimeProperty(
132:                            property);
133:                    Time t2 = ((Entity) o2).getProperties().getTimeProperty(
134:                            property);
135:                    int rv = t1.compareTo(t2);
136:                    if (!m_ascending)
137:                        rv = -rv;
138:                    return rv;
139:                } catch (Exception ignore) {
140:                }
141:
142:                // do a formatted interpretation - case insensitive
143:                if (o1 == null)
144:                    return -1;
145:                if (o2 == null)
146:                    return +1;
147:                String s1 = ((Entity) o1).getProperties().getPropertyFormatted(
148:                        property);
149:                String s2 = ((Entity) o2).getProperties().getPropertyFormatted(
150:                        property);
151:                int rv = s1.compareToIgnoreCase(s2);
152:                if (!m_ascending)
153:                    rv = -rv;
154:                return rv;
155:
156:            } // compare
157:
158:            public String toString() {
159:                return this .getClass().getName() + ": property(" + m_property
160:                        + ") ascending(" + m_ascending + ")";
161:
162:            }
163:
164:        } // ClassResourcesComparator
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.