dakaspbe
New Creator

Edit content page with API

Hi,

I want to edit a content page within a Beanshell script using the API.

This is the script part I tried:

 if (!page.isLocked()) {
   page.setLock(true, true);
}
 
...
page.setFormData(formData);
page.save();
page.release();
page.setLock(false, false);
 

Currently I get the following Error when I try to lock the page in the first step:

Target exception: java.lang.UnsupportedOperationException: lock is not supported for release store elements

Does anybody why this Exception occurs and how I can avoid it.

Or is there another way to edit the page?

Thanks in Advanced

0 Kudos
17 Replies

Hi Michael,

i'm not shure whether this fits for my needs. As discribed I need to find all external links in my project to create a whitelist with all referenced domains.

in our old script we just simply used 

de.espirit.firstspirit.ps.findexternalhosts.FindExternalHosts.find()

My first approach was to collect the url during the generation but this is not possible. Thus I have to reimplement the FindExternalHosts somehow.

As I'm a totally newbie it's very hard to understand your comments or the API documentations.

Kind regards 

Bernadette

0 Kudos

Hi Peter,

I tried this appoach. It seams that the incomingReferences are the section within the linktemplate is used. How do I get the used links within a section? 

Kind regards

Bernadette

0 Kudos
Peter_Jodeleit
Crownpeak employee

I'll try to find someone in the company who knows something about the internals of the class de.espirit.firstspirit.ps.findexternalhosts.FindExternalHosts 
Due to the holiday season this may take a while. Judging from the class name this was a project or customer specific implementation from our Professional Services team. Do you have more insights about this? Maybe the name of the module that provided this functionality and in which context this has been built? And why this is no longer available in your environment.

Peter
0 Kudos
mbergmann
Crownpeak employee

Hi Bernadette,

in general, collecting the external links during generation is a valid approach. Especially as the "real" output is decided during generation and other mechanisms that only rely on FormData might - depending on your templates - gather too many entries (in case those are not rendered) or also miss others (if there are "other mechanisms" than just form entries that create external links).

The problem here is in my opinion that you try to save it into a page.

An option would be to "remember" those links in the schedule context in a variable (e.g. a map).

You can use #global.scheduleContext here which will give a ScheduleContext object. On that, you can use set/getProperty to store a List or Map of URLs / domains. Of course you'd rather "bundle" that mechanism in a rendertemplate or script that is just called and also "extracts" the domain from the complete URL etc). The schedule context properties remain valid during the current execution of the whole schedule and thus allow "information transfer" from one schedule task to another.

Hint: Mind the difference between get/setPropertyand  get/setVariable as the latter has a more "permanent" character and is (invisibly) stored "in the schedule" after a schedules's execution and could be accessed during later executions of the same schedule. That MIGHT (at least partially) be intended if you use mechanisms like partial or delta generation - depending on the concrete logic / code that fills the list.

After the generation of the "normal" content, you could then (for example) generate a "technical page" that accesses that variable and renders the whitelist. That should be a separate partial generation task in the schedule to make sure it is executed after the generation of the content.

Michael

 

Hi Peter,

thanks for this remark. I wasn't aware that this is a customer specific implementation. Your hint lead me to old source code. The module was not working since our last first spirit update.

I had a look into the code. The functionality is like this:

iterate through all references of the linktemplates and search in the formdata for the url-field. 

But it's not working anylonger due to some errors. 

As we have redesigned the setup of our pages I think this approach will be very difficult. The text with the links can be in different form-fields within multiple FS_CATALOG-entries.

Kind regards

Bernadette

0 Kudos

Hi Michael,

this was a very good idea. It works. I can store the external host during the generation of the links and retrieve the stored entries to create the whitelist in a separate generation call.

Last point is how to trigger the generation of the whitelist-page during the generate_partly-schedule.

I tried to add a generate-action in the task administration. But unfortunately the task breaks with errors although I see no errors in the log.

Is it possible to trigger the generation with a context script?

 

Kind regards

Bernadette

0 Kudos
mbergmann
Crownpeak employee

Hi Bernadette,

hmm, usually that should work. Sounds strange especially that there is no error in the log... Do you have more details?

Using a context script would not help in this case as the information "lives" only in the schedule context and is not accessible from "outside". So the "whitelist generation" has to be in the same schedule - at least when following that approach (which usually works well in similar situations).

Kind regards

Michael

0 Kudos

Hi Michael,

this is very strange. Today everything works fine. The new additional generation of the whitelist works now without errors. The only difference to yesterday is that I closed the server manager before starting the generation.

Right now I'm doing some tests but the first impression is very good. The pages and the whitelist with all used external domains are generated correctly.

 

Thank you very much for all your help,

Bernadette

0 Kudos