Different strict mode value for different templates for Qute in Quarkus - quarkus

I use Quarkus which uses Qute as a template engine.
Is it possible to have strict mode true for some template(s) and strict-mode false for some other(s)?
#Location("report1-strict.html")
Template templateStrict;
#Location("report2-nonstrict.html")
Template templateNonStrict;
I've checked Qute configuration and it looks like strict mode can be set only for an Engine and not for a Template or as some parameter of a render(...) methods.
Then maybe it's possible to have 2 engines in Quarkus app?
Do I need to create another Qute Engine instance manuyally?
The best would be to set up a strict mode on template rendering manually but it doesn't seem to be possible.

Is it possible to have strict mode true for some template(s) and strict-mode false for some other(s)?
No, this is not possible. Strict rendering can be configured per an Engine instance.
Then maybe it's possible to have 2 engines in Quarkus app? Do I need to create another Qute Engine instance manuyally?
You can have many Engine instances but only the instance preconfigured by Quarkus is fully integrated, i.e. you would have to mimic the logic from the EngineProducer.

Related

Spring boot 2 - Template system recommendation needed for commerce site

We are planning to design a commerce site, using Spring boot as back end.
We would like our customers to be able to customize the front end template provided or create their own front templates.
Spring boot by default supports many templates, however, it seems there is no way to use them safely by the end customer, for example, they could call static methods if they know the class and method names.
It seems the correct way (without inventing a new safe template system) is to use front end template system. The idea is we provide a set of restful apis, and the template consumes the data and render the UI.
Are there any existing front end template systems / page builder we can use? Ideally, the template supports drag and drop editing of the template, as the customers are not developers.
Thanks!

Is it possible to disable an OSGi component programmatically in CQ?

Rather than manually making configuration changes to OSGi components in Felix, it's good practice to create sling:OsgiConfig nodes in the JCR to make sure that the settings are version controlled, applied the same across environments, etc.
Similarly, I want to disable an out-of-the-box component on each environment. Is there any way to achieve this via configuration? Rather than going to system/console/components and disabling it there?
Anything I've read about this has mentioned making changes internally within the bundle, but since it's one that I don't own, I'd need some external configuration to do this.
You can do this with the ScrService, which is published by the SCR runtime bundle. API documentation is here.
Note that ScrService is not "standard", i.e. it doesn't come from the OSGi specification. However it is supported by Felix and Equinox and Knopflerfish, so it's pretty much a de facto standard. In fact this service is used by the Web Console when you go to system/console/components.
Try to use attribute policy=ConfigurationPolicy.REQUIRE on #Component.
Then you could prepare a set of packages with configurations for each environment as part of the build. This is also a good practice for having different OSGI configurations for each environment.
So for some of enironments you could just simply not provide a configuration for a particular component. Such component would not run - it would have unsatisfied status.
I believe I've seen this approach in AEM itself.
You can also create a filter to remove current configurations but it still would require to disable the Component at least once. And this solution will work only if this component has mentioned policy.
The other way around is to prepare a Service that would be responsible for disabling other components - it could be configurable. But it doesn't sound like a good solution to me.

Does anybody use Jersey in embedded mode(not servlet env but standalone Grizzly instance) successfully with a template engine?

Velocity, Freemarker, Japid, Rythm, any other?
What i am looking for is a solution similar to what JSP provides in servlet environment. It should be a form of ViewProcessor implementation, but working on standalone embedded Grizzly deployment(NIO architecture).
Jersey has support for freemarker templates - see jersey-freemarker module on maven. It works with any container (i.e. is not depending on servlet). There is also freemarker sample in Jersey workspace that shows how to use it - see here.
I think all the template engines you listed could be used in an independent environment. Specifically for Rythm (coz I am the author of this stuff), it loads template files from different sources:
from the String content supplied:
String result = Rythm.render("hello #who", "world");
from a file found from the rythm.root setting:
String result = Rythm.render("helloWorld.html", "world");
from a file found from the class path if you have no rythm.root setup
It just doesn't depend on any servlet container, so you are free to use it as long as you have JRE. Be sure to set rythm.noFileWrite to true if you want to use it in GAE where no file write is allowed.
The Open Source Project
http://www.bitplan.com/index.php/SimpleRest
supplies a TemplateResource base class which will do most of the "heavy lifting" to make Jersey, Grizzly and the Rythm template engine work together nicely.

