use of io.clownfish.clownfish.compiler.CfClassCompiler in project Clownfish by rawdog71.
the class Clownfish method init.
/**
* Call of the "init" site
* Init is called at the beginning of the Clownfish startup and after changing system properties
* Checks the bootstrap flag of the application.properties and calls a bootstrap routine
* Initializes several variables and starts Quartz job triggers
*/
@PostConstruct
public void init() {
LOGGER.info("INIT CLOWNFISH START");
servicestatus.setMessage("Clownfish is initializing");
servicestatus.setOnline(false);
if (null == authtokenlist) {
authtokenlist = new AuthTokenList();
}
// read all System Properties of the property table
if (null == propertyUtil) {
propertyUtil = new PropertyUtil(propertylist);
}
if (null == cfclassLoader) {
cfclassLoader = new CfClassLoader();
}
if (null == cfclassCompiler) {
cfclassCompiler = new CfClassCompiler();
cfclassCompiler.setClownfish(this);
cfclassCompiler.init(cfclassLoader, propertyUtil, cfjavaService);
}
libloaderpath = propertyUtil.getPropertyValue("folder_libs");
if (null == beanUtil)
beanUtil = new BeanUtil();
if ((!libloaderpath.isBlank()) && (null != libloaderpath))
beanUtil.init(libloaderpath);
mavenpath = propertyUtil.getPropertyValue("folder_maven");
if ((!mavenpath.isBlank()) && (null != mavenpath)) {
if (classpathUtil == null) {
classpathUtil = new ClassPathUtil();
classpathUtil.init(cfclassLoader);
}
classpathUtil.addPath(mavenpath);
}
if (null == mavenlist) {
mavenlist = new MavenList();
mavenlist.setClasspathUtil(classpathUtil);
}
Thread compileThread = new Thread(cfclassCompiler);
compileThread.start();
if (1 == bootstrap) {
bootstrap = 0;
try {
AnsiConsole.systemInstall();
System.out.println(ansi().fg(GREEN));
System.out.println("BOOTSTRAPPING II");
System.out.println(ansi().reset());
Properties props = new Properties();
String propsfile = "application.properties";
InputStream is = new FileInputStream(propsfile);
if (null != is) {
props.load(is);
props.setProperty("bootstrap", String.valueOf(bootstrap));
File f = new File("application.properties");
bootstrap();
OutputStream out = new FileOutputStream(f);
DefaultPropertiesPersister p = new DefaultPropertiesPersister();
p.store(props, out, "Application properties");
} else {
LOGGER.error("application.properties file not found");
}
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
}
/* Hazelcast test */
/*
if (null == hazelConfig) {
hazelConfig = new Config();
}
if (null == hcInstance) {
hcInstance = Hazelcast.newHazelcastInstance(hazelConfig);
}
*/
Package p = FacesContext.class.getPackage();
if (null == clownfishutil) {
clownfishutil = new ClownfishUtil();
}
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = null;
if ((new File("pom.xml")).exists()) {
try {
model = reader.read(new FileReader("pom.xml"));
} catch (FileNotFoundException ex) {
LOGGER.error(ex.getMessage());
} catch (IOException | XmlPullParserException ex) {
LOGGER.error(ex.getMessage());
}
}
if (null != model) {
clownfishutil.setVersion(model.getVersion()).setVersionMojarra(p.getImplementationVersion()).setVersionTomcat(ServerInfo.getServerNumber());
} else {
clownfishutil.setVersion(getClass().getPackage().getImplementationVersion()).setVersionMojarra(p.getImplementationVersion()).setVersionTomcat(ServerInfo.getServerNumber());
}
try {
AnsiConsole.systemInstall();
System.out.println(ansi().fg(GREEN));
System.out.println("INIT CLOWNFISH CMS Version " + clownfishutil.getVersion() + " on Tomcat " + clownfishutil.getVersionTomcat() + " with Mojarra " + clownfishutil.getVersionMojarra());
System.out.println(ansi().fg(RED));
System.out.println(" ... ");
System.out.println(" &@@@@@@@ ");
System.out.println(" .&&%%%@%@@@@ ");
System.out.println(" %%%%%%%%&%%@ ");
System.out.println(" .%%%%%%%%#%%& ");
System.out.println(" /%%%%%%%%%##% &&@@. ");
System.out.println(" .,*//#############% %#%#%@@ ");
System.out.println(" #((############### ###%#%%&@ ");
System.out.println(" // #((((/(/(((((((/ (###(###&% ");
System.out.println(" *((//((#/ #((((#(((((((# (((##%##@ ");
System.out.println(" /(((((#(////# .((((((((((((* *((((###% ");
System.out.println(" /(((((#((###### #(((((##((@@@@& ((((((## ");
System.out.println(" (((((((####@@&#(% #((((####((((&@/ #(((((((* (&@@&# ");
System.out.println(" /(((((((#######(((& *((((##(((((((#@/ #(((((((/ &&%%%%&@@@, ");
System.out.println(" /((((((((((((((#((((& (#((#(##((##((@@ #(#####(* *########%%&@@@.");
System.out.println(" /%#(((((((((((((/((((. ###########(((#@* ((#####(. /#########%%%@@@@");
System.out.println(" ,(((((((((((((((((((/ ###########((((@, ((####### ###########%%%@@@");
System.out.println(" .(((((((((((((/((((* (#########((((#@ ((######% .##########%%%&@@@");
System.out.println(" ,/(((((((((((((& #(#########((((@/ .#((###(((( #########%%%%&@@@");
System.out.println(" /((((((##(& %(((((######(((&/ .#(((((((((. *########%%%&&@@@");
System.out.println(" ,//(#@ /(#(####(((##(((&. (((((((((/ /######%%%&&@@@@");
System.out.println(" ./* .#(########((#((*/. *#(((((((###. /%##%%%%@@@@@@ ");
System.out.println(" /######((#######( ./#######(###(#@ .&@@@@@@@% ");
System.out.println(" /#######%%#(((#((((@. /@%#####(##((@# ");
System.out.println(" /####%%#@& *#(((//(/(%@ *@@@@%#%&@@ ");
System.out.println(" %#%&&@&* *((((///(@@& .##/* ");
System.out.println(" ,,***, *((/(#@@@@@, ");
System.out.println(" *@@@@@@@@% ");
System.out.println(ansi().reset());
// Check Consistence
if (checkConsistency > 0) {
consistencyUtil.checkConsistency();
}
// Generate Hibernate DOM Mapping
if (null == hibernateInitializer) {
hibernateInitializer = new HibernateInit(servicestatus, cfclassService, cfattributService, cfclasscontentService, cfattributcontentService, cflistcontentService, cfclasscontentkeywordService, cfkeywordService, dburl);
hibernateUtil.init(hibernateInitializer);
hibernateUtil.setHibernateInit(hibernateInit);
Thread hibernateThread = new Thread(hibernateUtil);
hibernateThread.start();
/*
hibernateUtil.generateTablesDatamodel(hibernateInit);
// generate Relation Tables
hibernateUtil.generateRelationsDatamodel(hibernateInit);
*/
}
propertylist.setClownfish(this);
if (null == defaultUtil) {
defaultUtil = new DefaultUtil();
}
if (mailUtil == null)
mailUtil = new MailUtil(propertyUtil);
if (pdfUtil == null)
pdfUtil = new PDFUtil(cftemplateService, cftemplateversionService, cfsitedatasourceService, cfdatasourceService, cfsiteService, propertyUtil, templateUtil);
// Set default values
// 1 = Staging mode (fetch sourcecode from commited repository) <= default
modus = STAGING;
// 0 = Development mode (fetch sourcecode from database)
defaultUtil.setCharacterEncoding("UTF-8").setContentType("text/html").setLocale(new Locale("de"));
sapSupport = propertyUtil.getPropertyBoolean("sap_support", sapSupport);
if (sapSupport) {
if (null == sapc) {
sapc = new SAPConnection(SAPCONNECTION, "Clownfish1");
rpytableread = new RPY_TABLE_READ(sapc);
}
}
// Override default values with system properties
String systemContentType = propertyUtil.getPropertyValue("response_contenttype");
String systemCharacterEncoding = propertyUtil.getPropertyValue("response_characterencoding");
String systemLocale = propertyUtil.getPropertyValue("response_locale");
if (!systemCharacterEncoding.isEmpty()) {
defaultUtil.setCharacterEncoding(systemCharacterEncoding);
}
if (!systemContentType.isEmpty()) {
defaultUtil.setContentType(systemContentType);
}
if (!systemLocale.isEmpty()) {
defaultUtil.setLocale(new Locale(systemLocale));
}
if (null == gzipswitch) {
gzipswitch = new GzipSwitch();
}
if (null == markdownUtil) {
markdownUtil = new MarkdownUtil(propertylist);
markdownUtil.initOptions();
} else {
markdownUtil.initOptions();
}
if ((null != folderUtil.getIndex_folder()) && (!folderUtil.getIndex_folder().isEmpty())) {
// Call a parallel thread to index the content in Lucene
if (null == contentIndexer) {
contentIndexer = new ContentIndexer(cfattributcontentService, indexService);
}
Thread contentindexer_thread = new Thread(contentIndexer);
contentindexer_thread.start();
LOGGER.info("CONTENTINDEXER RUN");
if (null == assetIndexer) {
assetIndexer = new AssetIndexer(cfassetService, indexService, propertylist);
}
Thread assetindexer_thread = new Thread(assetIndexer);
assetindexer_thread.start();
LOGGER.info("ASSETINDEXER RUN");
indexService.getWriter().commit();
}
// Init Site Metadata Map
if (null == metainfomap) {
// hzMetainfomap = hcInstance.getMap("metainfos");
metainfomap = new HashMap();
}
metainfomap.put("version", clownfishutil.getVersion());
metainfomap.put("versionMojarra", clownfishutil.getVersionMojarra());
metainfomap.put("versionTomcat", clownfishutil.getVersionTomcat());
// Init Lucene Search Map
if (null == searchcontentmap) {
searchcontentmap = new HashMap<>();
}
if (null == searchassetmap) {
searchassetmap = new HashMap<>();
}
if (null == searchassetmetadatamap) {
searchassetmetadatamap = new HashMap<>();
}
if (null == searchclasscontentmap) {
searchclasscontentmap = new HashMap<>();
}
if (null == searchmetadata) {
searchmetadata = new HashMap<>();
}
searchlimit = propertyUtil.getPropertyInt("lucene_searchlimit", LuceneConstants.MAX_SEARCH);
jobSupport = propertyUtil.getPropertyBoolean("job_support", jobSupport);
if (jobSupport) {
scheduler.clear();
// Fetch the Quartz jobs
quartzlist.init();
quartzlist.setClownfish(this);
List<CfQuartz> joblist = quartzlist.getQuartzlist();
joblist.stream().forEach((quartz) -> {
try {
if (quartz.isActive()) {
JobDetail job = newJob(quartz.getName());
scheduler.scheduleJob(job, trigger(job, quartz.getSchedule()));
System.out.println(ansi().fg(GREEN));
System.out.println("JOB SCHEDULE: " + quartz.getName());
System.out.println(ansi().reset());
}
} catch (SchedulerException ex) {
LOGGER.error(ex.getMessage());
}
});
}
AnsiConsole.systemUninstall();
} catch (SchedulerException | IOException ex) {
LOGGER.error(ex.getMessage());
}
folderUtil.init();
servicestatus.setMessage("Clownfish is online");
servicestatus.setOnline(true);
LOGGER.info("INIT CLOWNFISH END");
}
use of io.clownfish.clownfish.compiler.CfClassCompiler in project Clownfish by rawdog71.
the class Clownfish method makeResponse.
/**
* makeResponse
*
* @param name
* @param postmap
* @param urlParams
* @param makestatic
* @return
* @throws io.clownfish.clownfish.exceptions.PageNotFoundException
*/
@Async
public Future<ClownfishResponse> makeResponse(String name, List<JsonFormParameter> postmap, List urlParams, boolean makestatic) throws PageNotFoundException {
ClownfishResponse cfresponse = new ClownfishResponse();
try {
List<CfSitedatasource> sitedatasourcelist = null;
// Freemarker Template
freemarker.template.Template fmTemplate = null;
Map fmRoot = null;
// Velocity Template
org.apache.velocity.VelocityContext velContext = null;
org.apache.velocity.Template velTemplate = null;
// fetch parameter list
Map parametermap = clownfishutil.getParametermap(postmap);
// manage urlParams
clownfishutil.addUrlParams(parametermap, urlParams);
preview = false;
if (parametermap.containsKey("preview")) {
// check mode for display (preview or productive)
if (parametermap.get("preview").toString().compareToIgnoreCase("true") == 0) {
preview = true;
}
}
if (parametermap.containsKey("modus")) {
// check mode for display (staging or dev)
if (parametermap.get("modus").toString().compareToIgnoreCase("dev") == 0) {
modus = DEVELOPMENT;
}
}
// fetch site by name or aliasname
CfSite cfsite = null;
try {
cfsite = cfsiteService.findByName(name);
} catch (Exception ex) {
try {
cfsite = cfsiteService.findByAliaspath(name);
} catch (Exception e1) {
throw new PageNotFoundException("PageNotFound Exception: " + name);
}
}
// Site has not job flag
if (!cfsite.isJob()) {
// increment site hitcounter
if ((!preview) && (modus == STAGING)) {
long hitcounter = cfsite.getHitcounter().longValue();
cfsite.setHitcounter(BigInteger.valueOf(hitcounter + 1));
cfsiteService.edit(cfsite);
}
// Site has static flag
if ((cfsite.isStaticsite()) && (!makestatic) && (!preview)) {
if ((cfsite.getContenttype() != null)) {
if (!cfsite.getContenttype().isEmpty()) {
this.contenttype = cfsite.getContenttype();
}
}
if ((cfsite.getCharacterencoding() != null)) {
if (!cfsite.getCharacterencoding().isEmpty()) {
this.characterencoding = cfsite.getCharacterencoding();
}
}
if ((cfsite.getLocale() != null)) {
if (!cfsite.getLocale().isEmpty()) {
this.locale = cfsite.getLocale();
}
}
cfresponse = getStaticSite(name);
if (0 == cfresponse.getErrorcode()) {
return new AsyncResult<>(cfresponse);
} else {
Future<ClownfishResponse> cfStaticResponse = makeResponse(name, postmap, urlParams, true);
try {
String aliasname = cfsite.getAliaspath();
StaticSiteUtil.generateStaticSite(name, aliasname, cfStaticResponse.get().getOutput(), cfassetService, folderUtil);
return makeResponse(name, postmap, urlParams, false);
} catch (InterruptedException | ExecutionException ex) {
LOGGER.error(ex.getMessage());
return makeResponse(name, postmap, urlParams, false);
}
}
} else {
if ((cfsite.getContenttype() != null)) {
if (!cfsite.getContenttype().isEmpty()) {
this.contenttype = cfsite.getContenttype();
}
}
if ((cfsite.getCharacterencoding() != null)) {
if (!cfsite.getCharacterencoding().isEmpty()) {
this.characterencoding = cfsite.getCharacterencoding();
}
}
if ((cfsite.getLocale() != null)) {
if (!cfsite.getLocale().isEmpty()) {
this.locale = cfsite.getLocale();
}
}
try {
CfTemplate cftemplate = cftemplateService.findById(cfsite.getTemplateref().longValue());
// fetch the dependend template
boolean isScripted = false;
switch(cftemplate.getScriptlanguage()) {
case // FREEMARKER
0:
fmRoot = new LinkedHashMap();
freemarkerTemplateloader.setModus(modus);
freemarkerCfg = new freemarker.template.Configuration();
freemarkerCfg.setDefaultEncoding("UTF-8");
freemarkerCfg.setTemplateLoader(freemarkerTemplateloader);
freemarkerCfg.setLocalizedLookup(false);
freemarkerCfg.setLocale(Locale.GERMANY);
fmTemplate = freemarkerCfg.getTemplate(cftemplate.getName());
isScripted = true;
break;
case // VELOCITY
1:
velContext = new org.apache.velocity.VelocityContext();
velTemplate = new org.apache.velocity.Template();
org.apache.velocity.runtime.RuntimeServices runtimeServices = org.apache.velocity.runtime.RuntimeSingleton.getRuntimeServices();
String templateContent;
if (DEVELOPMENT == modus) {
templateContent = cftemplate.getContent();
} else {
long currentTemplateVersion;
try {
currentTemplateVersion = cftemplateversionService.findMaxVersion(cftemplate.getId());
} catch (NullPointerException ex) {
currentTemplateVersion = 0;
}
templateContent = templateUtil.getVersion(cftemplate.getId(), currentTemplateVersion);
}
templateContent = templateUtil.fetchIncludes(templateContent, modus);
StringReader reader = new StringReader(templateContent);
velTemplate.setRuntimeServices(runtimeServices);
velTemplate.setData(runtimeServices.parse(reader, velTemplate));
velTemplate.initDocument();
isScripted = true;
break;
default:
break;
}
String gzip = propertyUtil.getPropertySwitch("html_gzip", cfsite.getGzip());
if (gzip.compareToIgnoreCase("on") == 0) {
gzipswitch.setGzipon(true);
}
String htmlcompression = propertyUtil.getPropertySwitch("html_compression", cfsite.getHtmlcompression());
HtmlCompressor htmlcompressor = new HtmlCompressor();
htmlcompressor.setRemoveSurroundingSpaces(HtmlCompressor.BLOCK_TAGS_MAX);
htmlcompressor.setPreserveLineBreaks(false);
Writer out = new StringWriter();
// fetch the dependend stylesheet, if available
String cfstylesheet = "";
if (cfsite.getStylesheetref() != null) {
cfstylesheet = ((CfStylesheet) cfstylesheetService.findById(cfsite.getStylesheetref().longValue())).getContent();
if (htmlcompression.compareToIgnoreCase("on") == 0) {
htmlcompressor.setCompressCss(true);
cfstylesheet = htmlcompressor.compress(cfstylesheet);
}
}
// fetch the dependend javascript, if available
String cfjavascript = "";
if (cfsite.getJavascriptref() != null) {
cfjavascript = ((CfJavascript) cfjavascriptService.findById(cfsite.getJavascriptref().longValue())).getContent();
if (htmlcompression.compareToIgnoreCase("on") == 0) {
htmlcompressor.setCompressJavaScript(true);
cfjavascript = htmlcompressor.compress(cfjavascript);
}
}
if (!cftemplate.isLayout()) {
// NORMAL Template
// fetch the dependend content
List<CfSitecontent> sitecontentlist = new ArrayList<>();
sitecontentlist.addAll(cfsitecontentService.findBySiteref(cfsite.getId()));
sitecontentmap = siteutil.getSitecontentmapList(sitecontentlist);
// fetch the dependend datalists, if available
sitecontentmap = siteutil.getSitelist_list(cfsite, sitecontentmap);
// fetch the site assetlibraries
sitecontentmap = siteutil.getSiteAssetlibrary(cfsite, sitecontentmap);
// fetch the site keywordlibraries
sitecontentmap = siteutil.getSiteKeywordlibrary(cfsite, sitecontentmap);
} else {
// LAYOUT Template
// Fetch the dependent content
List<CfLayoutcontent> layoutcontentlist = cflayoutcontentService.findBySiteref(cfsite.getId());
List<CfLayoutcontent> contentlist = layoutcontentlist.stream().filter(lc -> lc.getCfLayoutcontentPK().getContenttype().compareToIgnoreCase("C") == 0).collect(Collectors.toList());
List<CfClasscontent> classcontentlist = new ArrayList<>();
for (CfLayoutcontent layoutcontent : contentlist) {
if (preview) {
if (layoutcontent.getPreview_contentref().longValue() > 0) {
classcontentlist.add(cfclasscontentService.findById(layoutcontent.getPreview_contentref().longValue()));
}
} else {
if ((null != layoutcontent.getContentref()) && (layoutcontent.getContentref().longValue() > 0)) {
classcontentlist.add(cfclasscontentService.findById(layoutcontent.getContentref().longValue()));
}
}
}
sitecontentmap = siteutil.getClasscontentmapList(classcontentlist);
// fetch the dependend datalists, if available
contentlist = layoutcontentlist.stream().filter(lc -> lc.getCfLayoutcontentPK().getContenttype().compareToIgnoreCase("DL") == 0).collect(Collectors.toList());
List<CfList> sitelist = new ArrayList<>();
for (CfLayoutcontent layoutcontent : contentlist) {
if (preview) {
if (layoutcontent.getPreview_contentref().longValue() > 0) {
sitelist.add(cflistService.findById(layoutcontent.getPreview_contentref().longValue()));
}
} else {
if ((null != layoutcontent.getContentref()) && (layoutcontent.getContentref().longValue() > 0)) {
sitelist.add(cflistService.findById(layoutcontent.getContentref().longValue()));
}
}
}
sitecontentmap = siteutil.getSitelist_list(sitelist, sitecontentmap);
// fetch the dependend assetlibraries, if available
contentlist = layoutcontentlist.stream().filter(lc -> lc.getCfLayoutcontentPK().getContenttype().compareToIgnoreCase("AL") == 0).collect(Collectors.toList());
List<CfAssetlist> assetlibrary_list = new ArrayList<>();
for (CfLayoutcontent layoutcontent : contentlist) {
if (preview) {
if (layoutcontent.getPreview_contentref().longValue() > 0) {
assetlibrary_list.add(cfassetlistService.findById(layoutcontent.getPreview_contentref().longValue()));
}
} else {
if ((null != layoutcontent.getContentref()) && (layoutcontent.getContentref().longValue() > 0)) {
assetlibrary_list.add(cfassetlistService.findById(layoutcontent.getContentref().longValue()));
}
}
}
sitecontentmap = siteutil.getAssetlibrary(assetlibrary_list, sitecontentmap);
// fetch the site keywordlibraries
contentlist = layoutcontentlist.stream().filter(lc -> lc.getCfLayoutcontentPK().getContenttype().compareToIgnoreCase("KL") == 0).collect(Collectors.toList());
List<CfKeywordlist> keywordlibrary_list = new ArrayList<>();
for (CfLayoutcontent layoutcontent : contentlist) {
if (preview) {
if (layoutcontent.getPreview_contentref().longValue() > 0) {
keywordlibrary_list.add(cfkeywordlistService.findById(layoutcontent.getPreview_contentref().longValue()));
}
} else {
if ((null != layoutcontent.getContentref()) && (layoutcontent.getContentref().longValue() > 0)) {
keywordlibrary_list.add(cfkeywordlistService.findById(layoutcontent.getContentref().longValue()));
}
}
}
sitecontentmap = siteutil.getSiteKeywordlibrary(keywordlibrary_list, sitecontentmap);
}
// manage parameters
HashMap<String, DatatableProperties> datatableproperties = clownfishutil.getDatatableproperties(postmap);
EmailProperties emailproperties = clownfishutil.getEmailproperties(postmap);
HashMap<String, DatatableNewProperties> datatablenewproperties = clownfishutil.getDatatablenewproperties(postmap);
HashMap<String, DatatableDeleteProperties> datatabledeleteproperties = clownfishutil.getDatatabledeleteproperties(postmap);
HashMap<String, DatatableUpdateProperties> datatableupdateproperties = clownfishutil.getDatatableupdateproperties(postmap);
manageSessionVariables(postmap);
writeSessionVariables(parametermap);
// fetch the dependend datasources
sitedatasourcelist = new ArrayList<>();
sitedatasourcelist.addAll(cfsitedatasourceService.findBySiteref(cfsite.getId()));
HashMap<String, HashMap> dbexport = databaseUtil.getDbexport(sitedatasourcelist, datatableproperties, datatablenewproperties, datatabledeleteproperties, datatableupdateproperties);
sitecontentmap.put("db", dbexport);
// Put meta info to sitecontentmap
metainfomap.put("title", cfsite.getTitle());
metainfomap.put("description", cfsite.getDescription());
metainfomap.put("name", cfsite.getName());
metainfomap.put("encoding", cfsite.getCharacterencoding());
metainfomap.put("contenttype", cfsite.getContenttype());
metainfomap.put("locale", cfsite.getLocale());
metainfomap.put("alias", cfsite.getAliaspath());
// instantiate Template Beans
networkbean = new NetworkTemplateBean();
webservicebean = new WebServiceTemplateBean();
emailbean = new EmailTemplateBean();
emailbean.init(propertyUtil.getPropertymap(), mailUtil, propertyUtil);
// send a mail, if email properties are set
if (emailproperties != null) {
try {
sendRespondMail(emailproperties.getSendto(), emailproperties.getSubject(), emailproperties.getBody());
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
}
}
if (sapSupport) {
List<CfSitesaprfc> sitesaprfclist = new ArrayList<>();
sitesaprfclist.addAll(cfsitesaprfcService.findBySiteref(cfsite.getId()));
sapbean = new SAPTemplateBean();
sapbean.init(sapc, sitesaprfclist, rpytableread, postmap);
}
databasebean = new DatabaseTemplateBean();
importbean = new ImportTemplateBean();
pdfbean = new PDFTemplateBean();
pdfbean.init(pdfUtil);
if (!sitedatasourcelist.isEmpty()) {
databasebean.init(sitedatasourcelist, cfdatasourceService);
importbean.init(sitedatasourcelist, cfdatasourceService);
}
externalclassproviderbean = new ExternalClassProvider(cfclassCompiler);
if (isScripted) {
// NORMAL Template
switch(cftemplate.getScriptlanguage()) {
case // FREEMARKER
0:
if (null != fmRoot) {
fmRoot.put("css", cfstylesheet);
fmRoot.put("js", cfjavascript);
fmRoot.put("sitecontent", sitecontentmap);
fmRoot.put("metainfo", metainfomap);
fmRoot.put("property", propertyUtil.getPropertymap());
fmRoot.put("emailBean", emailbean);
if (sapSupport) {
fmRoot.put("sapBean", sapbean);
}
fmRoot.put("databaseBean", databasebean);
fmRoot.put("importBean", importbean);
fmRoot.put("networkBean", networkbean);
fmRoot.put("webserviceBean", webservicebean);
fmRoot.put("pdfBean", pdfbean);
fmRoot.put("classBean", externalclassproviderbean);
fmRoot.put("parameter", parametermap);
if (!searchmetadata.isEmpty()) {
fmRoot.put("searchmetadata", searchmetadata);
}
if (!searchcontentmap.isEmpty()) {
fmRoot.put("searchcontentlist", searchcontentmap);
}
if (!searchassetmap.isEmpty()) {
fmRoot.put("searchassetlist", searchassetmap);
}
if (!searchassetmetadatamap.isEmpty()) {
fmRoot.put("searchassetmetadatalist", searchassetmetadatamap);
}
if (!searchclasscontentmap.isEmpty()) {
fmRoot.put("searchclasscontentlist", searchclasscontentmap);
}
for (Class<?> tpbc : beanUtil.getLoadabletemplatebeans()) {
Constructor<?> ctor;
try {
ctor = tpbc.getConstructor();
Object object = ctor.newInstance();
fmRoot.put(tpbc.getName().replaceAll("\\.", "_"), object);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
LOGGER.error(ex.getMessage());
}
}
/*
for (Class<?> c : classpathUtil.getClass_set()) {
Constructor<?> ctor;
try {
if (!Modifier.isInterface(c.getModifiers()) && !Modifier.isAbstract(c.getModifiers()) && !Modifier.isFinal(c.getModifiers()))
{
ctor = c.getConstructor();
Object object = ctor.newInstance();
fmRoot.put(c.getName().replaceAll("\\.", "_"), object);
}
} catch (NoClassDefFoundError | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
if (ex instanceof NoSuchMethodException || ex instanceof IllegalAccessException || ex instanceof InvocationTargetException || ex instanceof NoClassDefFoundError)
continue;
LOGGER.error(ex.getMessage());
}
}
*/
Map finalFmRoot = fmRoot;
cfclassCompiler.getClassMethodMap().forEach((k, v) -> {
Constructor<?> ctor;
try {
ctor = k.getConstructor();
Object object = ctor.newInstance();
finalFmRoot.put(k.getName().replaceAll("\\.", "_"), object);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
LOGGER.error(ex.getMessage());
}
});
try {
if (null != fmTemplate) {
if (cftemplate.isLayout()) {
String output = manageLayout(cfsite, cftemplate.getName(), cftemplate.getContent(), cfstylesheet, cfjavascript, parametermap);
output = interpretscript(output, cftemplate, cfstylesheet, cfjavascript, parametermap);
out.write(output);
} else {
freemarker.core.Environment env = fmTemplate.createProcessingEnvironment(fmRoot, out);
env.process();
}
}
} catch (freemarker.template.TemplateException ex) {
LOGGER.error(ex.getMessage());
}
}
break;
case // VELOCITY
1:
if (null != velContext) {
velContext.put("css", cfstylesheet);
velContext.put("js", cfjavascript);
velContext.put("sitecontent", sitecontentmap);
velContext.put("metainfo", metainfomap);
velContext.put("emailBean", emailbean);
if (sapSupport) {
velContext.put("sapBean", sapbean);
}
velContext.put("databaseBean", databasebean);
velContext.put("importBean", importbean);
velContext.put("networkBean", networkbean);
velContext.put("webserviceBean", webservicebean);
velContext.put("pdfBean", pdfbean);
velContext.put("classBean", externalclassproviderbean);
velContext.put("parameter", parametermap);
velContext.put("property", propertyUtil.getPropertymap());
if (!searchmetadata.isEmpty()) {
velContext.put("searchmetadata", searchmetadata);
}
if (!searchcontentmap.isEmpty()) {
velContext.put("searchcontentlist", searchcontentmap);
}
if (!searchassetmap.isEmpty()) {
velContext.put("searchassetlist", searchassetmap);
}
if (!searchassetmetadatamap.isEmpty()) {
velContext.put("searchassetmetadatalist", searchassetmetadatamap);
}
if (!searchclasscontentmap.isEmpty()) {
velContext.put("searchclasscontentlist", searchclasscontentmap);
}
for (Class tpbc : beanUtil.getLoadabletemplatebeans()) {
Constructor<?> ctor;
try {
ctor = tpbc.getConstructor();
Object object = ctor.newInstance(new Object[] {});
velContext.put(tpbc.getName().replaceAll("\\.", "_"), object);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
LOGGER.error(ex.getMessage());
}
}
/*
for (Class<?> c : classpathUtil.getClass_set()) {
Constructor<?> ctor;
try {
if (!Modifier.isInterface(c.getModifiers()) && !Modifier.isAbstract(c.getModifiers()) && !Modifier.isFinal(c.getModifiers()))
{
ctor = c.getConstructor();
Object object = ctor.newInstance();
velContext.put(c.getName().replaceAll("\\.", "_"), object);
}
} catch (NoClassDefFoundError | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
if (ex instanceof NoSuchMethodException || ex instanceof IllegalAccessException || ex instanceof InvocationTargetException || ex instanceof NoClassDefFoundError)
continue;
LOGGER.error(ex.getMessage());
}
}
*/
org.apache.velocity.VelocityContext finalvelContext = velContext;
cfclassCompiler.getClassMethodMap().forEach((k, v) -> {
Constructor<?> ctor;
try {
ctor = k.getConstructor();
Object object = ctor.newInstance();
finalvelContext.put(k.getName().replaceAll("\\.", "_"), object);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
LOGGER.error(ex.getMessage());
}
});
if (null != velTemplate) {
if (cftemplate.isLayout()) {
String output = manageLayout(cfsite, cftemplate.getName(), cftemplate.getContent(), cfstylesheet, cfjavascript, parametermap);
output = interpretscript(output, cftemplate, cfstylesheet, cfjavascript, parametermap);
out.write(output);
} else {
velTemplate.merge(velContext, out);
}
}
}
break;
// HTML
default:
}
} else {
// LAYOUT Template
if (cftemplate.isLayout()) {
String output = manageLayout(cfsite, cftemplate.getName(), cftemplate.getContent(), cfstylesheet, cfjavascript, parametermap);
out.write(output);
out.flush();
out.close();
} else {
out.write(cftemplate.getContent());
out.flush();
out.close();
}
}
if (htmlcompression.compareToIgnoreCase("on") == 0) {
htmlcompressor.setCompressCss(false);
htmlcompressor.setCompressJavaScript(false);
cfresponse.setErrorcode(0);
cfresponse.setOutput(htmlcompressor.compress(out.toString()));
// LOGGER.info("END makeResponse: " + name);
return new AsyncResult<>(cfresponse);
} else {
cfresponse.setErrorcode(0);
cfresponse.setOutput(out.toString());
// LOGGER.info("END makeResponse: " + name);
return new AsyncResult<>(cfresponse);
}
} catch (NoResultException ex) {
LOGGER.info("Exception: " + ex);
cfresponse.setErrorcode(1);
cfresponse.setOutput("No template");
// LOGGER.info("END makeResponse: " + name);
return new AsyncResult<>(cfresponse);
}
}
} else {
cfresponse.setErrorcode(2);
cfresponse.setOutput("Only for Job calling");
return new AsyncResult<>(cfresponse);
}
} catch (IOException | org.apache.velocity.runtime.parser.ParseException ex) {
cfresponse.setErrorcode(1);
cfresponse.setOutput(ex.getMessage());
// LOGGER.info("END makeResponse: " + name);
return new AsyncResult<>(cfresponse);
}
}
Aggregations