xotcl.wu-wien.ac.at
Begin main content
Methods: Source: Variables:
[All Methods | Documented Methods | Hide Methods] [Display Source | Hide Source] [Show Variables | Hide Variables]

::xowiki::Object[i] ::xowiki::exporter

::xowiki::Object create ::xowiki::exporter

Methods

  • proc export

    ::247844 proc export item_ids {
        #
        # include implictely needed objects, instantiate the objects.
        #
        set item_ids [my include_needed_objects $item_ids]
        #
        # stream the objects via ns_write
        #
        ns_set put [ns_conn outputheaders] "Content-Type" "text/plain"
        ns_set put [ns_conn outputheaders] "Content-Disposition" "attachment;filename=export.xotcl"
        ReturnHeaders 
        
        foreach item_id $item_ids {
          ns_log notice "--exporting $item_id [$item_id name]"
          ns_write "# exporting $item_id [$item_id name] [$item_id pretty_link]\n"
          if {[catch {set obj [$item_id marshall]} errorMsg]} {
    	ns_log error "Error while exporting $item_id [$item_id name]\n$errorMsg\n$::errorInfo"
          } else {
    	ns_write "$obj\n" 
          }
        }
      }
    
  • proc include_needed_objects

    ::247844 proc include_needed_objects item_ids {
        #
        # Load the objects
        #
        foreach item_id $item_ids {
          if {[::xo::db::CrClass get_instance_from_db -item_id $item_id] eq ""} {
    	my log "Warning: cannot fetch item $item_id for exporting"
          } else {
    	set items($item_id) 1
          }
        }
    
        #
        # In a second step, include the objects which should be exported implicitly
        #
        while {1} {
          set new 0
          ns_log notice "--export works on [array names items]"
          foreach item_id [array names items] {
    	#
    	# We flag the reason, why the implicitely included elements were
    	# included. If the target can resolve already such items
    	# (e.g. forms), we might not have to materialize these finally.
    	#
    	# For PageInstances (or its subtypes), include the parent-objects as well
    	#
    	if {[$item_id istype ::xowiki::PageInstance]} {
    	  set template_id [$item_id page_template]
    	  if {![info exists items($template_id)]} {
    	    ns_log notice "--export including template-object $template_id [$template_id name]"
    	    set items($template_id) 1
    	    ::xo::db::CrClass get_instance_from_db -item_id $template_id
    	    set new 1
    	    $template_id set __export_reason implicit_page_template
    	    continue
    	  }
    	}
    	#
    	# check for child objects of the item
    	#
    	set sql [::xowiki::Page instance_select_query -folder_id $item_id -with_subtypes true]
    	db_foreach [my qn export_child_obj] $sql {
    	  if {![info exists items($item_id)]} {
    	    ::xo::db::CrClass get_instance_from_db -item_id $item_id
    	    ns_log notice "--export including child $item_id [$item_id name]"
    	    set items($item_id) 1 
    	    set new 1
    	    $item_id set __export_reason implicit_child_page
    	  }
    	}
          }
          if {!$new} break
        }
        return [array names items]
      }
    
  • proc marshall_all

    ::247844 proc marshall_all item_ids {
        set content ""
        foreach item_id $item_ids {
          if {[catch {set obj [$item_id marshall]} errorMsg]} {
    	ns_log error "Error while exporting $item_id [$item_id name]\n$errorMsg\n$::errorInfo"
    	error $errorMsg
          } else {
    	append content $obj\n
          }
        }
        return $content
      }
    

Methods: Source: Variables:
[All Methods | Documented Methods | Hide Methods] [Display Source | Hide Source] [Show Variables | Hide Variables]