Source Code Cross Referenced for VendorUtils.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » vendor » util » 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 » Kuali Financial System » org.kuali.module.vendor.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 The Kuali Foundation.
003:         * 
004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         * http://www.opensource.org/licenses/ecl1.php
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.kuali.module.vendor.util;
017:
018:        import org.apache.commons.lang.StringUtils;
019:
020:        /**
021:         * Utility class with helper methods for Vendor processing 
022:         */
023:        public class VendorUtils {
024:
025:            public static final char LEFT_COLLECTION_SEPERATOR = '[';
026:            public static final char RIGHT_COLLECTION_SEPERATOR = ']';
027:            public static final char FIELD_SEPERATOR = '.';
028:
029:            /**
030:             * Builds up a string and a position like so abc, 1 becomes abc[1] it is used for fields that require operations on
031:             * collections.
032:             * 
033:             * @param full
034:             * @param collections
035:             * @param pos
036:             * @return Newly formatted string
037:             */
038:            public static String assembleWithPosition(String full,
039:                    String[] collections, int[] positions) {
040:
041:                if (collections.length != positions.length) {
042:                    throw new IllegalArgumentException();
043:                }
044:
045:                String[] parts = StringUtils.split(full, FIELD_SEPERATOR);
046:
047:                for (int j = 0; j < parts.length; j++) {
048:                    for (int i = 0; i < collections.length; i++) {
049:                        if (StringUtils.equals(parts[j], collections[i])) {
050:                            parts[j] = collections[i]
051:                                    + LEFT_COLLECTION_SEPERATOR + positions[i]
052:                                    + RIGHT_COLLECTION_SEPERATOR;
053:                            break;
054:                        }
055:
056:                    }
057:                }
058:
059:                return StringUtils.join(parts, FIELD_SEPERATOR);
060:            }
061:
062:            /**
063:             * A helper to call assembleWithPosition(String full, String[] collections, int[] positions) when only one
064:             * collection
065:             * 
066:             * @param full
067:             * @param collection
068:             * @param position
069:             * @return Newly formatted string
070:             */
071:            public static String assembleWithPosition(String full,
072:                    String collection, int position) {
073:                String[] collections = { collection };
074:                int[] positions = { position };
075:                return assembleWithPosition(full, collections, positions);
076:            }
077:
078:            /**
079:             * Returns the headerId portion from a composite vendor number.
080:             * 
081:             * @param vendorNumber - composite vendor number (detail and header)
082:             * @return returns the headerId number
083:             */
084:            public static Integer getVendorHeaderId(String vendorNumber) {
085:
086:                // validate the vendorNumber passed in
087:                if (!VendorUtils.validVendorNumberFormat(vendorNumber)) {
088:                    return null;
089:                }
090:
091:                // return the headerId, everything before the dash (-)
092:                String[] vendorNumberParts = vendorNumber.split("-");
093:                return new Integer(Integer.parseInt(vendorNumberParts[0]));
094:            }
095:
096:            /**
097:             * Returns the detailId portion from a composite vendor number.
098:             * 
099:             * @param vendorNumber - composite vendor number (detail and header)
100:             * @return returns the detailId number
101:             */
102:            public static Integer getVendorDetailId(String vendorNumber) {
103:
104:                if (!VendorUtils.validVendorNumberFormat(vendorNumber)) {
105:                    return null;
106:                }
107:
108:                // return the headerId, everything before the dash (-)
109:                String[] vendorNumberParts = vendorNumber.split("-");
110:                return new Integer(Integer.parseInt(vendorNumberParts[1]));
111:            }
112:
113:            /**
114:             * Accepts a vendorNumber string, and evaluates it to make sure it is of the correct format. This method does not
115:             * test whether the given vendor number exists in the database, rather it just tests that the format is correct.
116:             * 
117:             * @param vendorNumber - String representing the vendor number
118:             * @return - returns an empty string on success, or an error message on a failure
119:             */
120:            public static boolean validVendorNumberFormat(String vendorNumber) {
121:
122:                // disallow null string
123:                if (vendorNumber == null) {
124:                    return false;
125:                }
126:
127:                // validate the overall format: numbers - numbers
128:                if (!vendorNumber.matches("\\d+-\\d+")) {
129:                    return false;
130:                }
131:
132:                return true;
133:            }
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.