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.config;
020
021import java.io.IOException;
022import java.io.PrintWriter;
023import java.net.URL;
024import java.util.Locale;
025import java.util.Map;
026import java.util.TimeZone;
027
028import lucee.commons.io.log.LogAndSource;
029import lucee.commons.io.res.Resource;
030import lucee.commons.io.res.ResourceProvider;
031import lucee.runtime.CFMLFactory;
032import lucee.runtime.Mapping;
033import lucee.runtime.PageContext;
034import lucee.runtime.PageSource;
035import lucee.runtime.cache.CacheConnection;
036import lucee.runtime.cfx.CFXTagPool;
037import lucee.runtime.db.DataSource;
038import lucee.runtime.dump.DumpWriter;
039import lucee.runtime.engine.ThreadQueue;
040import lucee.runtime.exp.PageException;
041import lucee.runtime.extension.Extension;
042import lucee.runtime.extension.ExtensionProvider;
043import lucee.runtime.listener.ApplicationListener;
044import lucee.runtime.monitor.IntervallMonitor;
045import lucee.runtime.monitor.RequestMonitor;
046import lucee.runtime.net.mail.Server;
047import lucee.runtime.net.proxy.ProxyData;
048import lucee.runtime.rest.RestSettings;
049import lucee.runtime.schedule.Scheduler;
050import lucee.runtime.search.SearchEngine;
051import lucee.runtime.security.SecurityManager;
052import lucee.runtime.spooler.SpoolerEngine;
053import lucee.runtime.type.Struct;
054import lucee.runtime.type.dt.TimeSpan;
055
056/**
057 * interface for Config Object 
058 */
059public interface Config {
060
061    /**
062     * Define a strict scope cascading
063     */
064    public static final short SCOPE_STRICT = 0;
065
066    /**
067     * Define a small scope cascading
068     */
069    public static final short SCOPE_SMALL = 1;
070
071    /**
072     * Define a standart scope cascading (like other cf versions)
073     */
074    public static final short SCOPE_STANDARD = 2;
075
076    /**
077     * Field <code>CLIENT_SCOPE_TYPE_COOKIE</code>
078     */
079    public static final short CLIENT_SCOPE_TYPE_COOKIE = 0;
080
081    /**
082     * Field <code>CLIENT_SCOPE_TYPE_FILE</code>
083     */
084    public static final short CLIENT_SCOPE_TYPE_FILE = 1;
085
086    /**
087     * Field <code>CLIENT_SCOPE_TYPE_DB</code>
088     */
089    public static final short CLIENT_SCOPE_TYPE_DB = 2;
090
091    /**
092     * Field <code>SESSION_TYPE_CFML</code>
093     */
094    public static final short SESSION_TYPE_CFML = 0;
095
096    /**
097     * Field <code>SESSION_TYPE_J2EE</code>
098     */
099    public static final short SESSION_TYPE_J2EE = 1;
100    
101
102    /**
103     * Field <code>RECOMPILE_NEVER</code>
104     */
105    public static final short RECOMPILE_NEVER = 0;
106    /**
107     * Field <code>RECOMPILE_AT_STARTUP</code>
108     */
109    public static final short RECOMPILE_AFTER_STARTUP = 1;
110    /**
111     * Field <code>RECOMPILE_ALWAYS</code>
112     */
113    public static final short RECOMPILE_ALWAYS = 2;
114    
115
116        public static final short INSPECT_ALWAYS = 0;
117        public static final short INSPECT_ONCE = 1;
118        public static final short INSPECT_NEVER = 2;
119        // Hibernate Extension has hardcoded this 4, do not change!!!!
120
121    /*public static final int CUSTOM_TAG_MODE_NONE = 0;
122    public static final int CUSTOM_TAG_MODE_CLASSIC = 1;
123    public static final int CUSTOM_TAG_MODE_MODERN = 2;
124    public static final int CUSTOM_TAG_MODE_CLASSIC_MODERN = 4;
125    public static final int CUSTOM_TAG_MODE_MODERN_CLASSIC = 8;
126    */
127        
128        public static final int CACHE_DEFAULT_NONE = 0;
129        public static final int CACHE_DEFAULT_OBJECT = 1;
130        public static final int CACHE_DEFAULT_TEMPLATE = 2;
131        public static final int CACHE_DEFAULT_QUERY = 4;
132        public static final int CACHE_DEFAULT_RESOURCE = 8;
133        public static final int CACHE_DEFAULT_FUNCTION = 16;
134        public static final int CACHE_DEFAULT_INCLUDE = 32;
135
136        
137        
138        public short getInspectTemplate();
139    
140        public String getDefaultDataSource();
141
142    /**
143     * return how lucee cascade scopes
144     * @return type of cascading
145     */
146    public abstract short getScopeCascadingType();
147
148    /**
149     * return cfml extesnion
150     * @return cfml extension
151     */
152    public abstract String[] getCFMLExtensions();
153    
154    public abstract String getCFCExtension();
155
156    /**
157     * return the mapping to custom tag directory
158     * @return custom tag directory
159     */
160    public abstract Mapping[] getCustomTagMappings();
161
162    /**
163     * return if it is allowed to implizid query call, call a query member witot define name of the query. 
164     * @return is allowed
165     */
166    public abstract boolean allowImplicidQueryCall();
167
168    /**e merged
169     * return if url and form scope will b
170     * @return merge or not
171     */
172    public abstract boolean mergeFormAndURL();
173    
174
175    /**
176     * @return Returns the application Timeout.
177     */
178    public abstract TimeSpan getApplicationTimeout();
179
180    /**
181     * @return Returns the session Timeout.
182     */
183    public abstract TimeSpan getSessionTimeout();
184    
185    /**
186     * @return Returns the client Timeout.
187     */
188    public TimeSpan getClientTimeout();
189
190    /**
191     * @return Returns the request Timeout.
192     */
193    public abstract TimeSpan getRequestTimeout();
194
195    /**
196     * @return Returns the clientCookies.
197     */
198    public abstract boolean isClientCookies();
199
200    /**
201     * @return Returns the clientManagement.
202     */
203    public abstract boolean isClientManagement();
204
205    /**
206     * @return Returns the domainCookies.
207     */
208    public abstract boolean isDomainCookies();
209
210    /**
211     * @return Returns the sessionManagement.
212     */
213    public abstract boolean isSessionManagement();
214
215    /**
216     * @return Returns the spoolEnable.
217     */
218    public abstract boolean isMailSpoolEnable();
219
220    /**
221     * @return Returns the mailTimeout.
222     */
223    public abstract int getMailTimeout();
224
225    /**
226     * @return preserve single quotes in cfquery tag or not
227     */
228    public abstract boolean getPSQL();
229
230    /**
231     * @return Returns the locale.
232     */
233    public abstract Locale getLocale();
234
235    /**
236     * return if debug output will be generated
237     * @return debug or not
238     */
239    public abstract boolean debug();
240
241    /**
242     * return the temp directory
243     * @return temp directory
244     */
245    public abstract Resource getTempDirectory();
246
247    /**
248     * @return Returns the spoolInterval.
249     */
250    public abstract int getMailSpoolInterval();
251
252    /**
253     * @return returns the time zone for this 
254     */
255    public abstract TimeZone getTimeZone();
256
257    /**
258     * @return returns the offset from the timeserver to local time 
259     */
260    public abstract long getTimeServerOffset();
261
262    /**
263     * @return return if a password is set
264     */
265    public abstract boolean hasPassword();
266
267    /**
268     * @param password 
269     * @return return if a password is set
270     */
271    public abstract boolean passwordEqual(String password);
272
273    /**
274     * @return return if a password is set
275     */
276    public abstract boolean hasServerPassword();
277
278    /**
279     * @return Returns the mappings.
280     */
281    public abstract Mapping[] getMappings();
282
283    /**
284     * @return Returns the configDir.
285     */
286    public abstract Resource getConfigDir();
287
288    /**
289     * @return Returns the configFile.
290     */
291    public abstract Resource getConfigFile();
292
293    /**
294     * @return Returns the loadTime.
295     */
296    public abstract long getLoadTime();
297
298    /**
299     * @return Returns the baseComponent.
300     */
301    public abstract String getBaseComponentTemplate();
302
303    /**
304     * @return returns the client type
305     */
306    public abstract short getClientType();
307
308    /**
309     * @return Returns the componentDataMemberDefaultAccess.
310     */
311    public abstract int getComponentDataMemberDefaultAccess();
312
313    /**
314     * @return Returns the timeServer.
315     */
316    public abstract String getTimeServer();
317
318    /**
319     * @return Returns the componentDump.
320     */
321    public abstract String getComponentDumpTemplate();
322    
323    /**
324     * @return id of the config 
325     */
326    public abstract String getId();
327
328    /**
329     * @return Returns the debug Template.
330     * @deprecated use instead <code>getDebugEntry(ip, defaultValue)</code>
331     */
332    public abstract String getDebugTemplate();
333
334    /**
335     * @return Returns the error Template for given status code.
336     */
337    public abstract String getErrorTemplate(int statusCode);
338
339    /**
340     * @return Returns the sessionType.
341     */
342    public abstract short getSessionType();
343
344    /**
345     * @return returns the charset for the response and request
346     */
347    public abstract String getWebCharset(); // FUTURE return Charset
348    /**
349     * @return returns the charset used to read cfml files
350     */
351    public abstract String getTemplateCharset(); // FUTURE return Charset
352    /**
353     * @return returns the charset used to read and write resources
354     */
355    public abstract String getResourceCharset(); // FUTURE return Charset
356
357    /**
358     * @return returns the default encoding for mail
359     */
360    public String getMailDefaultEncoding(); // FUTURE return Charset?
361    
362    /**
363     * @return returns update type (auto or manual)
364     */
365    public abstract String getUpdateType();
366
367    /**
368     * @return returns URL for update
369     */
370    public abstract URL getUpdateLocation();
371
372    /**
373     * return directory, where lucee deploy translated cfml classes (java and class files)
374     * @return deploy directory
375     */
376    public abstract Resource getDeployDirectory();
377
378    /**
379     * @return Returns the rootDir.
380     */
381    public abstract Resource getRootDirectory();
382
383    /**
384     * @return Returns the accessor.
385     */
386    public abstract SecurityManager getSecurityManager();
387   
388    /**
389     * @return Returns the cfxTagPool.
390     * @throws PageException 
391     */
392    public abstract CFXTagPool getCFXTagPool() throws PageException;
393    
394    /**
395     * @return returns the application logger
396     */
397    public abstract LogAndSource getApplicationLogger();  // FUTURE deprecated, use instead getLogger()
398
399
400    /**
401     * @return returns the exception logger
402     */
403    public abstract LogAndSource getExceptionLogger();  // FUTURE deprecated, use instead getLogger()
404
405    /**
406     * @return returns the trace logger
407     */
408    public abstract LogAndSource getTraceLogger();  // FUTURE deprecated, use instead getLogger()
409    
410    /**
411     * @param password
412     * @return ConfigServer
413     * @throws PageException
414     */ 
415    public abstract ConfigServer getConfigServer(String password) throws PageException;
416    
417    /**
418     * @return Returns the mailLogger.
419     */
420    public abstract LogAndSource getMailLogger(); // FUTURE deprecated, use instead getLogger()
421    
422    /**
423     * @return Returns the request timeout Directory.
424     */
425    public LogAndSource getRequestTimeoutLogger();  // FUTURE deprecated, use instead getLogger()
426    
427    /**
428     * @return returns schedule logger
429     */
430    public LogAndSource getScheduleLogger(); // FUTURE deprecated, use instead getLogger()
431    
432    /**
433     * reload the time offset to a time server 
434     */
435    public void reloadTimeServerOffset();
436    
437    /**
438     * reset config
439     */
440    public void reset();
441    
442    /**
443     * @return return the search Storage
444     */
445    public SearchEngine getSearchEngine();
446    
447    /**
448     * @return return the Scheduler
449     */
450    public Scheduler getScheduler();
451    
452    /**
453     * @return return all defined Mail Servers
454     */
455    public Server[] getMailServers();
456
457    /**
458     * return the compile type of this context
459     */
460    public short getCompileType();
461    
462    /**
463     * return the all datasources
464    */
465    public DataSource[] getDataSources();
466    
467
468        /**
469         * @param path get a resource that match this path
470         * @return resource matching path
471         */
472        public Resource getResource(String path);
473
474
475        /**
476         * return current application listener
477         * @return application listener
478         */
479        public ApplicationListener getApplicationListener();
480        
481
482        /**
483         * @return the scriptProtect
484         */
485        public int getScriptProtect();
486
487
488        /**
489         * return default proxy setting password
490         * @return the password for proxy
491         */
492        public ProxyData getProxyData();
493        
494        /**
495         * return if proxy is enabled or not
496         * @return is proxy enabled
497         */
498        public boolean isProxyEnableFor(String host);
499        
500        /**
501         * @return the triggerComponentDataMember
502         */
503        public boolean getTriggerComponentDataMember();
504        
505        public RestSettings getRestSetting();
506        
507        public abstract Resource getClientScopeDir();
508
509        public abstract long getClientScopeDirSize();
510
511        public abstract ClassLoader getRPCClassLoader(boolean reload) throws IOException;
512        
513        public Resource getCacheDir();
514
515        public long getCacheDirSize();
516        
517        public Map<String,CacheConnection> getCacheConnections();
518        
519        /**
520         * get default cache connection for a specific type
521         * @param type default type, one of the following (CACHE_DEFAULT_NONE, CACHE_DEFAULT_OBJECT, CACHE_DEFAULT_TEMPLATE, CACHE_DEFAULT_QUERY, CACHE_DEFAULT_RESOURCE)
522         * @return matching Cache Connection
523         */
524        public CacheConnection getCacheDefaultConnection(int type);
525
526        /**
527         * get name of a default cache connection for a specific type
528         * @param type default type, one of the following (CACHE_DEFAULT_NONE, CACHE_DEFAULT_OBJECT, CACHE_DEFAULT_TEMPLATE, CACHE_DEFAULT_QUERY, CACHE_DEFAULT_RESOURCE)
529         * @return name of matching Cache Connection
530         */
531        public String getCacheDefaultConnectionName(int type);
532        
533        /**
534         * returns the default DumpWriter  
535         * @param defaultType
536         * @return default DumpWriter
537         */
538        public abstract DumpWriter getDefaultDumpWriter(int defaultType);
539
540        /**
541         * returns the DumpWriter matching key
542         * @param key key for DumpWriter
543         * @param defaultType
544         * @return matching DumpWriter
545         * @throws PageException if there is no DumpWriter for this key
546         */
547        public abstract DumpWriter getDumpWriter(String key,int defaultType) throws PageException;
548
549        /**
550         * returns the DumpWriter matching key
551         * @param key key for DumpWriter
552         * @return matching DumpWriter
553         * @deprecated use instead <code>getDumpWriter(String key,int defaultType)</code>
554         * @throws PageException if there is no DumpWriter for this key
555         */
556        public abstract DumpWriter getDumpWriter(String key) throws PageException;
557        
558        
559        /**
560         * define if components has a "shadow" in the component variables scope or not.
561         * @return
562         */
563        public abstract boolean useComponentShadow();
564        
565
566    /* *
567     * return a database connection hold inside by a datasource definition
568     * @param datasource definiti0on of the datasource
569     * @param user username to connect
570     * @param pass password to connect
571     * @return datasource connnection
572     * @throws PageException
573     */
574    //public DatasourceConnection getConnection(String datasource, String user, String pass) throws PageException;
575
576    /* *
577     * @return returns the ConnectionPool
578     */
579
580        public Mapping[] getComponentMappings();
581
582        public abstract boolean doCustomTagDeepSearch();
583
584
585        /**
586         * @return returns the error print writer stream
587         */
588        public abstract PrintWriter getErrWriter();
589        
590        /**
591         * @return returns the out print writer stream
592         */
593        public abstract PrintWriter getOutWriter();
594
595        /**
596         * define if lucee search in local directory for custom tags or not
597         * @return search in local dir?
598         */
599        public abstract boolean doLocalCustomTag();
600        
601        public String[] getCustomTagExtensions();
602        
603        /**
604         * @return if error status code will be returned or not
605         */
606        public boolean getErrorStatusCode();
607        
608
609        public abstract int getLocalMode();
610        
611        /**
612         * @return return the class defined for the cluster scope
613         */
614        public Class getClusterClass();
615        
616        /**
617         * @return classloader of ths context
618         */
619        public ClassLoader getClassLoader();
620        
621        // FUTURE @deprected use instead PageContext.getClassLoader(Resource[] reses);
622        public ClassLoader getClassLoader(Resource[] reses) throws IOException;
623        
624        public Resource getExtensionDirectory();
625        
626        public ExtensionProvider[] getExtensionProviders();
627        
628        public Extension[] getExtensions();
629        
630        public PageSource getBaseComponentPageSource();
631        
632        public boolean allowRealPath();
633        
634        public Struct getConstants();
635        
636        public DataSource getDataSource(String datasource) throws PageException;
637        
638        public DataSource getDataSource(String datasource, DataSource defaultValue);
639        
640        public Map getDataSourcesAsMap();
641        
642        public String getDefaultEncoding();
643        
644        public ResourceProvider getDefaultResourceProvider();
645        
646        public CFMLFactory getFactory();
647        
648        public boolean isExtensionEnabled();
649
650        public Resource getFldFile();
651
652        /**
653         * @return the tldFile
654         */
655        public Resource getTldFile();
656        
657        /**
658         * get PageSource of the first Mapping that match the given criteria
659         * @param mappings per application mappings
660         * @param relPath path to get PageSource for
661         * @param onlyTopLevel checks only toplevel mappings
662         * @deprecated use instead getPageSources or getPageSourceExisting
663         */
664        public PageSource getPageSource(Mapping[] mappings, String relPath,boolean onlyTopLevel);
665        
666        /**
667         * return existing PageSource that match the given criteria, if there is no PageSource null is returned.
668         * @param pc current PageContext
669         * @param mappings per application mappings
670         * @param relPath path to get PageSource for
671         * @param onlyTopLevel checks only toplevel mappings
672         * @param useSpecialMappings invoke special mappings like "mapping-tag" or "mapping-customtag"
673         * @param useDefaultMapping also invoke the always existing default mapping "/"
674         */
675        public PageSource getPageSourceExisting(PageContext pc,Mapping[] mappings, String relPath,boolean onlyTopLevel,boolean useSpecialMappings, boolean useDefaultMapping, boolean onlyPhysicalExisting);
676        
677        /**
678         * get all PageSources that match the given criteria
679         * @param pc current PageContext
680         * @param mappings per application mappings
681         * @param relPath path to get PageSource for
682         * @param onlyTopLevel checks only toplevel mappings
683         * @param useSpecialMappings invoke special mappings like "mapping-tag" or "mapping-customtag"
684         * @param useDefaultMapping also invoke the always existing default mapping "/"
685         */
686        public PageSource[] getPageSources(PageContext pc,Mapping[] mappings, String relPath,boolean onlyTopLevel,boolean useSpecialMappings, boolean useDefaultMapping); // FUTURE add boolean useComponentMappings
687        
688        /**
689         * get Resource of the first Mapping that match the given criteria
690         * @param mappings per application mappings
691         * @param relPath path to get PageSource for
692         * @param onlyTopLevel checks only toplevel mappings
693         * @deprecated use instead getPhysicalResources or getPhysicalResourceExisting
694         */
695        public Resource getPhysical(Mapping[] mappings, String relPath, boolean alsoDefaultMapping);
696    
697        /**
698         * get all Resources that match the given criteria
699         * @param pc current PageContext
700         * @param mappings per application mappings
701         * @param relPath path to get PageSource for
702         * @param onlyTopLevel checks only toplevel mappings
703         * @param useSpecialMappings invoke special mappings like "mapping-tag" or "mapping-customtag"
704         * @param useDefaultMapping also invoke the always existing default mapping "/"
705         */
706        public Resource[] getPhysicalResources(PageContext pc,Mapping[] mappings, String relPath,boolean onlyTopLevel,boolean useSpecialMappings, boolean useDefaultMapping);
707        
708        /**
709         * return existing Resource that match the given criteria, if there is no Resource null is returned.
710         * @param pc current PageContext
711         * @param mappings per application mappings
712         * @param relPath path to get Resource for
713         * @param onlyTopLevel checks only toplevel mappings
714         * @param useSpecialMappings invoke special mappings like "mapping-tag" or "mapping-customtag"
715         * @param useDefaultMapping also invoke the always existing default mapping "/"
716         */
717        public Resource getPhysicalResourceExisting(PageContext pc,Mapping[] mappings, String relPath,boolean onlyTopLevel,boolean useSpecialMappings, boolean useDefaultMapping);
718            
719    
720    public Resource getRemoteClientDirectory();
721    
722        public LogAndSource getRemoteClientLog(); // FUTURE deprecated, use instead getLogger()
723        
724        public RemoteClient[] getRemoteClients();
725        
726        public SpoolerEngine getSpoolerEngine();
727        
728        public ResourceProvider[] getResourceProviders();
729        
730        public double getVersion();
731        
732        public Resource getVideoDirectory();
733        
734        //public String getVideoProviderLocation();
735        
736        public boolean isShowVersion();
737        
738        public boolean isSuppressWhitespace();
739        
740        //public boolean isVideoAgreementAccepted();
741        
742        public Struct getRemoteClientUsage();
743        
744        public Class getAdminSyncClass();
745        
746        public Class getVideoExecuterClass();
747        
748        public ThreadQueue getThreadQueue();
749        
750        public boolean getSessionCluster();
751
752        public boolean getClientCluster();
753        
754        public Resource getSecurityDirectory();
755        
756        public boolean isMonitoringEnabled();
757        
758        public RequestMonitor[] getRequestMonitors();
759        
760        public RequestMonitor getRequestMonitor(String name) throws PageException;
761        
762        public IntervallMonitor[] getIntervallMonitors();
763
764        public IntervallMonitor getIntervallMonitor(String name) throws PageException;
765        
766        /**
767         * if free permspace gen is lower than 10000000 bytes, lucee shrinks all classloaders 
768         * @param cs
769         */
770    public void checkPermGenSpace(boolean check);
771    
772    public boolean allowRequestTimeout();
773}