|
| 1 | +/* |
| 2 | + * Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.ocpsoft.rewrite.showcase.transform; |
| 17 | + |
| 18 | +import javax.servlet.ServletContext; |
| 19 | + |
| 20 | +import org.ocpsoft.rewrite.config.Configuration; |
| 21 | +import org.ocpsoft.rewrite.config.ConfigurationBuilder; |
| 22 | +import org.ocpsoft.rewrite.config.Direction; |
| 23 | +import org.ocpsoft.rewrite.servlet.config.Forward; |
| 24 | +import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider; |
| 25 | +import org.ocpsoft.rewrite.servlet.config.Path; |
| 26 | +import org.ocpsoft.rewrite.servlet.config.Resource; |
| 27 | +import org.ocpsoft.rewrite.transform.Transform; |
| 28 | +import org.ocpsoft.rewrite.transform.less.Less; |
| 29 | +import org.ocpsoft.rewrite.transform.markup.Markdown; |
| 30 | +import org.ocpsoft.rewrite.transform.markup.Sass; |
| 31 | +import org.ocpsoft.rewrite.transform.markup.Textile; |
| 32 | + |
| 33 | +public class TransformConfigurationProvider extends HttpConfigurationProvider |
| 34 | +{ |
| 35 | + |
| 36 | + @Override |
| 37 | + public Configuration getConfiguration(ServletContext context) |
| 38 | + { |
| 39 | + return ConfigurationBuilder.begin() |
| 40 | + |
| 41 | + // Markdown |
| 42 | + .addRule() |
| 43 | + .when(Direction.isInbound() |
| 44 | + .and(Path.matches("/markdown/{name}.html")) |
| 45 | + .and(Resource.exists("/markdown/{name}.md"))) |
| 46 | + .perform(Forward.to("/markdown/{name}.md") |
| 47 | + .and(Transform.with(Markdown.fullDocument() |
| 48 | + .withTitle("Markdown Demo") |
| 49 | + .addStylesheet(context.getContextPath() + "/common/bootstrap.css") |
| 50 | + .addStylesheet(context.getContextPath() + "/common/common.css")))) |
| 51 | + |
| 52 | + // Textile |
| 53 | + .addRule() |
| 54 | + .when(Direction.isInbound() |
| 55 | + .and(Path.matches("/textile/{name}.html")) |
| 56 | + .and(Resource.exists("/textile/{name}.textile"))) |
| 57 | + .perform(Forward.to("/textile/{name}.textile") |
| 58 | + .and(Transform.with(Textile.fullDocument() |
| 59 | + .withTitle("Textile Demo") |
| 60 | + .addStylesheet(context.getContextPath() + "/common/bootstrap.css") |
| 61 | + .addStylesheet(context.getContextPath() + "/common/common.css")))) |
| 62 | + |
| 63 | + // LESS |
| 64 | + .addRule() |
| 65 | + .when(Direction.isInbound() |
| 66 | + .and(Path.matches("/less/{name}.css")) |
| 67 | + .and(Resource.exists("/less/{name}.less"))) |
| 68 | + .perform(Forward.to("/less/{name}.less") |
| 69 | + .and(Transform.with(Less.compiler()))) |
| 70 | + |
| 71 | + // Sass |
| 72 | + .addRule() |
| 73 | + .when(Direction.isInbound() |
| 74 | + .and(Path.matches("/sass/{name}.css")) |
| 75 | + .and(Resource.exists("/sass/{name}.scss"))) |
| 76 | + .perform(Forward.to("/sass/{name}.scss") |
| 77 | + .and(Transform.with(Sass.compiler()))); |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public int priority() |
| 83 | + { |
| 84 | + return 0; |
| 85 | + } |
| 86 | + |
| 87 | +} |
0 commit comments