Source Code Cross Referenced for NFS4StringPrep.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » stringprep » 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 » Internationalization Localization » icu4j » com.ibm.icu.dev.test.stringprep 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *******************************************************************************
003:         * Copyright (C) 2003-2005, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */
007:        package com.ibm.icu.dev.test.stringprep;
008:
009:        import java.io.IOException;
010:        import java.io.InputStream;
011:        import java.io.UnsupportedEncodingException;
012:        import java.util.MissingResourceException;
013:
014:        import com.ibm.icu.impl.ICUData;
015:        import com.ibm.icu.text.StringPrepParseException;
016:        import com.ibm.icu.text.StringPrep;
017:        import com.ibm.icu.text.UCharacterIterator;
018:
019:        /**
020:         * @author ram
021:         *
022:         * This is a dumb implementation of NFS4 profiles. It is a direct port of
023:         * C code, does not use Object Oriented principles. Quick and Dirty implementation
024:         * for testing.
025:         */
026:        public final class NFS4StringPrep {
027:
028:            private StringPrep nfscss = null;
029:            private StringPrep nfscsi = null;
030:            private StringPrep nfscis = null;
031:            private StringPrep nfsmxp = null;
032:            private StringPrep nfsmxs = null;
033:            //singleton instance
034:            private static final NFS4StringPrep prep = new NFS4StringPrep();
035:
036:            private NFS4StringPrep() {
037:                ClassLoader loader = NFS4StringPrep.class.getClassLoader();
038:                try {
039:                    InputStream nfscsiFile = loader
040:                            .getResourceAsStream("com/ibm/icu/dev/data/testdata/nfscsi.spp");
041:                    nfscsi = new StringPrep(nfscsiFile);
042:                    nfscsiFile.close();
043:
044:                    InputStream nfscssFile = loader
045:                            .getResourceAsStream("com/ibm/icu/dev/data/testdata/nfscss.spp");
046:                    nfscss = new StringPrep(nfscssFile);
047:                    nfscssFile.close();
048:
049:                    InputStream nfscisFile = loader
050:                            .getResourceAsStream("com/ibm/icu/dev/data/testdata/nfscis.spp");
051:                    nfscis = new StringPrep(nfscisFile);
052:                    nfscisFile.close();
053:
054:                    InputStream nfsmxpFile = loader
055:                            .getResourceAsStream("com/ibm/icu/dev/data/testdata/nfsmxp.spp");
056:                    nfsmxp = new StringPrep(nfsmxpFile);
057:                    nfsmxpFile.close();
058:
059:                    InputStream nfsmxsFile = loader
060:                            .getResourceAsStream("com/ibm/icu/dev/data/testdata/nfsmxs.spp");
061:                    nfsmxs = new StringPrep(nfsmxsFile);
062:                    nfsmxsFile.close();
063:                } catch (IOException e) {
064:                    throw new MissingResourceException(e.toString(), "", "");
065:                }
066:            }
067:
068:            private static byte[] prepare(byte[] src, StringPrep prep)
069:                    throws StringPrepParseException,
070:                    UnsupportedEncodingException {
071:                String s = new String(src, "UTF-8");
072:                UCharacterIterator iter = UCharacterIterator.getInstance(s);
073:                StringBuffer out = prep.prepare(iter, StringPrep.DEFAULT);
074:                return out.toString().getBytes("UTF-8");
075:            }
076:
077:            public static byte[] cs_prepare(byte[] src, boolean isCaseSensitive)
078:                    throws StringPrepParseException,
079:                    UnsupportedEncodingException {
080:                if (isCaseSensitive == true) {
081:                    return prepare(src, prep.nfscss);
082:                } else {
083:                    return prepare(src, prep.nfscsi);
084:                }
085:            }
086:
087:            public static byte[] cis_prepare(byte[] src) throws IOException,
088:                    StringPrepParseException, UnsupportedEncodingException {
089:                return prepare(src, prep.nfscis);
090:            }
091:
092:            /* sorted array for binary search*/
093:            private static final String[] special_prefixes = { "ANONYMOUS",
094:                    "AUTHENTICATED", "BATCH", "DIALUP", "EVERYONE", "GROUP",
095:                    "INTERACTIVE", "NETWORK", "OWNER", };
096:
097:            /* binary search the sorted array */
098:            private static final int findStringIndex(String[] sortedArr,
099:                    String target) {
100:
101:                int left, middle, right, rc;
102:
103:                left = 0;
104:                right = sortedArr.length - 1;
105:
106:                while (left <= right) {
107:                    middle = (left + right) / 2;
108:                    rc = sortedArr[middle].compareTo(target);
109:
110:                    if (rc < 0) {
111:                        left = middle + 1;
112:                    } else if (rc > 0) {
113:                        right = middle - 1;
114:                    } else {
115:                        return middle;
116:                    }
117:                }
118:                return -1;
119:            }
120:
121:            private static final char AT_SIGN = '@';
122:
123:            public static byte[] mixed_prepare(byte[] src) throws IOException,
124:                    StringPrepParseException, UnsupportedEncodingException {
125:                String s = new String(src, "UTF-8");
126:                int index = s.indexOf(AT_SIGN);
127:                StringBuffer out = new StringBuffer();
128:
129:                if (index > -1) {
130:                    /* special prefixes must not be followed by suffixes! */
131:                    String prefixString = s.substring(0, index);
132:                    int i = findStringIndex(special_prefixes, prefixString);
133:                    String suffixString = s.substring(index + 1, s.length());
134:                    if (i > -1 && !suffixString.equals("")) {
135:                        throw new StringPrepParseException(
136:                                "Suffix following a special index",
137:                                StringPrepParseException.INVALID_CHAR_FOUND);
138:                    }
139:                    UCharacterIterator prefix = UCharacterIterator
140:                            .getInstance(prefixString);
141:                    UCharacterIterator suffix = UCharacterIterator
142:                            .getInstance(suffixString);
143:                    out.append(prep.nfsmxp.prepare(prefix, StringPrep.DEFAULT));
144:                    out.append(AT_SIGN); // add the delimiter
145:                    out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
146:                } else {
147:                    UCharacterIterator iter = UCharacterIterator.getInstance(s);
148:                    out.append(prep.nfsmxp.prepare(iter, StringPrep.DEFAULT));
149:
150:                }
151:                return out.toString().getBytes("UTF-8");
152:            }
153:
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.