Source Code Cross Referenced for SvnFileViewerController.java in  » Project-Management » EmForce » ru » emdev » EmForge » svn » web » 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 » Project Management » EmForce » ru.emdev.EmForge.svn.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package ru.emdev.EmForge.svn.web;
002:
003:        import java.io.BufferedOutputStream;
004:        import java.io.ByteArrayOutputStream;
005:        import java.io.IOException;
006:        import java.util.Collection;
007:        import java.util.HashMap;
008:        import java.util.Map;
009:
010:        import javax.faces.context.FacesContext;
011:        import javax.servlet.http.HttpServletResponse;
012:
013:        import org.tmatesoft.svn.core.SVNException;
014:        import org.tmatesoft.svn.core.SVNProperty;
015:
016:        import ru.emdev.EmForge.web.bean.MainMenuController.MainMenuItem;
017:        import ru.emdev.EmForge.wiki.web.bean.Crumb;
018:
019:        /**
020:         * Subversion file viewer (svnfileviewer.xhtml) backing bean
021:         * 
022:         * @author Walter Mourao
023:         *
024:         */
025:        public class SvnFileViewerController extends SvnBaseController {
026:
027:            public static final String TITLE = "File viewer";
028:
029:            @Override
030:            public MainMenuItem getSelectionItemOnMainMenu() {
031:                return MainMenuItem.SOURCES;
032:            }
033:
034:            @Override
035:            public String getTitleImpl() {
036:                return TITLE;
037:            }
038:
039:            @Override
040:            public Crumb getTrailCrumbInfo() {
041:                return null;
042:            }
043:
044:            @Override
045:            protected void init() {
046:                super .init();
047:
048:                fileContentLines = null;
049:                resourceProperties = null;
050:                commitMessage = null;
051:                fileTextType = false;
052:                binaryFileContent = null;
053:                fileContent = null;
054:                lastRevision = null;
055:                size = 0;
056:                strSize = null;
057:                author = null;
058:                age = null;
059:                date = null;
060:
061:                loadFileContent();
062:            }
063:
064:            //********* controller code ********//
065:
066:            /**
067:             * Fills the relevante properties
068:             * 
069:             */
070:            private void loadFileContent() {
071:
072:                binaryFileContent = new ByteArrayOutputStream();
073:
074:                final Map fileProperties = new HashMap();
075:                final long fileRevision = Helper
076:                        .getCurrentRevision(getRevision());
077:
078:                try {
079:                    getSvnRepository().getFile(getPath(), fileRevision,
080:                            fileProperties, binaryFileContent);
081:                } catch (SVNException e) {
082:                    this .addErrorMessage("Subversion error", e
083:                            .getLocalizedMessage());
084:                    logger.error(e.getLocalizedMessage());
085:                    binaryFileContent = null;
086:                    return;
087:                }
088:
089:                mimeType = (String) fileProperties.get(SVNProperty.MIME_TYPE);
090:                fileTextType = SVNProperty.isTextMimeType(mimeType);
091:
092:                resourceProperties = new java.util.ArrayList<String[]>();
093:                for (java.util.Iterator it = fileProperties.keySet().iterator(); it
094:                        .hasNext();) {
095:                    final String key = (String) it.next();
096:
097:                    if (Helper.isUserProperty(key))//filters only user properties.
098:                        resourceProperties.add(new String[] { key,
099:                                fileProperties.get(key).toString() });
100:                }
101:
102:                SvnDataVO[] svnDataArray = null;
103:                try {
104:                    svnDataArray = Helper
105:                            .listEntries(getSvnRepository(), Helper
106:                                    .dirPathFromFilePath(getPath()),
107:                                    fileRevision);
108:                } catch (SVNException e) {
109:                    this .addErrorMessage("Subversion error", e
110:                            .getLocalizedMessage());
111:                    logger.error(e.getLocalizedMessage(), e);
112:                    binaryFileContent = null;
113:                    return;
114:                }
115:
116:                SvnDataVO svnData = null;
117:
118:                for (int i = 0; i < svnDataArray.length; i++) {
119:                    if (svnDataArray[i].getPath().equals(getPath())) {
120:                        svnData = svnDataArray[i];
121:                        break;
122:                    }
123:                }
124:
125:                if (svnData != null) {
126:                    commitMessage = svnData.getCommitMessage();
127:                    lastRevision = svnData.getRevision();
128:                    size = svnData.getSize();
129:                    strSize = svnData.getStrSize();
130:                    author = svnData.getAuthor();
131:                    age = svnData.getAge();
132:                    date = svnData.getDate();
133:                } else {
134:                    logger.warn("Cannot get svn data for " + getPath()
135:                            + " revision " + fileRevision);
136:                }
137:            }
138:
139:            /**
140:             * Responses the "download" link
141:             */
142:            public void download() {
143:                final FacesContext context = FacesContext.getCurrentInstance();
144:
145:                final int contentLength = binaryFileContent.size();
146:
147:                HttpServletResponse response = (HttpServletResponse) context
148:                        .getExternalContext().getResponse();
149:                response.setContentType("application/octet-stream");
150:                response.setContentLength(contentLength);
151:                response.setHeader("Content-disposition", "inline; filename=\""
152:                        + Helper.fileNameFromFilePath(getPath()) + "\"");
153:
154:                try {
155:                    // Write file contents to the response
156:                    final BufferedOutputStream output = new BufferedOutputStream(
157:                            response.getOutputStream());
158:
159:                    output.write(binaryFileContent.toByteArray());
160:
161:                    output.flush();
162:                } catch (IOException e) {
163:                    this .addErrorMessage("Download error", e
164:                            .getLocalizedMessage());
165:                    logger.error(e.getLocalizedMessage(), e);
166:                }
167:
168:                context.responseComplete();
169:            }
170:
171:            //********* attributes ***********//
172:
173:            /**
174:             * The current file mime type
175:             */
176:            private String mimeType;
177:
178:            public String getMimeType() {
179:                return mimeType;
180:            }
181:
182:            /**
183:             * The revision commit message
184:             */
185:            private String commitMessage;
186:
187:            public String getCommitMessage() {
188:                return commitMessage;
189:            }
190:
191:            /**
192:             * Holds the file content
193:             */
194:            private ByteArrayOutputStream binaryFileContent;
195:
196:            public ByteArrayOutputStream getBinaryFileContent() {
197:                return binaryFileContent;
198:            }
199:
200:            /**
201:             * Holds the file content in String format
202:             */
203:            private String fileContent;
204:
205:            public String getFileContent() {
206:                if (binaryFileContent == null)
207:                    return null;
208:                else {
209:                    if (fileContent == null)
210:                        fileContent = binaryFileContent.toString();
211:
212:                    return fileContent;
213:                }
214:            }
215:
216:            /**
217:             * True if it is a text file.
218:             */
219:            private boolean fileTextType;
220:
221:            public boolean isFileTextType() {
222:                return fileTextType;
223:            }
224:
225:            /**
226:             * The setted user properties
227:             */
228:            private Collection<String[]> resourceProperties;
229:
230:            public Collection<String[]> getResourceProperties() {
231:                return resourceProperties;
232:            }
233:
234:            /**
235:             * The file content splitted into lines, if it is a text file, null if it is a binary file.
236:             */
237:            private String[] fileContentLines;
238:
239:            public String[] getFileContentLines() {
240:                if (getFileContent() != null)
241:                    fileContentLines = fileContent.split("\n");
242:
243:                return fileContentLines;
244:            }
245:
246:            /**
247:             * The file revision text info
248:             */
249:            String lastRevision;
250:            long size;
251:            String strSize;
252:            String author;
253:            String age;
254:            java.util.Date date;
255:
256:            public String getAge() {
257:                return age;
258:            }
259:
260:            public String getAuthor() {
261:                return author;
262:            }
263:
264:            public java.util.Date getDate() {
265:                return date;
266:            }
267:
268:            public String getLastRevision() {
269:                return lastRevision;
270:            }
271:
272:            public long getSize() {
273:                return size;
274:            }
275:
276:            public String getStrSize() {
277:                return strSize;
278:            }
279:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.