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

com.tsc9526.monalisa.tools.template.jsp.Jsp Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
/*******************************************************************************************
 *	Copyright (c) 2016, zzg.zhou([email protected])
 * 
 *  Monalisa is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU Lesser General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.

 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU Lesser General Public License for more details.

 *	You should have received a copy of the GNU Lesser General Public License
 *	along with this program.  If not, see .
 *******************************************************************************************/
package com.tsc9526.monalisa.tools.template.jsp;

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

import com.tsc9526.monalisa.tools.io.MelpFile;

/**
 * 
 * @author zzg.zhou([email protected])
 */
public class Jsp{
	public static String DEFAULT_PAGE_ENCODING ="utf-8";
	 
	private String filePath;
	private String body;
	private List elements=new ArrayList();
	
	private long lastModified;
	
	public Jsp(File jspFile) {
		parseFile(jspFile);
	}
	
	public Jsp(String body){
		if(body.indexOf("\n")<0 && new File(body).exists()){
			parseFile(new File(body));
		}else{
			parseBody(body);
		}
	}
	
	protected void parseFile(File jspFile){
		try{
			this.filePath=jspFile.getAbsolutePath();
			this.lastModified=jspFile.lastModified();
			
			String body=MelpFile.readToString(new FileInputStream(filePath), DEFAULT_PAGE_ENCODING);
			
			parseBody(body);
			
			String encoding=getPageEncoding();
			if(!DEFAULT_PAGE_ENCODING.equalsIgnoreCase(encoding)){
				elements.clear();
				body=MelpFile.readToString(new FileInputStream(filePath), encoding);			
				parseBody(body);
			}
		}catch(IOException e){
			throw new RuntimeException(e);
		}
	}
	
	
	public String getPageEncoding(){
		String pageEncoding=null;
		for(JspElement e:elements){
			if(e instanceof JspPage){
				pageEncoding=((JspPage)e).getPageEncoding();
				if(pageEncoding!=null){
					return pageEncoding;
				}
			}
		}
		return DEFAULT_PAGE_ENCODING;
	}
	
	
	public void process(JspContext context,JspPageOut out){
		 String className=context.getParameter("$$CLASS_NAME$$");
		 if(className==null){
			 
		 }
	}
	
	
	protected void parseBody(String body){
		this.body=body;
		
		int len=body.length();
		for(int i=0;i",i);
				 
				if(i getElements() {
		return elements;
	}

	public long getLastModified() {
		return lastModified;
	}

	public void setLastModified(long lastModified) {
		this.lastModified = lastModified;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy