Thursday, 14 August 2014

Fixing 1 property on nodes in content

First of all locate all of the data I need :-

p.hits=selective target/pageInformation

This gives me a JSON output.  Put the JSON output in a file and transform the file :

perl -pe 's/},{/\n/g' < raw_data.json > raw_data.txt

I now have line separators.  Edit the raw_data.txt and remove the first line, relating to "success" of the query.

Run the following Perl program to generate curl commands which will put the data on to the target CQ instance :-


sub trim($)
    my $string = shift;
    $string =~ s/^\s+//;
    $string =~ s/\s+$//;
    return $string;

open (FILE, 'raw_data.txt');
while (<FILE>)

($jcr_path_data, $page_information_data) = split("\",\"");
($rubbish1, $target_path) = split("\":\"", $jcr_path_data);
($rubbish2, $page_information) = split("\":\"", $page_information_data);

$target_path =~ s/"//g;
$page_information =~ s/"//g;

if ($page_information =~ /^''''''''/)
    $page_information =~ s/^''''''''/''''en''''/;


$CURL_CMD = "/usr/bin/curl -u \"" . $TARGET_USER . ":" . $TARGET_PASS . "\" -F \"_charset_=UTF-8\" -F \"pageInformation=" . $page_information . "\" \"http://" . $TARGET_HOST . "$target_path/target\"";

print ($CURL_CMD) . "\n";
print "\n"; print "\n";

Redirect the output of this to a separate file & then execute that file.  This way we have a record of the commands that were executed.

Note, that the form field name "_charset_=UTF-8" allows you to post accented characters.  This way you can use curl to HTTP POST data in the correct charset to Apache Sling.  See the "Character Encoding" section of : Apache Sling - Request Parameter Handling in Sling