Source Code Cross Referenced for CmsHistoryResourceHandler.java in  » Content-Management-System » opencms » org » opencms » file » history » 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 » Content Management System » opencms » org.opencms.file.history 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/file/history/CmsHistoryResourceHandler.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:25 $
004:         * Version: $Revision: 1.5 $
005:         *
006:         * This library is part of OpenCms -
007:         * the Open Source Content Management System
008:         *
009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * For further information about Alkacon Software GmbH, please see the
022:         * company website: http://www.alkacon.com
023:         *
024:         * For further information about OpenCms, please see the
025:         * project website: http://www.opencms.org
026:         *
027:         * You should have received a copy of the GNU Lesser General Public
028:         * License along with this library; if not, write to the Free Software
029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030:         */
031:
032:        package org.opencms.file.history;
033:
034:        import org.opencms.file.CmsObject;
035:        import org.opencms.file.CmsResource;
036:        import org.opencms.file.Messages;
037:        import org.opencms.main.CmsException;
038:        import org.opencms.main.CmsLog;
039:        import org.opencms.main.CmsResourceInitException;
040:        import org.opencms.main.I_CmsResourceInit;
041:
042:        import javax.servlet.ServletRequest;
043:        import javax.servlet.http.HttpServletRequest;
044:        import javax.servlet.http.HttpServletResponse;
045:
046:        import org.apache.commons.logging.Log;
047:
048:        /**
049:         * Resource init handler that loads historical versions of resources.<p>
050:         *
051:         * @author Michael Emmerich 
052:         * @author Michael Moossen
053:         * 
054:         * @version $Revision: 1.5 $
055:         * 
056:         * @since 6.9.1
057:         */
058:        public class CmsHistoryResourceHandler implements  I_CmsResourceInit {
059:
060:            /** Constant for the historical version request attribute name. */
061:            public static final String ATTRIBUTE_NAME = "org.opencms.file.history.CmsHistoryResourceHandler";
062:
063:            /** The historical version handler path. */
064:            public static final String HISTORY_HANDLER = "/system/shared/showversion";
065:
066:            /** The static log object for this class. */
067:            private static final Log LOG = CmsLog
068:                    .getLog(CmsHistoryResourceHandler.class);
069:
070:            /** Request parameter name for the version number. */
071:            public static final String PARAM_VERSION = "version";
072:
073:            /** Constant for the offline project version. */
074:            public static final int PROJECT_OFFLINE_VERSION = Integer.MAX_VALUE;
075:
076:            /**
077:             * Returns the historical version of a resource, 
078:             * if the given request is displaying a history version.<p> 
079:             * 
080:             * @param req the request to check
081:             * 
082:             * @return the historical resource if the given request is displaying an historical version
083:             */
084:            public static I_CmsHistoryResource getHistoryResource(
085:                    ServletRequest req) {
086:
087:                return (I_CmsHistoryResource) req.getAttribute(ATTRIBUTE_NAME);
088:            }
089:
090:            /**
091:             * Returns <code>true</code> if the given request is displaying an historical version.<p> 
092:             * 
093:             * @param req the request to check
094:             * 
095:             * @return <code>true</code> if the given request is displaying a historical version
096:             */
097:            public static boolean isHistoryRequest(ServletRequest req) {
098:
099:                return (null != req.getAttribute(ATTRIBUTE_NAME));
100:            }
101:
102:            /**
103:             * @see org.opencms.main.I_CmsResourceInit#initResource(org.opencms.file.CmsResource, org.opencms.file.CmsObject, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
104:             */
105:            public CmsResource initResource(CmsResource resource,
106:                    CmsObject cms, HttpServletRequest req,
107:                    HttpServletResponse res) throws CmsResourceInitException {
108:
109:                // we only have to check for history resources if the handler was called
110:                // during a real request and NOT during a dummy-request while doing
111:                // a static export
112:                if (req != null) {
113:                    String uri = cms.getRequestContext().getUri();
114:                    // check if the resource starts with the HISTORY_HANDLER
115:                    if (uri.startsWith(HISTORY_HANDLER)) {
116:                        String version = req.getParameter(PARAM_VERSION);
117:
118:                        // only do something if the resource was not found and there was a "versionid" parameter included
119:                        if ((resource == null) && (version != null)) {
120:
121:                            // test if the current user is allowed to read historical versions of resources
122:                            // this can be done by trying to read the history handler resource
123:                            if (cms.existsResource(HISTORY_HANDLER)) {
124:                                String storedSiteRoot = cms.getRequestContext()
125:                                        .getSiteRoot();
126:                                try {
127:                                    // we now must switch to the root site to read the history resource
128:                                    cms.getRequestContext().setSiteRoot("/");
129:
130:                                    // extract the "real" resourcename
131:                                    uri = uri.substring(HISTORY_HANDLER
132:                                            .length(), uri.length());
133:                                    int id = new Integer(version).intValue();
134:                                    if (id == CmsHistoryResourceHandler.PROJECT_OFFLINE_VERSION) {
135:                                        resource = new CmsHistoryFile(cms
136:                                                .readFile(uri));
137:                                    } else {
138:                                        resource = (CmsResource) cms
139:                                                .readResource(cms.readResource(
140:                                                        uri).getStructureId(),
141:                                                        id);
142:                                    }
143:                                    // store a request attribute to indicate that this is in fact a historical version
144:                                    req.setAttribute(ATTRIBUTE_NAME, resource);
145:                                } catch (CmsException e) {
146:                                    if (LOG.isErrorEnabled()) {
147:                                        LOG
148:                                                .error(Messages
149:                                                        .get()
150:                                                        .getBundle()
151:                                                        .key(
152:                                                                Messages.ERR_HISTORYRESOURCE_2,
153:                                                                uri, version));
154:                                    }
155:                                    throw new CmsResourceInitException(Messages
156:                                            .get().container(
157:                                                    Messages.ERR_SHOWVERSION_2,
158:                                                    uri, version), e);
159:                                } finally {
160:                                    // restore the siteroot and modify the uri to the one of the correct resource
161:                                    cms.getRequestContext().setSiteRoot(
162:                                            storedSiteRoot);
163:                                    if (resource != null) {
164:                                        // resource may be null in case of an error
165:                                        cms.getRequestContext().setUri(
166:                                                cms.getSitePath(resource));
167:                                    }
168:                                }
169:                            }
170:                        }
171:                    }
172:                }
173:                return resource;
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.