Source Code Cross Referenced for SettingsServiceImpl.java in  » Portal » gridsphere » org » gridsphere » services » core » customization » impl » 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 » Portal » gridsphere » org.gridsphere.services.core.customization.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.gridsphere.services.core.customization.impl;
002:
003:        import org.apache.commons.logging.Log;
004:        import org.apache.commons.logging.LogFactory;
005:        import org.apache.oro.text.perl.Perl5Util;
006:        import org.apache.oro.text.regex.MatchResult;
007:        import org.gridsphere.portlet.service.PortletServiceUnavailableException;
008:        import org.gridsphere.portlet.service.spi.PortletServiceConfig;
009:        import org.gridsphere.portlet.service.spi.PortletServiceProvider;
010:        import org.gridsphere.services.core.customization.SettingsService;
011:        import org.gridsphere.servlets.GridSphereServlet;
012:
013:        import javax.naming.Context;
014:        import javax.naming.InitialContext;
015:        import javax.naming.NamingException;
016:        import java.io.File;
017:        import java.io.FileInputStream;
018:        import java.io.FileOutputStream;
019:        import java.io.IOException;
020:
021:        public class SettingsServiceImpl implements  PortletServiceProvider,
022:                SettingsService {
023:
024:            private Log log = LogFactory.getLog(GridSphereServlet.class);
025:            private String settingsPath = System.getProperty("user.home")
026:                    + File.separator + ".gridsphere";
027:            private Perl5Util util = new Perl5Util();
028:
029:            /**
030:             * Checks if the JNDI variable for storing gs settings data is set, if not the default is assumed
031:             *
032:             * @param config
033:             * @throws PortletServiceUnavailableException
034:             *
035:             */
036:            public void init(PortletServiceConfig config)
037:                    throws PortletServiceUnavailableException {
038:
039:                log.debug("In Settings");
040:
041:                try {
042:                    Context initCtx = new InitialContext();
043:                    javax.naming.Context env = (Context) initCtx
044:                            .lookup("java:comp/env");
045:                    settingsPath = (String) env.lookup("gridspheresettingsdir");
046:
047:                    //GPF-480 feature: change ${ENV.SYS_VAR_NAME} to value of system environment variable with named "SYS_VAR_NAME"
048:                    while (util
049:                            .match("m/\\$\\{ENV\\.([^}]+)\\}/", settingsPath)) {
050:                        MatchResult matchResult = util.getMatch();
051:                        String systemEnvironmentVariableName = matchResult
052:                                .group(1);
053:                        //can cause NPE if system environment variable was not set
054:                        settingsPath = settingsPath.replaceAll("\\$\\{ENV\\."
055:                                + systemEnvironmentVariableName + "\\}", System
056:                                .getenv(systemEnvironmentVariableName).replace(
057:                                        '\\', '/'));
058:                    }
059:                    log.info("Got config settings from JNDI");
060:                } catch (NamingException e) {
061:                    // it does not exist, which is ok as well, we just use the default
062:                    settingsPath = System.getProperty("user.home")
063:                            + File.separator + ".gridsphere";
064:                } catch (NullPointerException e) {
065:                    // it exists, but some of system environment variable used in it's value was not set
066:                    settingsPath = System.getProperty("user.home")
067:                            + File.separator + ".gridsphere";
068:                }
069:                // check if the path exist, if not create it and copy the template files (from WEB-INF/CustomPortal) to it
070:                File path = new File(settingsPath);
071:                log.info("GridSphere Settings will be saved in: "
072:                        + settingsPath);
073:                if (!path.exists()) {
074:                    path.mkdirs();
075:                    log.info("GridSphere ConfigDir did not exist, created.");
076:                    try {
077:                        copyFiles(config.getServletContext().getRealPath(
078:                                "/WEB-INF/CustomPortal"), settingsPath);
079:                        log.info("Copy files to directory");
080:                    } catch (IOException e) {
081:                        log
082:                                .error("Could not copy files to defined destination: "
083:                                        + config
084:                                                .getServletContext()
085:                                                .getRealPath(
086:                                                        "/WEB-INF/CustomPortal")
087:                                        + " to " + settingsPath);
088:                    }
089:
090:                }
091:            }
092:
093:            public void destroy() {
094:                //To change body of implemented methods use File | Settings | File Templates.
095:            }
096:
097:            public String getSettingsPath() {
098:                return settingsPath;
099:            }
100:
101:            public String getRealSettingsPath(String path) {
102:                String result = settingsPath + File.separator + path;
103:                //result = result.replaceAll("/", File.separator);
104:                File f = new File(result);
105:                if (f.isDirectory() && !result.endsWith(File.separator))
106:                    result = result + File.separator;
107:                return result;
108:            }
109:
110:            private void copyFiles(String strPath, String dstPath)
111:                    throws IOException {
112:                File src = new File(strPath);
113:                File dest = new File(dstPath);
114:
115:                if (src.isDirectory()) {
116:                    //if(dest.exists()!=true)
117:                    dest.mkdirs();
118:                    String list[] = src.list();
119:
120:                    for (int i = 0; i < list.length; i++) {
121:                        String dest1 = dest.getAbsolutePath() + File.separator
122:                                + list[i];
123:                        String src1 = src.getAbsolutePath() + File.separator
124:                                + list[i];
125:                        copyFiles(src1, dest1);
126:                    }
127:                } else {
128:                    FileInputStream fin = new FileInputStream(src);
129:                    FileOutputStream fout = new FileOutputStream(dest);
130:                    int c;
131:                    while ((c = fin.read()) >= 0)
132:                        fout.write(c);
133:                    fin.close();
134:                    fout.close();
135:                }
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.