All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cat.inspiracio.orange.Part Maven / Gradle / Ivy

Go to download

Orange-maven-plugin builds template files for use with orange-servlet. Orange Servlet provides HTML templating with server-side Java.

There is a newer version: 5.0.0
Show newest version
package cat.inspiracio.orange;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/** Some classes that help parsing source strings. 
 * 
 * Part has subclasses Literal and Expression. 
 * An expression is like "${o.getName()}" and everything else 
 * is Literal.
 * 
 * For example, 
 * 
 * 	

Name: ${o.getName()}

* * is a sequence: * * Literal("

Name: ") * Expression("o.getName()") * Literal("

") * */ abstract class Part{ String s; Part(String s){this.s=s;} abstract boolean isLiteral(); String getLiteral(){return s;} String getExpression(){return s;} @Override public boolean equals(Object o){ if(o==null) return false; if(!(o instanceof Part)) return false; Part p=(Part)o; return isLiteral()==p.isLiteral() && s.equals(p.s); } /** Factory: parse a string into literals and expressions. */ static Listparse(String s) throws IOException{ //opt: use StringBuilder Listparts=new ArrayList(); int start=s.indexOf("${"); while(0<=start){ //check that it's not \${...} boolean escaped = 1<=start && s.charAt(start-1)=='\\'; if(escaped){ //Must output $ for \$ // s[start-1] = \ // s[start] = $ // s[start+1] = { //delete \ s = s.substring(0, start-1) + s.substring(start); // look for the next ${ start=s.indexOf("${", start); } else if(!escaped){ int end=s.indexOf("}", start); if(-1==end){ //String location=getLocation(source); String message="Unterminated expression: " + s;// + " at " + location; throw new IOException(message); } //s[end] = '}' String prefix=s.substring(0, start); if(0




© 2015 - 2025 Weber Informatics LLC | Privacy Policy