001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime;
020
021import java.io.IOException;
022import java.io.Reader;
023
024import lucee.commons.io.CharsetUtil;
025import lucee.commons.io.IOUtil;
026import lucee.commons.io.res.Resource;
027
028public abstract class PagePlus extends Page {
029        
030        private Resource staticTextLocation;
031
032        public Object udfDefaultValue(PageContext pc, int functionIndex, int argumentIndex) {
033                return udfDefaultValue(pc, functionIndex, argumentIndex, null);
034        }
035        
036        public Object udfDefaultValue(PageContext pc, int functionIndex, int argumentIndex, Object defaultValue) {
037                return null;
038        }
039        
040        public String str(PageContext pc, int off, int len) throws IOException{
041                if(staticTextLocation==null) {
042                        PageSource ps = getPageSource();
043                        Mapping m = ps.getMapping();
044                        staticTextLocation=m.getClassRootDirectory();
045                        staticTextLocation=staticTextLocation.getRealResource(ps.getJavaName()+".txt");
046                }
047                
048                Reader reader = IOUtil.getReader(staticTextLocation, CharsetUtil.UTF8);
049                char[] carr=new char[len];
050                try {
051                        if(off>0)reader.skip(off);
052                        reader.read(carr);
053                }
054                finally {
055                        IOUtil.closeEL(reader);
056                }
057                
058                //print.e(carr);
059                return new String(carr);
060        }
061}