From 1b6bba2d29f3afa2f44c48e9988584a43992080c Mon Sep 17 00:00:00 2001 From: rwincewicz Date: Mon, 28 May 2012 12:58:00 -0300 Subject: [PATCH 1/4] working on vertical tabs --- islandora_basic_collection/islandora_basic_collection.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/islandora_basic_collection/islandora_basic_collection.module b/islandora_basic_collection/islandora_basic_collection.module index 5d9a7350..58c0356c 100644 --- a/islandora_basic_collection/islandora_basic_collection.module +++ b/islandora_basic_collection/islandora_basic_collection.module @@ -30,8 +30,8 @@ function islandora_basic_collection_menu() { $items = array(); $items['islandora/object/%/manage/collection'] = array( 'title' => 'Collection Related', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('islandora_basic_collection_manage_object', 2), + 'page callback' => 'islandora_basic_collection_manage_object', + 'page arguments' => array(2), 'type' => MENU_LOCAL_TASK, 'access callback' => 'islandora_basic_collection_access', 'access arguments' => array(2), From 715dd70c392de646fb422ec55dac36ea44b16397 Mon Sep 17 00:00:00 2001 From: rwincewicz Date: Mon, 28 May 2012 14:44:18 -0300 Subject: [PATCH 2/4] Adding collection management functions from d6 module --- .../includes/ChildCollection.inc | 1 + .../includes/CollectionManagement.inc | 130 ++++++++++++++++-- .../includes/ManagePolicies.inc | 79 ++++++++++- 3 files changed, 194 insertions(+), 16 deletions(-) diff --git a/islandora_basic_collection/includes/ChildCollection.inc b/islandora_basic_collection/includes/ChildCollection.inc index 7f0efdd5..a443bfc5 100644 --- a/islandora_basic_collection/includes/ChildCollection.inc +++ b/islandora_basic_collection/includes/ChildCollection.inc @@ -24,6 +24,7 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle $form['child_creation']['collection_name'] = array( '#title' => "Collection Name", '#type' => 'textfield', + '#size' => 25, '#description' => t("Human readable name for this collection"), ); diff --git a/islandora_basic_collection/includes/CollectionManagement.inc b/islandora_basic_collection/includes/CollectionManagement.inc index cae0d6e5..a1856a0b 100644 --- a/islandora_basic_collection/includes/CollectionManagement.inc +++ b/islandora_basic_collection/includes/CollectionManagement.inc @@ -435,17 +435,18 @@ function get_represented_content_models($pid) { $restConnection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; - $query = "select \$model from <#ri> + $query = "select \$model \$title from <#ri> where (\$object or \$object ) - and \$object \$model"; + and \$object \$model + and \$object \$title"; $model_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); $represented_models = array(); foreach ($model_pids as $model_pid) { - if ($model_pid && $model_pid['object']['value'] != 'fedora-system:FedoraObject-3.0') { + if ($model_pid && $model_pid['model']['value'] != 'fedora-system:FedoraObject-3.0') { - $represented_models[$model_pid['object']['value']] = $model_pid['object']['value'] . ' ~ ' . $model_pid['title']['value']; + $represented_models[$model_pid['model']['value']] = $model_pid['model']['value'] . ' ~ ' . $model_pid['title']['value']; } } return $represented_models; @@ -492,7 +493,6 @@ function Islandora_collections_get_collection_from_pid($pid) { * @param $query_format R */ function get_related_items_as_array($collection_pid, $relationship = array('isMemberOfCollection'), $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') { -// module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'islandora', 'RestConnection'); $restConnection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; @@ -533,14 +533,6 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe $query_string .= ') minus $content order by ' . $orderby; - -// $query_string = htmlentities(urlencode($query_string)); -// -// -// $content = ''; -// $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); -// $url .= "?type=tuples&flush=TRUE&format=Sparql&limit=$limit&offset=$offset&lang=itql&stream=on&query=" . $query_string; -// $content .= do_curl($url); $results = $restConnection->repository->ri->itqlQuery($query_string, $limit, $offset); @@ -561,4 +553,114 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe // $resultsarray[] = substr($result->object->attributes()->uri, 12); // Remove 'info:fedora/'. // } // return $resultsarray; -//} \ No newline at end of file +//} + + /** + * gets the name of the content models for the specified object + * this now returns an array of pids as in Fedora 3 we can have more then one Cmodel for an object + * @param type $pid + * @param type $include_fedora_system_content_models + * @return array + */ + function get_content_models_list($pid, $include_fedora_system_content_models = FALSE) { +// module_load_include('inc', 'fedora_repository', 'CollectionClass'); +// module_load_include('inc', 'fedora_repository', 'ContentModel'); +// $collectionHelper = new CollectionClass(); + module_load_include('inc', 'islandora', 'RestConnection'); + require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; + $restConnection = new RestConnection(); + $pids = array(); + $query = 'select $object from <#ri> + where $object + and $object '; +// $content_models = $collectionHelper->getRelatedItems($pid, $query); + $content_models = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + + if (empty($content_models)) { + return $pids; + } + + $cmodels = array(); + foreach ($content_models as $content_model) { + if (strpos($content_model['object']['uri'], 'fedora-system:FedoraObject-3.0') != FALSE && $include_fedora_system_content_models == FALSE) { + continue; + } + $cmodels[] = substr(strstr($content_model['object']['uri'], '/'), 1); +// $cm = ContentModel::loadFromModel($cmodel_pid); +// if ($cm) { +// $cmodels[] = $cm; +// } + } + + return $cmodels; + } + + /** + * Function: get_content_models_as_option_array + * + * Description: Returns an associative array of all available content models in Fedora instance + * + * @return array + */ +function get_content_models_as_option_array() { + module_load_include('inc', 'islandora', 'RestConnection'); + $restConnection = new RestConnection(); + require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; + + $restricted = variable_get('fedora_namespace_restriction_enforced', TRUE); + $allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:'); + $namespaces = explode(':', $allowed_string); + foreach ($namespaces as $namespace) { + if ($namespace) { + $allowed[] = trim($namespace); + } + } + $query = 'select $object $title from <#ri> + where ($object $title + and ($object + or $object ) + and $object ) + order by $title'; + + $list = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $options = array(); + foreach ($list as $item) { //removes blanks + if ($item) { + $item_namespace = explode(':', $item['object']['value']); + if (!$restricted || in_array($item_namespace[0], $allowed)) { + + if (!preg_match('/fedora-system/', $item['object']['value'])) { + $options[$item['object']['value']] = $item['title']['value'] . ' ~ ' . $item['object']['value']; + } + } + } + } + + return $options; +} + + function getContentModels($collection_pid, $showError = TRUE) { + module_load_include('inc', 'islandora', 'RestConnection'); + $restConnection = new RestConnection(); +// module_load_include('inc', 'Fedora_Repository', 'ContentModel'); + $collection_stream = $this->getCollectionPolicyStream($collection_pid); + $collection_object = new FedoraObject($collection_pid, $restConnection->repository); + $collection_stream = $collection_object->getDatastream('COLLECTION_POLICY'); + try { + $xml = new SimpleXMLElement($collection_stream); + } catch (Exception $e) { + if ($showError) { + drupal_set_message(t('@e', array('@e' => check_plain($e->getMessage()))), 'error'); + } + return NULL; + } + foreach ($xml->contentmodels->contentmodel as $content_model) { + $contentModel = new ContentModel(); + $contentModel->contentModelDsid = $content_model->dsid; + $contentModel->contentModelPid = $content_model->pid; + $contentModel->pidNamespace = $content_model->pidNamespace; + $contentModel->contentModelName = $content_model['name']; + $models[] = $contentModel; + } + return $models; + } \ No newline at end of file diff --git a/islandora_basic_collection/includes/ManagePolicies.inc b/islandora_basic_collection/includes/ManagePolicies.inc index 9f5ae738..4381dcb9 100644 --- a/islandora_basic_collection/includes/ManagePolicies.inc +++ b/islandora_basic_collection/includes/ManagePolicies.inc @@ -1,12 +1,54 @@ repository); + $cm_name = $item->Label; + $cm_options[$content_model] = $cm_name; + } + } $new_options = array(); if (is_array($content_models) && is_array($cm_options)) { $new_options = array_diff_key($content_models, $cm_options); } + $namespace = substr($collection_pid, 0, strpos($collection_pid, ":")); + + $collection_policy_dsid = variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'); + $collection_object = new FedoraObject($collection_pid, $restConnection->repository); + $collection_policy_string = $collection_object->getDatastream($collection_policy_dsid); + $collection_policy = new CollectionPolicy($collection_policy_string->content); + + if ($collection_policy) { + $supported_collection_models = $collection_policy->getContentModels(); + } + $collection_namespace = substr($collection_pid, 0, strpos($collection_pid, ":")); + + $represented_content_models = get_represented_content_models($collection_pid); + $collection_name = $collection_object->label; + $new_content_models = get_content_models_as_option_array(); + $current_models_in_policy = array(); + + if ($supported_collection_models) { + foreach ($supported_collection_models as $supported_model) { + $current_models_in_policy[$supported_model['pid']] = $supported_model['pid']; + } + } + + $new_options = array(); + if (is_array($new_content_models) && is_array($current_models_in_policy)) { + $new_options = array_diff_key($new_content_models, $current_models_in_policy); + } + $form ['manage_collection_policy']['add']['content_model_to_add'] = array( '#title' => "Choose Content Model", '#type' => 'select', @@ -18,7 +60,7 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) { '#title' => "Choose Namespace", '#type' => 'textfield', '#size' => 15, - '#default_value' => $collection_namespace, + '#default_value' => $namespace, '#description' => t("Choose namespace for objects in this collection associated with this content model"), ); $form['manage_collection_policy']['add']['submit'] = array( @@ -57,5 +99,38 @@ function islandora_manage_policies_form_validate($form, &$form_state) { } function islandora_manage_policies_form_submit($form, &$form_state) { - + module_load_include('inc', 'islandora', 'RestConnection'); + $restConnection = new RestConnection(); + if ($form_state['clicked_button']['#id'] == 'add_cm') { + if (!$policy) { + $item = new Fedora_Item($collection_pid); + $item->add_datastream_from_string($collection_policy, 'COLLECTION_POLICY', 'COLLECTION_POLICY', 'text/xml', 'X'); + $policy = CollectionPolicy::loadFromCollection($collection_pid, TRUE); + } + + $cp_namespace = $form_state['values']['new_cp_namespace']; + $cp_content_model = $form_state['values']['content_model_to_add']; + $policy->addModel(ContentModel::loadFromModel($cp_content_model), $cp_namespace); + $policy->saveToFedora(); + drupal_set_message("Collection model successfully added"); + } + + //remove content model from collection policy + if ($form_state['clicked_button']['#id'] == 'remove_cm') { + $candidates = $form_state['values']['content_models_to_remove']; + $count = 0; + foreach ($candidates as $candidate) { + if (is_string($candidate)) { + $policy->removeModel(ContentModel::loadFromModel($candidate)); + $count++; + } + } + if ($count > 0) { + $policy->saveToFedora(); + if ($count > 1) { + $s = 's'; + } + drupal_set_message("$count collection model$s removed"); + } + } } \ No newline at end of file From 64eb8ebbacba7331d38a83459cb63dae513ef83e Mon Sep 17 00:00:00 2001 From: rwincewicz Date: Mon, 28 May 2012 16:34:26 -0300 Subject: [PATCH 3/4] Content model addition to collection now working --- .../includes/CollectionPolicy.inc | 119 ++++++++++++++++-- .../includes/ManagePolicies.inc | 80 ++++++++++-- 2 files changed, 182 insertions(+), 17 deletions(-) diff --git a/islandora_basic_collection/includes/CollectionPolicy.inc b/islandora_basic_collection/includes/CollectionPolicy.inc index 94cad1e1..2302f58d 100644 --- a/islandora_basic_collection/includes/CollectionPolicy.inc +++ b/islandora_basic_collection/includes/CollectionPolicy.inc @@ -1,4 +1,5 @@ validate() && $cm->validate()) { +// var_dump(self::valid_pid($namespace)); +// var_dump($this->validate()); +// var_dump($cm->validate()); +// if (self::valid_pid($namespace) && $this->validate() && $cm->validate()) { $contentmodelsEl = $this->xml->getElementsByTagName('content_models'); $models = $contentmodelsEl->item(0)->getElementsByTagName('content_model'); $found = FALSE; - for ($i = 0; !$found && $i < $models->length; $i++) { - if ($models->item($i)->getAttribute('pid') == $cm->pid) - $found = TRUE; - } +// for ($i = 0; !$found && $i < $models->length; $i++) { +// if ($models->item($i)->getAttribute('pid') == $cm->pid) +// $found = TRUE; +// } - if (!$found) { +// if (!$found) { $cmEl = $this->xml->createElement('content_model'); - $cmEl->setAttribute('name', $cm->getName()); + $cmEl->setAttribute('name', $cm->name); $cmEl->setAttribute('dsid', $cm->dsid); $cmEl->setAttribute('namespace', $namespace); $cmEl->setAttribute('pid', $cm->pid); $contentmodelsEl->item(0)->appendChild($cmEl); - } +// } $ret = !$found; - } +// } return $ret; } @@ -147,4 +151,101 @@ class CollectionPolicy { return $ret; } + /** + * valid_pid + * Validates a fedora PID based on the regexp provided in the fedora + * 3.3 documentation. + * http://www.fedora-commons.org/confluence/display/FCR30/Fedora+Identifiers + * + * @param String $pid + * @return boolean $valid + */ + public static function valid_pid($pid) { + $valid = FALSE; + if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) { + $valid = TRUE; + } + + return $valid; + } + + /** + * Validates the XMLDatastream against the schema location + * defined by the xmlns:schemaLocation attribute of the root + * element. If the xmlns:schemaLocation attribute does not exist, + * then it is assumed to be the old schema and it attempts to convert + * using the convertFromOldSchema method. + * + * TODO: Maybe change it so that it always validates against a known + * schema. This makes more sense because this class assumes the structure + * to be known after it has been validated. + * + * @return boolean $valid + */ + public function validate() { + global $user; + if ($this->valid === NULL) { + $ret = TRUE; + if ($this->xml == NULL) { + $this->fetchXml(); + } + // figure out if we're dealing with a new or old schema + $rootEl = $this->xml->firstChild; + if (!$rootEl->hasAttributes() || $rootEl->attributes->getNamedItem('schemaLocation') === NULL) { + //$tmpname = substr($this->pid, strpos($this->pid, ':') + 1); + $tmpname = user_password(10); + $this->convertFromOldSchema(); + drupal_add_js("fedora_repository_print_new_schema_$tmpname = function(tagID) { + var target = document.getElementById(tagID); + var content = target.innerHTML; + var text = 'Title' + + '' + content +''; + printerWindow = window.open('', '', 'toolbar=no,location=no,' + 'status=no,menu=no,scrollbars=yes,width=650,height=400'); + printerWindow.document.open(); + printerWindow.document.write(text); + }", 'inline'); + + if (user_access('administer site configuration')) { + drupal_set_message('Warning: XMLDatastream performed conversion of \'' . $this->getIdentifier() . '\' from old schema. Please update the datastream. The new datastream contents are here. '); + } + + $rootEl = $this->xml->firstChild; + } + + $schemaLocation = NULL; + if ($this->forceSchema) { + // hack because you cant easily get the static property value from + // a subclass. + $vars = get_class_vars(get_class($this)); + $schemaLocation = $vars['SCHEMA_URI']; + } + elseif ($rootEl->attributes->getNamedItem('schemaLocation') !== NULL) { + //figure out where the schema is located and validate. + list(, $schemaLocation) = preg_split('/\s+/', $rootEl->attributes->getNamedItem('schemaLocation')->nodeValue); + } + $schemaLocation = NULL; + return TRUE; + if ($schemaLocation !== NULL) { + if (!$this->xml->schemaValidate($schemaLocation)) { + $ret = FALSE; + $errors = libxml_get_errors(); + foreach ($errors as $err) { + self::$errors[] = 'XML Error: Line ' . $err->line . ': ' . $err->message; + } + } + else { + $this->name = $rootEl->attributes->getNamedItem('name')->nodeValue; + } + } + else { + $ret = FALSE; + self::$errors[] = 'Unable to load schema.'; + } + + $this->valid = $ret; + } + + return $this->valid; + } + } diff --git a/islandora_basic_collection/includes/ManagePolicies.inc b/islandora_basic_collection/includes/ManagePolicies.inc index 4381dcb9..dcb807c7 100644 --- a/islandora_basic_collection/includes/ManagePolicies.inc +++ b/islandora_basic_collection/includes/ManagePolicies.inc @@ -63,6 +63,17 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) { '#default_value' => $namespace, '#description' => t("Choose namespace for objects in this collection associated with this content model"), ); + + $form['parent_collection'] = array( + '#type' => 'hidden', + '#value' => $collection_pid, + ); + + $form['collection_pid'] = array( + '#type' => 'hidden', + '#value' => $collection_pid, + ); + $form['manage_collection_policy']['add']['submit'] = array( '#type' => 'submit', '#value' => t('Add Content Model to Collection Policy'), @@ -99,19 +110,55 @@ function islandora_manage_policies_form_validate($form, &$form_state) { } function islandora_manage_policies_form_submit($form, &$form_state) { + module_load_include('inc', 'islandora_basic_collection', 'CollectionPolicy'); module_load_include('inc', 'islandora', 'RestConnection'); $restConnection = new RestConnection(); + + $collection_pid = $form_state['values']['parent_collection']; + $collection_object = new FedoraObject($collection_pid, $restConnection->repository); + $policy = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY')); + $collection_policy = ' + + + + + + + + isMemberOfCollection +'; + + $collection_policy_xml = new DOMDocument(); + $collection_policy_xml->loadXML($policy->content); + if ($form_state['clicked_button']['#id'] == 'add_cm') { - if (!$policy) { - $item = new Fedora_Item($collection_pid); - $item->add_datastream_from_string($collection_policy, 'COLLECTION_POLICY', 'COLLECTION_POLICY', 'text/xml', 'X'); - $policy = CollectionPolicy::loadFromCollection($collection_pid, TRUE); + if (!$policy->content) { + $collection_policy_datastream = $collection_object->constructDatastream('COLLECTION_POLICY', 'X'); + $collection_policy_datastream->setContentFromString($collection_policy); + $collection_policy_datastream->label = 'COLLECTION_POLICY'; + $collection_object->ingestDatastream($collection_policy_datastream); + $policy = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY')); } $cp_namespace = $form_state['values']['new_cp_namespace']; $cp_content_model = $form_state['values']['content_model_to_add']; - $policy->addModel(ContentModel::loadFromModel($cp_content_model), $cp_namespace); - $policy->saveToFedora(); + $content_model_object = new FedoraObject($cp_content_model, $restConnection->repository); + $content_model_datastream = $content_model_object->getDatastream(variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); + + $content_models_element = $collection_policy_xml->getElementsByTagName('content_models'); + $content_model_element = $content_models_element->item(0)->getElementsByTagName('content_model'); + + $content_model_element = $collection_policy_xml->createElement('content_model'); + $content_model_element->setAttribute('name', $content_model_object->label); + $content_model_element->setAttribute('dsid', variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); + $content_model_element->setAttribute('namespace', $cp_namespace); + $content_model_element->setAttribute('pid', $content_model_object->id); + $content_models_element->item(0)->appendChild($content_model_element); + + $new_collection_policy_datastream = $collection_object->getDatastream('COLLECTION_POLICY'); + $new_collection_policy_datastream->setContentFromString($collection_policy_xml->saveXML()); + $new_collection_policy_datastream->label = 'COLLECTION_POLICY'; + $collection_object->ingestDatastream($new_collection_policy_datastream); drupal_set_message("Collection model successfully added"); } @@ -119,14 +166,31 @@ function islandora_manage_policies_form_submit($form, &$form_state) { if ($form_state['clicked_button']['#id'] == 'remove_cm') { $candidates = $form_state['values']['content_models_to_remove']; $count = 0; + $s = ''; foreach ($candidates as $candidate) { if (is_string($candidate)) { - $policy->removeModel(ContentModel::loadFromModel($candidate)); + + $content_models_element = $collection_policy_xml->getElementsByTagName('content_models'); + $models = $content_models_element->item(0)->getElementsByTagName('content_model'); + $found = FALSE; + for ($i = 0; $found === FALSE && $i < $models->length; $i++) { + if ($models->item($i)->getAttribute('pid') == $candidate) { + $found = $models->item($i); + } + } + + if ($found !== FALSE && $models->length > 1) { + $content_models_element->item(0)->removeChild($found); + $ret = TRUE; + } $count++; } } if ($count > 0) { - $policy->saveToFedora(); + $new_collection_policy_datastream = $collection_object->getDatastream('COLLECTION_POLICY'); + $new_collection_policy_datastream->setContentFromString($collection_policy_xml->saveXML()); + $new_collection_policy_datastream->label = 'COLLECTION_POLICY'; + $collection_object->ingestDatastream($new_collection_policy_datastream); if ($count > 1) { $s = 's'; } From c0a53e31b837ffe9a1d07298dec2d6d33ab63f84 Mon Sep 17 00:00:00 2001 From: rwincewicz Date: Mon, 28 May 2012 16:40:08 -0300 Subject: [PATCH 4/4] Bug fix for collection management when no collection_policy datastream exists --- islandora_basic_collection/includes/ManagePolicies.inc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/islandora_basic_collection/includes/ManagePolicies.inc b/islandora_basic_collection/includes/ManagePolicies.inc index dcb807c7..a1dbe861 100644 --- a/islandora_basic_collection/includes/ManagePolicies.inc +++ b/islandora_basic_collection/includes/ManagePolicies.inc @@ -26,9 +26,10 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) { $collection_policy_dsid = variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'); $collection_object = new FedoraObject($collection_pid, $restConnection->repository); $collection_policy_string = $collection_object->getDatastream($collection_policy_dsid); - $collection_policy = new CollectionPolicy($collection_policy_string->content); - if ($collection_policy) { + $supported_collection_models = array(); + if ($collection_policy_string) { + $collection_policy = new CollectionPolicy($collection_policy_string->content); $supported_collection_models = $collection_policy->getContentModels(); } $collection_namespace = substr($collection_pid, 0, strpos($collection_pid, ":")); @@ -132,7 +133,7 @@ function islandora_manage_policies_form_submit($form, &$form_state) { $collection_policy_xml->loadXML($policy->content); if ($form_state['clicked_button']['#id'] == 'add_cm') { - if (!$policy->content) { + if (empty($policy->content)) { $collection_policy_datastream = $collection_object->constructDatastream('COLLECTION_POLICY', 'X'); $collection_policy_datastream->setContentFromString($collection_policy); $collection_policy_datastream->label = 'COLLECTION_POLICY';