Source Code Cross Referenced for ReferenceList.java in  » Web-Services » restlet-1.0.8 » org » restlet » data » 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 » Web Services » restlet 1.0.8 » org.restlet.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 Noelios Consulting.
003:         * 
004:         * The contents of this file are subject to the terms of the Common Development
005:         * and Distribution License (the "License"). You may not use this file except in
006:         * compliance with the License.
007:         * 
008:         * You can obtain a copy of the license at
009:         * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
010:         * language governing permissions and limitations under the License.
011:         * 
012:         * When distributing Covered Code, include this CDDL HEADER in each file and
013:         * include the License file at http://www.opensource.org/licenses/cddl1.txt If
014:         * applicable, add the following below this CDDL HEADER, with the fields
015:         * enclosed by brackets "[]" replaced with your own identifying information:
016:         * Portions Copyright [yyyy] [name of copyright owner]
017:         */
018:
019:        package org.restlet.data;
020:
021:        import java.io.BufferedReader;
022:        import java.io.IOException;
023:        import java.io.InputStreamReader;
024:        import java.util.ArrayList;
025:        import java.util.List;
026:
027:        import org.restlet.resource.Representation;
028:        import org.restlet.resource.StringRepresentation;
029:        import org.restlet.util.WrapperList;
030:
031:        /**
032:         * List of URI references.
033:         * 
034:         * @author Jerome Louvel (contact@noelios.com)
035:         */
036:        public class ReferenceList extends WrapperList<Reference> {
037:            /** The list identifier. */
038:            private Reference identifier;
039:
040:            /**
041:             * Constructor.
042:             */
043:            public ReferenceList() {
044:                super ();
045:            }
046:
047:            /**
048:             * Constructor.
049:             * 
050:             * @param initialCapacity
051:             *            The initial list capacity.
052:             */
053:            public ReferenceList(int initialCapacity) {
054:                super (new ArrayList<Reference>(initialCapacity));
055:            }
056:
057:            /**
058:             * Constructor.
059:             * 
060:             * @param delegate
061:             *            The delegate list.
062:             */
063:            public ReferenceList(List<Reference> delegate) {
064:                super (delegate);
065:            }
066:
067:            /**
068:             * Constructor from a "text/uri-list" representation.
069:             * 
070:             * @param uriList
071:             *            The "text/uri-list" representation to parse.
072:             * @throws IOException
073:             */
074:            public ReferenceList(Representation uriList) throws IOException {
075:                BufferedReader br = null;
076:                try {
077:                    br = new BufferedReader(new InputStreamReader(uriList
078:                            .getStream()));
079:
080:                    String line = br.readLine();
081:
082:                    // Checks if the list reference is specified as the first comment.
083:                    if ((line != null) && line.startsWith("#")) {
084:                        setIdentifier(new Reference(line.substring(1).trim()));
085:                        line = br.readLine();
086:                    }
087:
088:                    while (line != null) {
089:                        if (!line.startsWith("#")) {
090:                            add(new Reference(line.trim()));
091:                        }
092:
093:                        line = br.readLine();
094:                    }
095:                } finally {
096:                    if (br != null) {
097:                        br.close();
098:                    }
099:                }
100:            }
101:
102:            /**
103:             * Creates then adds a reference at the end of the list.
104:             * 
105:             * @param uri
106:             *            The uri of the reference to add.
107:             * @return True (as per the general contract of the Collection.add method).
108:             */
109:            public boolean add(String uri) {
110:                return add(new Reference(uri));
111:            }
112:
113:            /**
114:             * Returns the list identifier.
115:             * 
116:             * @return The list identifier.
117:             */
118:            public Reference getIdentifier() {
119:                return this .identifier;
120:            }
121:
122:            /**
123:             * Returns a representation of the list in the "text/uri-list" format.
124:             * 
125:             * @return A representation of the list in the "text/uri-list" format.
126:             */
127:            public Representation getTextRepresentation() {
128:                StringBuilder sb = new StringBuilder();
129:
130:                if (getIdentifier() != null) {
131:                    sb.append("# ").append(getIdentifier().toString()).append(
132:                            "\r\n");
133:                }
134:
135:                for (Reference ref : this ) {
136:                    sb.append(ref.toString()).append("\r\n");
137:                }
138:
139:                return new StringRepresentation(sb.toString(),
140:                        MediaType.TEXT_URI_LIST);
141:            }
142:
143:            /**
144:             * Returns a representation of the list in "text/html" format.
145:             * 
146:             * @return A representation of the list in "text/html" format.
147:             */
148:            public Representation getWebRepresentation() {
149:                // Create a simple HTML list
150:                StringBuilder sb = new StringBuilder();
151:                sb.append("<html><body>\n");
152:
153:                if (getIdentifier() != null) {
154:                    sb.append("<h2>Listing of \"" + getIdentifier().getPath()
155:                            + "\"</h2>\n");
156:                    Reference parentRef = getIdentifier().getParentRef();
157:
158:                    if (!parentRef.equals(getIdentifier())) {
159:                        sb
160:                                .append("<a href=\"" + parentRef
161:                                        + "\">..</a><br/>\n");
162:                    }
163:                } else {
164:                    sb.append("<h2>List of references</h2>\n");
165:                }
166:
167:                for (Reference ref : this ) {
168:                    sb.append("<a href=\"" + ref.toString() + "\">"
169:                            + ref.getRelativeRef(getIdentifier())
170:                            + "</a><br/>\n");
171:                }
172:                sb.append("</body></html>\n");
173:
174:                return new StringRepresentation(sb.toString(),
175:                        MediaType.TEXT_HTML);
176:            }
177:
178:            /**
179:             * Sets the list reference.
180:             * 
181:             * @param identifier
182:             *            The list identifier.
183:             */
184:            public void setIdentifier(Reference identifier) {
185:                this .identifier = identifier;
186:            }
187:
188:            /**
189:             * Sets the list reference.
190:             * 
191:             * @param identifier
192:             *            The list identifier as a URI.
193:             */
194:            public void setIdentifier(String identifier) {
195:                setIdentifier(new Reference(identifier));
196:            }
197:
198:            /**
199:             * Returns a view of the portion of this list between the specified
200:             * fromIndex, inclusive, and toIndex, exclusive.
201:             * 
202:             * @param fromIndex
203:             *            The start position.
204:             * @param toIndex
205:             *            The end position (exclusive).
206:             * @return The sub-list.
207:             */
208:            @Override
209:            public ReferenceList subList(int fromIndex, int toIndex) {
210:                return new ReferenceList(getDelegate().subList(fromIndex,
211:                        toIndex));
212:            }
213:
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.