Source Code Cross Referenced for RestConfigurationImpl.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » component » app » help » 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.component.app.help 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/help/tags/sakai_2-4-1/help-component/src/java/org/sakaiproject/component/app/help/RestConfigurationImpl.java $
003:         * $Id: RestConfigurationImpl.java 7653 2006-04-12 12:10:02Z marquard@ched.uct.ac.za $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004 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.component.app.help;
021:
022:        import java.io.BufferedReader;
023:        import java.io.IOException;
024:        import java.io.InputStreamReader;
025:        import java.io.StringReader;
026:        import java.net.MalformedURLException;
027:        import java.net.URL;
028:        import java.net.URLConnection;
029:
030:        import javax.xml.parsers.DocumentBuilder;
031:        import javax.xml.parsers.DocumentBuilderFactory;
032:
033:        import org.apache.commons.logging.Log;
034:        import org.apache.commons.logging.LogFactory;
035:        import org.sakaiproject.api.app.help.RestConfiguration;
036:        import org.w3c.dom.Node;
037:        import org.w3c.dom.NodeList;
038:        import org.xml.sax.InputSource;
039:
040:        import sun.misc.BASE64Encoder;
041:
042:        /**
043:         * @author <a href="mailto:jlannan.iupui.edu">Jarrod Lannan</a>
044:         * @version $Id: RestConfigurationImpl.java 7653 2006-04-12 12:10:02Z marquard@ched.uct.ac.za $
045:         * 
046:         */
047:        public class RestConfigurationImpl implements  RestConfiguration {
048:
049:            /** user:pass as string ... will be converted to Base64 **/
050:            private String restCredentials;
051:
052:            private String organization;
053:            private String restDomain;
054:            private String restUrl;
055:            private long cacheInterval;
056:
057:            private static String REST_DOMAIN_URL;
058:            private static String REST_CORPUS_URL;
059:
060:            private final static Log LOG = LogFactory
061:                    .getLog(RestConfigurationImpl.class);
062:
063:            /**
064:             * @see org.sakaiproject.api.app.help.RestConfiguration#getOrganization()
065:             */
066:            public String getOrganization() {
067:                return organization;
068:            }
069:
070:            /**
071:             * @see org.sakaiproject.api.app.help.RestConfiguration#setOrganization(java.lang.String)
072:             */
073:            public void setOrganization(String organization) {
074:                this .organization = organization;
075:            }
076:
077:            /**
078:             * @see org.sakaiproject.api.app.help.RestConfiguration#getRestCredentials()
079:             */
080:            public String getRestCredentials() {
081:                return restCredentials;
082:            }
083:
084:            /**
085:             * @see org.sakaiproject.api.app.help.RestConfiguration#setRestCredentials(java.lang.String)
086:             */
087:            public void setRestCredentials(String restCredentials) {
088:                this .restCredentials = restCredentials;
089:            }
090:
091:            /**
092:             * @see org.sakaiproject.api.app.help.RestConfiguration#getRestDomain()
093:             */
094:            public String getRestDomain() {
095:                return restDomain;
096:            }
097:
098:            /**
099:             * @see org.sakaiproject.api.app.help.RestConfiguration#setRestDomain(java.lang.String)
100:             */
101:            public void setRestDomain(String restDomain) {
102:                this .restDomain = restDomain;
103:            }
104:
105:            /**
106:             * @see org.sakaiproject.api.app.help.RestConfiguration#getRestUrl()
107:             */
108:            public String getRestUrl() {
109:                return restUrl;
110:            }
111:
112:            /**
113:             * @see org.sakaiproject.api.app.help.RestConfiguration#setRestUrl(java.lang.String)
114:             */
115:            public void setRestUrl(String restUrl) {
116:                this .restUrl = restUrl;
117:            }
118:
119:            /**
120:             * @see org.sakaiproject.api.app.help.RestConfiguration#getCacheInterval()
121:             */
122:            public long getCacheInterval() {
123:                return cacheInterval;
124:            }
125:
126:            /**
127:             * @see org.sakaiproject.api.app.help.RestConfiguration#setCacheInterval(long)
128:             */
129:            public void setCacheInterval(long cacheInterval) {
130:                this .cacheInterval = cacheInterval;
131:            }
132:
133:            /**
134:             * @see org.sakaiproject.api.app.help.RestConfiguration#getRestUrlInDomain()
135:             */
136:            public String getRestUrlInDomain() {
137:                if (REST_DOMAIN_URL != null) {
138:                    return REST_DOMAIN_URL;
139:                } else {
140:                    return REST_DOMAIN_URL = getRestUrl() + "/"
141:                            + getRestDomain() + "/" + "document/"
142:                            + getRestDomain() + "/";
143:                }
144:            }
145:
146:            /**
147:             * @see org.sakaiproject.api.app.help.RestConfiguration#getRestCorpusUrl()
148:             */
149:            public String getRestCorpusUrl() {
150:                if (REST_DOMAIN_URL != null) {
151:                    return REST_CORPUS_URL;
152:                } else {
153:                    return REST_CORPUS_URL = getRestUrl() + "/"
154:                            + getRestDomain() + "/" + "documents";
155:                }
156:            }
157:
158:            /**
159:             * @see org.sakaiproject.api.app.help.RestConfiguration#getCorpusDocument()
160:             */
161:            public String getCorpusDocument() {
162:
163:                if (LOG.isDebugEnabled()) {
164:                    LOG.debug("getCorpusDocument()");
165:                }
166:
167:                URL url = null;
168:                StringBuffer sBuffer = new StringBuffer();
169:                BufferedReader br = null;
170:                try {
171:                    url = new URL(getRestCorpusUrl());
172:                    URLConnection urlConnection = url.openConnection();
173:
174:                    String basicAuthUserPass = getRestCredentials();
175:                    String encoding = new BASE64Encoder()
176:                            .encode(basicAuthUserPass.getBytes());
177:
178:                    urlConnection.setRequestProperty("Authorization", "Basic "
179:                            + encoding);
180:
181:                    br = new BufferedReader(new InputStreamReader(urlConnection
182:                            .getInputStream()), 512);
183:                    int readReturn = 0;
184:                    char[] cbuf = new char[512];
185:                    while ((readReturn = br.read(cbuf, 0, 512)) != -1) {
186:                        sBuffer.append(cbuf, 0, readReturn);
187:                    }
188:
189:                } catch (MalformedURLException e) {
190:                    LOG.error("Malformed URL in REST document: "
191:                            + url.getPath(), e);
192:                } catch (IOException e) {
193:                    LOG.error("Could not open connection to REST document: "
194:                            + url.getPath(), e);
195:                } finally {
196:                    try {
197:                        if (br != null) {
198:                            br.close();
199:                        }
200:                    } catch (IOException e) {
201:                        LOG.error("error closing corpus doc", e);
202:                    }
203:                }
204:
205:                return sBuffer.toString();
206:            }
207:
208:            /**
209:             * @see org.sakaiproject.api.app.help.RestConfiguration#getResourceNameFromCorpusDoc(java.lang.String)
210:             */
211:            public String getResourceNameFromCorpusDoc(String xml) {
212:                try {
213:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
214:                            .newInstance();
215:                    dbf.setNamespaceAware(true);
216:                    DocumentBuilder builder = dbf.newDocumentBuilder();
217:                    StringReader sReader = new StringReader(xml);
218:                    InputSource inputSource = new org.xml.sax.InputSource(
219:                            sReader);
220:                    org.w3c.dom.Document xmlDocument = builder
221:                            .parse(inputSource);
222:                    sReader.close();
223:
224:                    NodeList nodeList = xmlDocument.getElementsByTagName("kbq");
225:
226:                    int nodeListLength = nodeList.getLength();
227:                    for (int i = 0; i < nodeListLength; i++) {
228:                        Node currentNode = nodeList.item(i);
229:
230:                        NodeList nlChildren = currentNode.getChildNodes();
231:
232:                        for (int j = 0; j < nlChildren.getLength(); j++) {
233:                            if (nlChildren.item(j).getNodeType() == Node.TEXT_NODE) {
234:                                return nlChildren.item(j).getNodeValue();
235:                            }
236:                        }
237:                    }
238:                    return null;
239:                } catch (Exception e) {
240:                    LOG.error(e.getMessage(), e);
241:                }
242:
243:                return null;
244:            }
245:
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.