Source Code Cross Referenced for CompilerMediaCache.java in  » Ajax » Laszlo-4.0.10 » org » openlaszlo » compiler » 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 » Ajax » Laszlo 4.0.10 » org.openlaszlo.compiler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* *****************************************************************************
002:         * CompilerMediaCache.java
003:         * ****************************************************************************/
004:
005:        /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006:         * Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
007:         * Use is subject to license terms.                                            *
008:         * J_LZ_COPYRIGHT_END *********************************************************/
009:
010:        package org.openlaszlo.compiler;
011:
012:        import org.openlaszlo.media.Transcoder;
013:        import org.openlaszlo.media.TranscoderException;
014:        import org.openlaszlo.cache.Cache;
015:        import org.openlaszlo.cache.CachedInfo;
016:        import org.openlaszlo.utils.FileUtils;
017:        import org.openlaszlo.server.LPS;
018:
019:        import org.apache.log4j.*;
020:
021:        import java.util.Properties;
022:        import java.io.File;
023:        import java.io.IOException;
024:        import java.io.FileNotFoundException;
025:        import java.io.InputStream;
026:        import java.io.FileOutputStream;
027:
028:        /**
029:         * A class for maintaining a disk-backed cache of transcoded media
030:         * files for the compiler.
031:         *
032:         * @author <a href="mailto:bloch@laszlosystems.com">Eric Bloch</a>
033:         */
034:        public class CompilerMediaCache extends Cache {
035:
036:            /** Logger. */
037:            private static Logger mLogger = Logger
038:                    .getLogger(CompilerMediaCache.class);
039:
040:            /** Properties */
041:            private static Properties mProperties = null;
042:
043:            /** See the constructor. */
044:            protected File mCacheDirectory;
045:
046:            /**
047:             * Creates a new <code>CompilerMediaCache</code> instance.
048:             */
049:            public CompilerMediaCache(File cacheDirectory, Properties props)
050:                    throws IOException {
051:                super ("cmcache", cacheDirectory, props);
052:                this .mCacheDirectory = cacheDirectory;
053:                if (props == null) {
054:                    this .mProperties = new Properties();
055:                } else {
056:                    this .mProperties = props;
057:                }
058:
059:            }
060:
061:            /**
062:             * Return properties object
063:             * There is one property <code>forcetranscode</code>
064:             * which when set to <code>true</code> will force the
065:             * cache to always transcode requests.
066:             */
067:            public Properties getProperties() {
068:                return mProperties;
069:            }
070:
071:            /**
072:             * Transcode the given input file from the fromType to toType
073:             * @return the transcoded file
074:             * @param inputFile file to be transcoded
075:             * @param fromType type of file to be transcoded
076:             * @param toType type of file to transcode into
077:             */
078:            public synchronized File transcode(File inputFile, String fromType,
079:                    String toType) throws TranscoderException,
080:                    FileNotFoundException, IOException {
081:
082:                mLogger.debug(
083:                /* (non-Javadoc)
084:                 * @i18n.test
085:                 * @org-mes="transcoding from " + p[0] + " to " + p[1]
086:                 */
087:                org.openlaszlo.i18n.LaszloMessages.getMessage(
088:                        CompilerMediaCache.class.getName(), "051018-90",
089:                        new Object[] { fromType, toType }));
090:                if (fromType.equalsIgnoreCase(toType)) {
091:                    return inputFile;
092:                }
093:
094:                if (!inputFile.exists()) {
095:                    throw new FileNotFoundException(inputFile.getPath());
096:                }
097:
098:                // Key should be relative to webapp path and have
099:                // consistent path separator
100:                String key = FileUtils.relativePath(inputFile, LPS.HOME())
101:                        + ":" + toType;
102:
103:                /* we don't use the cache's encoding support; we do it ourselves */
104:                String enc = null;
105:                boolean lockit = false;
106:                Item item = findItem(key, null, lockit);
107:
108:                String inputFilePath = inputFile.getAbsolutePath();
109:                File cacheFile = item.getFile();
110:                String cacheFilePath = cacheFile.getAbsolutePath();
111:                mLogger.debug(
112:                /* (non-Javadoc)
113:                 * @i18n.test
114:                 * @org-mes="transcoding input: " + p[0] + " output: " + p[1]
115:                 */
116:                org.openlaszlo.i18n.LaszloMessages.getMessage(
117:                        CompilerMediaCache.class.getName(), "051018-118",
118:                        new Object[] { inputFilePath, cacheFilePath }));
119:
120:                InputStream input = null;
121:                FileOutputStream output = null;
122:
123:                if (!cacheFile.exists()
124:                        || !inputFile.canRead()
125:                        || inputFile.lastModified() > cacheFile.lastModified()
126:                        || mProperties.getProperty("forcetranscode", "false") == "true") {
127:
128:                    item.markDirty();
129:
130:                    mLogger.debug(
131:                    /* (non-Javadoc)
132:                     * @i18n.test
133:                     * @org-mes="transcoding..."
134:                     */
135:                    org.openlaszlo.i18n.LaszloMessages.getMessage(
136:                            CompilerMediaCache.class.getName(), "051018-135"));
137:
138:                    CachedInfo info = item.getInfo();
139:                    try {
140:                        input = Transcoder.transcode(inputFile, fromType,
141:                                toType);
142:                        mLogger.debug(
143:                        /* (non-Javadoc)
144:                         * @i18n.test
145:                         * @org-mes="done transcoding"
146:                         */
147:                        org.openlaszlo.i18n.LaszloMessages.getMessage(
148:                                CompilerMediaCache.class.getName(),
149:                                "051018-147"));
150:                        item.update(input, null);
151:                        info.setLastModified(cacheFile.lastModified());
152:                        item.updateInfo();
153:                        item.markClean();
154:                    } finally {
155:                        FileUtils.close(input);
156:                    }
157:                } else {
158:                    mLogger.debug(
159:                    /* (non-Javadoc)
160:                     * @i18n.test
161:                     * @org-mes="using cached transcode"
162:                     */
163:                    org.openlaszlo.i18n.LaszloMessages.getMessage(
164:                            CompilerMediaCache.class.getName(), "051018-163"));
165:                }
166:
167:                updateCache(item);
168:
169:                return cacheFile;
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.