Using XPages with Freemarker help needed - xpages

I would like to use Freemarker template engine in my XPages app but cant get it to work in XPages environment. The problem I have is related to template path which I don't know how to setup correctly. Freemarker simply assumes that templates resides somewhere on file system. I put my template file into the same directory as related java class exists. The path to such file is something like this xspnsf://server:0/xpages_tests.nsf/WEB-INF/classes/tcl/ which doesn't work for me. Is there anyone having experience with this? I simply need directory path to nsf that is accepted by File() constructor. This virtual xspnsf://.... is not understandable for java File object.
Here is the template path code for Freemarker:
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(new File("??????"));
Template temp = cfg.getTemplate("tmp.ftl");

Since you are storing the templates together with the classes (if I understand well), can't you use cfg.setClassForTemplateLoading(SomeClassFromThere.class, "/com/example/yourapplication/templates")?

Try to use Velocity (http://velocity.apache.org/) instead. It allows You to create custom resources loaders which can easily load templates from any place (for example from documents from notes db).
I have seen it used many times in different xpage projects and it works great.

Related

How to apply cruft/cookiecutter template to existing Git/GitHub project?

What's the best way to apply a cruft (or cookiecutter) template to an existing Git/GitHub project, which doesn't use any cookiecutter template so far?
In most cases, this would be a bad idea. Cookiecutter will override the contents of your folder. Any existing files, matching to template files, will be overridden with the template ones. So if you already have real logic inside those files, it gets lost.
If you want to adopt some good practices from the template, better do it manually and not by applying it on the existing project.

How to override hybris platform files other than customize

So, I can see many files under customize folder under platform.
Is there any other way to oveerride platform in general other than putting it in customize folder?
If we have to override some OOTB file there are two ways:
1) If its in some extension, we can create customized extension and do our changes.
2) Add stuff into customize folder and do ant customize.
What if OOTB file is in platform? Is there any other way?
I expect to customize platform without adding it to customize folder.
Is the function/bean you want to override is injected through Spring?
If no, and you need to override say some jar, class or xml. You have choice of ant customize or buildcallbacks.xml
If yes, it's no different than overriding any other beans from parent extension. The only thing is that you will not need to create an extension dependency as platform is available globally.
For example : If you wish to override some function in DefaultCatalogDao to give your own implementation. You can do it like...
Create your own implementation extending the platform related service
Inject your custom bean with alias of the defaultCatalogDao
<alias alias="catalogDao" name="customCatalogDao"/>
<bean id="customCatalogDao" class="......CustomCatalogDao" parent="defaultCatalogDao"/>
For Commerce Cloud
You can change platform files using customize folder in Commerce Cloud V2 too. You would need to create a folder in your custom repository with name _CUSTOMIZE_ and then as you do in non cloud version, add your files (with exact folder structure as in platform).
Once you creare above folder, CCV2 build strategy automatically picks and deploys it, without any additional configuration.
Hope it helps!
Using buildcallbacks you can replace the files even the files in platform jar .
You can simply copy paste your file or write your own shell script to execute it and copy file to platform but how would it be different from ant customize. And why would you want to go away from standard hybris practices? Would that give you any extra benefit? I am sure that would only lead to issues during upgrade etc. Its not spring bean injection where you could tell your platform to use your implementation instead on other. There is no sense in wasting time in finding something which doesnt go along with product best practices.

How can i use resources when using feature folders in dotnet core

Im using the feature folder structure, and i want to use Localizer in views. This usually works fine with the standard MVC structure, since Localizer searches for the standard folders (Views/Models/Controllers).
Since im using Feature folder this does not work(its not searching the correct folders).
Have anyone made this work?

Orchard CMS Custom Module Project File

I have an existing solution (multiple projects, one MVC web project) that I'm trying to wrap into an Orchard module.
All documentation says that the web csproj should be at the root under my module directory (eg Modules/MyModule/MyWeb.csproj).
However, I have an existing solution structure where the sln file sits at the top level and each csproj file (and project content) sits in its own directory (the standard solution structure when you build a multi-project app in Visual Studio).
Is there a way I can tell my Module.txt file that the Orchard Module csproj is under MyModule/MyWeb/MyWeb.csproj? I'd prefer to not restructure the whole solution.
Thank you.
Note: As a point of clarification, it is not ~/Modules/MyModule/MyWeb.csproj but ~/Modules/MyModule/MyModule.csproj. The Folder name of the Module must match the file name of the project (before .csproj). This is enforced by the Dynamic Extension Loader, which requires ~/Module/{ModuleId}/{ModuleId}.csproj. (A similar approach is required for themes.)
The only potential way to do this is to write a custom module that follows the above that contains a custom loader. Within your module, create your own implementation of IExtensionLoader, and register it with Autofac. However, I don't know if it would work; I've never tried.
You will probably have an easier time reorganizing your solution.

Using log4net in a complex software

I'm using log4net logging in my software that consists of several applications.
I want to have one common library for this.
I created a library and put it in the conficuration file. In AssemblyInfo.cs placed attribute:
log4net.Config.XmlConfigurator(ConfigFile = #"c:\logging.xml", Watch = true)
It work for windows service, but in dosn't work for asp.net application.
It work in asp.net if delete attribute from common library and put in into global.asax. However, this leads to that section of the log4net configuration must be made in the windows service.
There is also a business process which causes our library through the
remouting. I want the logging was carried out there too.
Is there way around this?
In my opinion the library should not define where the configuration file is found. Maybe a better idea would be to have a helper method that allows you to configure log4net quickly; that method would take an optional parameter for the config file path and would try to load the configuration file from the specified path first and if that does not work fallback to some maybe the current folder, the application folder or even the web / app.config.
If you insist that it must be an absolute path then you need to give the IIS Application Pool user read access to this file. This way the configuration by attribute should work for services and ASP.Net applications. I do not understand what you mean by "remounting".

Resources