Source Code Cross Referenced for ResourceCompiler.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:        /* -*- mode: Java; c-basic-offset: 2; -*- */
002:
003:        /**
004:         * LZX Resource Compiler
005:         */package org.openlaszlo.compiler;
006:
007:        import org.openlaszlo.xml.internal.XMLUtils;
008:        import org.openlaszlo.sc.ScriptCompiler;
009:        import org.jdom.Element;
010:        import java.io.File;
011:        import java.io.FileNotFoundException;
012:        import java.util.*;
013:        import org.apache.log4j.*;
014:
015:        /** 
016:         * Compiler for resource and audio elements.
017:         *
018:         * @author Oliver Steele
019:         */
020:        class ResourceCompiler extends ElementCompiler {
021:
022:            Logger mLogger = Logger.getLogger(ResourceCompiler.class);
023:
024:            ResourceCompiler(CompilationEnvironment env) {
025:                super (env);
026:            }
027:
028:            /** Returns true iff this class applies to this element.
029:             * @param element an element
030:             * @return see doc
031:             */
032:            static boolean isElement(Element element) {
033:                String name = element.getName();
034:                return name.equals("resource") || name.equals("audio");
035:            }
036:
037:            /*
038:             * @see <code>CompilerNode</code>
039:             * @param env a compilation environment
040:             */
041:            public void compile(Element element) throws CompilationError {
042:                File file = null;
043:
044:                if (!element.getChildren().isEmpty()) {
045:                    file = mEnv.resolveParentReference(element);
046:                } else {
047:                    file = mEnv.resolveReference(element);
048:                }
049:
050:                if (element.getAttribute("src") != null) {
051:                    Element info = new Element("resolve");
052:                    info.setAttribute("src", element.getAttributeValue("src"));
053:                    try {
054:                        info.setAttribute("pathname", file.getCanonicalPath());
055:                    } catch (java.io.IOException ioe) {
056:                        mLogger.warn(
057:                        /* (non-Javadoc)
058:                         * @i18n.test
059:                         * @org-mes="Can't canonicalize " + p[0]
060:                         */
061:                        org.openlaszlo.i18n.LaszloMessages.getMessage(
062:                                ResourceCompiler.class.getName(), "051018-69",
063:                                new Object[] { file.toString() }));
064:                    }
065:                    if (mEnv.isCanvas()) {
066:                        mEnv.getCanvas().addInfo(info);
067:                    }
068:                }
069:
070:                String tagName = element.getName();
071:                try {
072:                    if (tagName.equals("resource")
073:                            || tagName.equals("preloadresource")) {
074:                        String name = element.getAttributeValue("name");
075:                        String src = element.getAttributeValue("src");
076:
077:                        if (name == null) {
078:                            throw new CompilationError(
079:                            /* (non-Javadoc)
080:                             * @i18n.test
081:                             * @org-mes="You must supply a value for the 'name' attribute, and it must be a valid Javascript identifier."
082:                             */
083:                            org.openlaszlo.i18n.LaszloMessages.getMessage(
084:                                    ResourceCompiler.class.getName(),
085:                                    "051018-88"), element);
086:                        }
087:
088:                        if (!ScriptCompiler.isIdentifier(name)) {
089:                            mEnv.warn(
090:                            /* (non-Javadoc)
091:                             * @i18n.test
092:                             * @org-mes="Resource names must be valid Javascript identifiers. The resource name '" + p[0] + "' is not a valid Javascript identifier"
093:                             */
094:                            org.openlaszlo.i18n.LaszloMessages.getMessage(
095:                                    ResourceCompiler.class.getName(),
096:                                    "051018-99", new Object[] { name }),
097:                                    element);
098:                        }
099:
100:                        // TODO: [1-02-2003 ows]
101:                        // XMLUtils.requireAttributeValue should work here,
102:                        // and the caller should add the source location info
103:                        if (name == null)
104:                            throw new CompilationError(
105:                            /* (non-Javadoc)
106:                             * @i18n.test
107:                             * @org-mes="resource name is required"
108:                             */
109:                            org.openlaszlo.i18n.LaszloMessages.getMessage(
110:                                    ResourceCompiler.class.getName(),
111:                                    "051018-113"), element);
112:
113:                        Set resourceNames = mEnv.getResourceNames();
114:                        if (false) {
115:                            if (resourceNames.contains(name)) {
116:                                mEnv.warn(
117:                                /* (non-Javadoc)
118:                                 * @i18n.test
119:                                 * @org-mes="The resource name '" + p[0] + "' has already been defined"
120:                                 */
121:                                org.openlaszlo.i18n.LaszloMessages.getMessage(
122:                                        ResourceCompiler.class.getName(),
123:                                        "051018-124", new Object[] { name }),
124:                                        element);
125:                            }
126:                        }
127:                        resourceNames.add(name);
128:
129:                        // Check if children are valid tags to be contained 
130:                        mEnv.checkValidChildContainment(element);
131:
132:                        // N.B.: Resources are always imported into the main
133:                        // program for the Flash target, hence the use of
134:                        // getResourceGenerator below
135:                        if (src == null) {
136:                            List sources = new Vector();
137:                            for (Iterator iter = element.getChildren("frame",
138:                                    element.getNamespace()).iterator(); iter
139:                                    .hasNext();) {
140:                                Element child = (Element) iter.next();
141:                                mEnv.resolveReference(child);
142:
143:                                // throw error if 'src' attribute not found
144:                                XMLUtils.requireAttributeValue(child, "src");
145:                                File pathname = mEnv.resolveReference(child);
146:                                sources.add(pathname.getAbsolutePath());
147:
148:                                Element rinfo = new Element("resolve");
149:                                rinfo.setAttribute("src", child
150:                                        .getAttributeValue("src"));
151:                                rinfo.setAttribute("pathname", pathname
152:                                        .toString());
153:                                if (mEnv.isCanvas()) {
154:                                    mEnv.getCanvas().addInfo(rinfo);
155:                                }
156:                            }
157:                            if (!sources.isEmpty()) {
158:                                if (tagName.equals("preloadresource")) {
159:                                    mEnv.getResourceGenerator()
160:                                            .importPreloadResource(sources,
161:                                                    name, file);
162:                                } else {
163:                                    mEnv.getResourceGenerator().importResource(
164:                                            sources, name, file);
165:                                }
166:                            } else {
167:                                throw new CompilationError(
168:                                /* (non-Javadoc)
169:                                 * @i18n.test
170:                                 * @org-mes="required src or children"
171:                                 */
172:                                org.openlaszlo.i18n.LaszloMessages.getMessage(
173:                                        ResourceCompiler.class.getName(),
174:                                        "051018-162"), element);
175:                            }
176:                        } else {
177:                            if (tagName.equals("preloadresource")) {
178:                                mEnv.getResourceGenerator()
179:                                        .importPreloadResource(
180:                                                file.getAbsolutePath(), name);
181:                            } else {
182:                                mEnv.getResourceGenerator().importResource(
183:                                        file.getAbsolutePath(), name);
184:                            }
185:                        }
186:                        return;
187:                    } else if (tagName.equals("audio")) {
188:                        String name = XMLUtils.requireAttributeValue(element,
189:                                "name");
190:                        mEnv.getResourceGenerator().importResource(
191:                                file.getAbsolutePath(), name);
192:                        return;
193:                    } else {
194:                        // Program error: this shouldn't happen
195:                        throw new RuntimeException(
196:                        /* (non-Javadoc)
197:                         * @i18n.test
198:                         * @org-mes="Unknown resource tag: " + p[0]
199:                         */
200:                        org.openlaszlo.i18n.LaszloMessages.getMessage(
201:                                ResourceCompiler.class.getName(), "051018-188",
202:                                new Object[] { element.getName() }));
203:                    }
204:                } catch (SWFWriter.ImportResourceError e) {
205:                    mEnv.warn(e, element);
206:                    return;
207:                }
208:            }
209:        }
210:
211:        /**
212:         * @copyright Copyright 2001-2007 Laszlo Systems, Inc.  All Rights
213:         * Reserved.  Use is subject to license terms.
214:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.