Source Code Cross Referenced for DisplayText.java in  » EJB-Server-geronimo » crypto » org » apache » geronimo » crypto » asn1 » x509 » 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 » EJB Server geronimo » crypto » org.apache.geronimo.crypto.asn1.x509 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.crypto.asn1.x509;
017:
018:        import org.apache.geronimo.crypto.asn1.ASN1Choice;
019:        import org.apache.geronimo.crypto.asn1.ASN1Encodable;
020:        import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
021:        import org.apache.geronimo.crypto.asn1.DERObject;
022:        import org.apache.geronimo.crypto.asn1.DERBMPString;
023:        import org.apache.geronimo.crypto.asn1.DERIA5String;
024:        import org.apache.geronimo.crypto.asn1.DERUTF8String;
025:        import org.apache.geronimo.crypto.asn1.DERVisibleString;
026:        import org.apache.geronimo.crypto.asn1.DERString;
027:
028:        /**
029:         * <code>DisplayText</code> class, used in
030:         * <code>CertificatePolicies</code> X509 V3 extensions (in policy qualifiers).
031:         *
032:         * <p>It stores a string in a chosen encoding.
033:         * <pre>
034:         * DisplayText ::= CHOICE {
035:         *      ia5String        IA5String      (SIZE (1..200)),
036:         *      visibleString    VisibleString  (SIZE (1..200)),
037:         *      bmpString        BMPString      (SIZE (1..200)),
038:         *      utf8String       UTF8String     (SIZE (1..200)) }
039:         * </pre>
040:         * @see PolicyQualifierInfo
041:         * @see PolicyInformation
042:         */
043:        public class DisplayText extends ASN1Encodable implements  ASN1Choice {
044:            /**
045:             * Constant corresponding to ia5String encoding.
046:             *
047:             */
048:            public static final int CONTENT_TYPE_IA5STRING = 0;
049:            /**
050:             * Constant corresponding to bmpString encoding.
051:             *
052:             */
053:            public static final int CONTENT_TYPE_BMPSTRING = 1;
054:            /**
055:             * Constant corresponding to utf8String encoding.
056:             *
057:             */
058:            public static final int CONTENT_TYPE_UTF8STRING = 2;
059:            /**
060:             * Constant corresponding to visibleString encoding.
061:             *
062:             */
063:            public static final int CONTENT_TYPE_VISIBLESTRING = 3;
064:
065:            /**
066:             * Describe constant <code>DISPLAY_TEXT_MAXIMUM_SIZE</code> here.
067:             *
068:             */
069:            public static final int DISPLAY_TEXT_MAXIMUM_SIZE = 200;
070:
071:            int contentType;
072:            DERString contents;
073:
074:            /**
075:             * Creates a new <code>DisplayText</code> instance.
076:             *
077:             * @param type the desired encoding type for the text.
078:             * @param text the text to store. Strings longer than 200
079:             * characters are truncated.
080:             */
081:            public DisplayText(int type, String text) {
082:                if (text.length() > DISPLAY_TEXT_MAXIMUM_SIZE) {
083:                    // RFC3280 limits these strings to 200 chars
084:                    // truncate the string
085:                    text = text.substring(0, DISPLAY_TEXT_MAXIMUM_SIZE);
086:                }
087:
088:                contentType = type;
089:                switch (type) {
090:                case CONTENT_TYPE_IA5STRING:
091:                    contents = (DERString) new DERIA5String(text);
092:                    break;
093:                case CONTENT_TYPE_UTF8STRING:
094:                    contents = (DERString) new DERUTF8String(text);
095:                    break;
096:                case CONTENT_TYPE_VISIBLESTRING:
097:                    contents = (DERString) new DERVisibleString(text);
098:                    break;
099:                case CONTENT_TYPE_BMPSTRING:
100:                    contents = (DERString) new DERBMPString(text);
101:                    break;
102:                default:
103:                    contents = (DERString) new DERUTF8String(text);
104:                    break;
105:                }
106:            }
107:
108:            /**
109:             * return true if the passed in String can be represented without
110:             * loss as a UTF8String, false otherwise.
111:             */
112:            private boolean canBeUTF8(String str) {
113:                for (int i = str.length() - 1; i >= 0; i--) {
114:                    if (str.charAt(i) > 0x00ff) {
115:                        return false;
116:                    }
117:                }
118:
119:                return true;
120:            }
121:
122:            /**
123:             * Creates a new <code>DisplayText</code> instance.
124:             *
125:             * @param text the text to encapsulate. Strings longer than 200
126:             * characters are truncated.
127:             */
128:            public DisplayText(String text) {
129:                // by default use UTF8String
130:                if (text.length() > DISPLAY_TEXT_MAXIMUM_SIZE) {
131:                    text = text.substring(0, DISPLAY_TEXT_MAXIMUM_SIZE);
132:                }
133:
134:                if (canBeUTF8(text)) {
135:                    contentType = CONTENT_TYPE_UTF8STRING;
136:                    contents = new DERUTF8String(text);
137:                } else {
138:                    contentType = CONTENT_TYPE_BMPSTRING;
139:                    contents = new DERBMPString(text);
140:                }
141:            }
142:
143:            /**
144:             * Creates a new <code>DisplayText</code> instance.
145:             * <p>Useful when reading back a <code>DisplayText</code> class
146:             * from it's ASN1Encodable/DEREncodable form.
147:             *
148:             * @param de a <code>DEREncodable</code> instance.
149:             */
150:            public DisplayText(DERString de) {
151:                contents = de;
152:            }
153:
154:            public static DisplayText getInstance(Object de) {
155:                if (de instanceof  DERString) {
156:                    return new DisplayText((DERString) de);
157:                } else if (de instanceof  DisplayText) {
158:                    return (DisplayText) de;
159:                }
160:
161:                throw new IllegalArgumentException(
162:                        "illegal object in getInstance");
163:            }
164:
165:            public static DisplayText getInstance(ASN1TaggedObject obj,
166:                    boolean explicit) {
167:                return getInstance(obj.getObject()); // must be explicitly tagged
168:            }
169:
170:            public DERObject toASN1Object() {
171:                return (DERObject) contents;
172:            }
173:
174:            /**
175:             * Returns the stored <code>String</code> object.
176:             *
177:             * @return the stored text as a <code>String</code>.
178:             */
179:            public String getString() {
180:                return contents.getString();
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.