OSGi and Component Management

I have a dynamic application that uses OSGi to load modular functionality at runtime. OSGi bundles contain the modular functionality and the application loads the bundles when they are needed. This approach works okay, but I would like a more granular solution. The bundles contain components controlled through Declarative Services. I'd like to be able to load a bundle, and only enable the components that are needed within the bundle. I've done research in this area, but cannot find a solution that I'm satisfied with. One approach was to create a "gatekeeper" component that is always enabled in the bundle and through the ComponentContext let it call enable and disable component. It's a viable solution, but I could not figure out a way for the "gatekeeper" to "know about" the other components in the bundle without hard coding the component names as properties in the "gatekeepers" SCR xml descriptor.
What I prefer is a way to load bundles and "know about" all components within the loaded bundles. Be able to determine what bundle the components are located in and what state they are currently in (similar to the equinox console command 'ls' that lists out all components). I would like to enable and disable the components when needed.
How does the console do this and how could I do this in an application?
Update:
#Neil Bartlett: Sorry for the delay. I had to move on to something else. Now I'm back on this issue. Really would appreciate any further assistance. My application is role based. I need to enable components based on the functionality they provide. The goal is for all role based components to initially be disabled. Upon role change, a role manager polls each component for its provided functionality and determines whether to load it. Each component will broadcast what functionality it provides (through a common service interface). ScrService will not allow me to enable an initially disabled service component. Having the components initially enabled and let ScrService disable them as soon as possible during application startup does not fit my needs.
Have a look at ScrService. Bothe equinox and felix has it.
However, components can be made to load lazily, i.e. only when needed by other components/bundles; but that is perhaps not what you want.
In your service description, mark the components as enabled, but requiring configuration information provided by the Configuration Management service. you then can write a CM plugin service (can't remember the exact term) that can publish and modify the configuration of your components. Services by default are identified by their name, which by default is their implementation class name. Configuration data is passed as a map, and it can be empty. DS will make the service available as soon as the CM provides a configuration.
I have a similar issue, but for a different purpose:
- I have apache file install and configuration admin service to configure my components externally with property files.
- I needed to make sure that some components get the config from the outer file and the only way I've found so far is that I mark my components with ConfigurationPolicy.REQUIRED.
- But that way my plugin projects doesn't run in eclipse (where there are no config files).
- The component.xml also contains a default development configuration so I'm okay with that, just my component doesn't start until there is a config data avalilable with configadmin. My components ar unsatisfied this way, until someone creates a configadmin entry.
- I figured out that if I create a osgi command line extender that sends empty configurations to service pid's they would start up with default values in component.xml files.
- I just came here to find a way to list all bundles
But I think this solution I use can also work with your setup and that's why I write this.
Just mark all your components with the configurtationpolicy.require and you can selectively start and stop them with adding and removing configurations with configadmin. This could be hard if you already use the configadmin for other purposes too, but it may be managable as a last resort.

Applying settings in Spring based application in runtime

We have Spring based (Spring.NET) web application and use VariablePlaceholderConfigurer to keep some settings in a separate properties file.
These properties are mainly different values affecting business logic, like emails, timeouts, paths, etc.
Now we need to implement administrative UI to allow users to change these settings in more friendly way.
So we will move all these settings to a database.
Question: What is the best (standard, common) approach to implementing settings like I described in Spring based application? (Assuming we want changes to be effective immediately without application restart.)
It is good if we can keep our current approach when setting values as just properties of beans.
The VariablePlaceholderConfigurer is ObjectFactoryPostProcessor, which is only invoked after reading the object definitions. So you cannot simply introduce a new IVariableSource that you refer to in your VariablePlaceholderConfigurer configuration, because it will only take effect after container reload.
You have to create an IObjectObjectPostProcessor to modify properties on container managed objects at runtime.

Resources