Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(402)

Unified Diff: src/com/google/caja/plugin/stages/CompileHtmlStage.java

Issue 61041: Cajole to HTML (Closed) Base URL: http://google-caja.googlecode.com/svn/trunk/
Patch Set: Cajole to HTML Created 14 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/com/google/caja/plugin/stages/CompileHtmlStage.java
===================================================================
--- src/com/google/caja/plugin/stages/CompileHtmlStage.java (revision 3513)
+++ src/com/google/caja/plugin/stages/CompileHtmlStage.java (working copy)
@@ -16,24 +16,26 @@
import com.google.caja.lang.css.CssSchema;
import com.google.caja.lang.html.HtmlSchema;
-import com.google.caja.lexer.FilePosition;
import com.google.caja.parser.AncestorChain;
+import com.google.caja.parser.css.CssTree;
+import com.google.caja.parser.html.DomParser;
import com.google.caja.parser.js.Block;
-import com.google.caja.parser.js.Statement;
-import com.google.caja.parser.js.TranslatedCode;
import com.google.caja.plugin.Dom;
-import com.google.caja.plugin.HtmlCompiler;
import com.google.caja.plugin.Job;
import com.google.caja.plugin.Jobs;
+import com.google.caja.plugin.templates.TemplateCompiler;
+import com.google.caja.plugin.templates.TemplateSanitizer;
+import com.google.caja.reporting.MessageQueue;
+import com.google.caja.util.Pair;
import com.google.caja.util.Pipeline;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
+import org.w3c.dom.Node;
/**
- * Compile the html and add a method to the plugin for the
- * html and one for each extracted script tag and event handler.
+ * Compile the HTML and CSS to javascript.
*
* @author mikesamuel@gmail.com
*/
@@ -49,44 +51,40 @@
}
public boolean apply(Jobs jobs) {
- HtmlCompiler htmlc = new HtmlCompiler(
- cssSchema, htmlSchema, jobs.getMessageContext(), jobs.getMessageQueue(),
- jobs.getPluginMeta());
+ List<Node> ihtmlRoots = new ArrayList<Node>();
+ List<CssTree.StyleSheet> stylesheets = new ArrayList<CssTree.StyleSheet>();
- List<Statement> renderedHtmlStatements = new ArrayList<Statement>();
-
- ListIterator<Job> it = jobs.getJobs().listIterator();
- while (it.hasNext()) {
- Job job = it.next();
- if (Job.JobType.HTML != job.getType()) { continue; }
-
- it.remove();
- try {
- renderedHtmlStatements.add(
- htmlc.compileDocument(((Dom) job.getRoot().node).getValue()));
- } catch (HtmlCompiler.BadContentException ex) {
- ex.toMessageQueue(jobs.getMessageQueue());
+ for (Iterator<Job> jobIt = jobs.getJobs().iterator(); jobIt.hasNext();) {
+ Job job = jobIt.next();
+ switch (job.getType()) {
+ case HTML:
+ ihtmlRoots.add(job.getRoot().cast(Dom.class).node.getValue());
+ jobIt.remove();
+ break;
+ case CSS:
+ stylesheets.add(job.getRoot().cast(CssTree.StyleSheet.class).node);
+ jobIt.remove();
+ break;
+ default: break;
}
}
- if (!htmlc.getEventHandlers().isEmpty()) {
- TranslatedCode compiledHtml = new TranslatedCode(new Block(
- FilePosition.UNKNOWN,
- new ArrayList<Statement>(htmlc.getEventHandlers())));
- jobs.getJobs().add(new Job(AncestorChain.instance(compiledHtml)));
- }
+ MessageQueue mq = jobs.getMessageQueue();
- if (!renderedHtmlStatements.isEmpty()) {
- Block htmlGeneration;
- if (renderedHtmlStatements.size() == 1
- && renderedHtmlStatements.get(0) instanceof Block) {
- htmlGeneration = (Block) renderedHtmlStatements.get(0);
- } else {
- htmlGeneration = new Block(
- FilePosition.UNKNOWN, renderedHtmlStatements);
- }
- jobs.getJobs().add(new Job(AncestorChain.instance(htmlGeneration)));
+ TemplateSanitizer ts = new TemplateSanitizer(htmlSchema, mq);
+ for (Node ihtmlRoot : ihtmlRoots) { ts.sanitize(ihtmlRoot); }
+ TemplateCompiler tc = new TemplateCompiler(
+ ihtmlRoots, stylesheets, cssSchema, htmlSchema,
+ jobs.getPluginMeta(), jobs.getMessageContext(), mq);
+ tc.inspect();
+ Pair<Node, List<Block>> htmlAndJs = tc.getSafeHtml(
+ DomParser.makeDocument(null, null));
+
+ jobs.getJobs().add(new Job(AncestorChain.instance(new Dom(htmlAndJs.a))));
+ for (Block bl : htmlAndJs.b) {
+ jobs.getJobs().add(new Job(AncestorChain.instance(bl)));
}
+
return jobs.hasNoFatalErrors();
}
}

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b