Forum OpenACS Q&A: Troubles exporting static-portlet to xowiki

I am trying to export static portlet to xowiki. For some strange reason the following script returns in a file export.tcl a different output than in developer shell:

set package_id 48643
set content ""
db_multirow -extend edit_url content select_content {
select content_id, body,
pretty_name
from static_portal_content
where package_id = :package_id
} {
set obj [::xowiki::Page create $content_id \
-set text $body \
-set title $pretty_name \
-set creation_user [ad_conn user_id] \
-set modifying_user [ad_conn user_id] \
-name "portlet-$content_id" \
-parent_id -100 \
-package_id [ad_conn package_id]]

$obj volatile
append content [$obj marshall] \n
}

The only difference is that in the shell I call

set content

to see the result and

ns_return 200 text/plain $content

in export.tcl.

In export.tcl I see this:

namespace eval ::template {}
::xowiki::Page create ::template::48901 -noinit \
-set creator {} \
-set page_order {} \
-set lang en \
-set creation_user 27685 \
-set render_adp 1 \
-set text {...} \
-set absolute_links 0 \
-set package_id 1456 \
-set folder_id -100 \
-set nls_language en_US \
-set name portlet-48901 \
-set mime_type text/plain \
-set publish_status ready \
-set title Hilfe \
-set revision_id 0 \
-set modifying_user 27685 \
-set parent_id -100
namespace eval ::template {namespace export query request form element}

As you can see two things are added:

namespace eval ::template {}
namespace eval ::template {namespace export query request form element}

missing in the shell and template::::template::48901 instead of ::48901.

Any idea where the template namespace suddenly comes from?

Collapse
Posted by Gustaf Neumann on
The script runs in ds/shell and in your export script in a different tcl namespace. Add e.g. "ns_log notice ns=[namespace current]" to your commands...

When a new object is created, the name might be absolute (with leading ::) or relative to the current namespace of tcl. To get your expected result, use an absolute name and do ::xowiki::Page create ::$content_id ...

Clear?

Collapse
Posted by Nima Mazloumi on
Yes. Thanks. It works now. For some reason when importing the file the content is not displayed correctly though it was imported fully. Any idea?

Is this an encoding problem?

::xowiki::Page create ::48901 -noinit \
	-set creator {} \
	-set page_order {} \
	-set lang en \
	-set creation_user 27685 \
	-set render_adp 1 \
-set text {<ol>
<li>FAQs
<ul>
<li>Für <a href="#/a/admin-faq">Admins</a>
<li>Für <a href="#/a/user-faq">Users</a> allgemein
<li><a href="#/help">Help</a>
</ul>
<li><a href="#/dotlrn/help">Hilfe</a>
<li><a href="#/support">Support Service</a>
<li><a href="#/shared/community-member?user_id=27685">Systemadministrator</a>
</ol>} \
	-set absolute_links 0 \
	-set package_id 1456 \
	-set folder_id -100 \
	-set nls_language en_US \
	-set name portlet-48901 \
	-set mime_type text/html \
	-set publish_status ready \
	-set title Hilfe \
	-set revision_id 0 \
	-set modifying_user 27685 \
	-set parent_id -100 

::xowiki::Page create ::48865 -noinit \
	-set creator {} \
	-set page_order {} \
	-set lang en \
	-set creation_user 27685 \
	-set render_adp 1 \
	-set text {

 Hallo - Willkommen..

} \ -set absolute_links 0 \ -set package_id 1456 \ -set folder_id -100 \ -set nls_language en_US \ -set name portlet-48865 \ -set mime_type text/html \ -set publish_status ready \ -set title {e-Learning Gruppe} \ -set revision_id 0 \ -set modifying_user 27685 \ -set parent_id -100
Collapse
Posted by Gustaf Neumann on
For content items of mime_type text/html, the convention in
OpenACS is to store in the contents of the attribute "text" 
the detailed mime-type as well. So instead of "hello world",
use "{{hello world" text/html}" 
Technically the contents are a tcl list with two elements. 

On import/export of xowiki, this field is not interpreted. 
So change your generation script to:

::xowiki::Page create ::48865 -noinit \
  ...
  -set text {{
 Hallo - Willkommen..
} text/html} \
  ...
Collapse
Posted by Nima Mazloumi on
Gustaf: Thank you very much.

Now admins can export static portlets to Xowiki. Next step would be to automatically convert them to xowiki and to remove the applet in a community. The applet removal I have implemented already.