<< September 2013 | Home | November 2013 >>

MarkLogic XQuery MultiUpload

Some jQuery and XQuery code to load content into a MarkLogic database:

'form#uploadForm': function(idx, elm) {
    var form = $(elm)
    form.submit(function(evt) {
        evt.preventDefault();
        rn_util.log('SUBMITTED: ', form);
        
        $.ajax({
            url: 'spike/uploadController.xqy',
            type: 'POST',
            data: new FormData(elm),
            cache: false,
            contentType: false,
            processData: false,
            beforeSend: function(jqXHR, settings) {
                rn_util.log('beforeSend', jqXHR.upload);
            },
            success: function(data, textStatus, jqXHR) {
                rn_util.log('POST COMPLETED: ', textStatus, '; ', jqXHR);
            }
        });
    });
}
xquery version "1.0-ml";

declare namespace zip = "xdmp:zip";
declare namespace aib = "co.wlv.xml.aib";

xdmp:log("GREETINGS:UPLOAD"),

for $headerName as xs:string in xdmp:get-request-header-names()
return 
    xdmp:log(concat("HEADERNAME: ", $headerName, " = ", xdmp:get-request-header($headerName))),
    
for $fieldName as xs:string in xdmp:get-request-field-names()
return 
    xdmp:log(concat("FIELDNAME: ", $fieldName)),
    
for $inputFile as xs:string in xdmp:get-request-field-filename("inputFiles")
return xdmp:log(concat("FILENAME: ", $inputFile)),

let $fileNames as xs:string* := xdmp:get-request-field-filename("inputFiles"),
    $inventory as element(aib:inventory) := doc("/packages/inventory.xml")/aib:inventory
for $inputFile as item() at $i in xdmp:get-request-field("inputFiles")
let $fileName as xs:string := $fileNames[$i],
    $packageUri as xs:anyURI := xs:anyURI(concat("/packages/package-", xdmp:random())),
    $zipManifest as node() := xdmp:zip-manifest($inputFile)
return (
    xdmp:log(concat("FILE: ", $fileName, ";&#10;", xdmp:quote($zipManifest), "&#10;COUNT: ", count($zipManifest/zip:part))),
    xdmp:node-insert-child($inventory, element {QName("co.wlv.xml.aib", "package")} {
        attribute uri {$packageUri},
        attribute name {$fileName},
        attribute added {current-dateTime()},
        for $part as element(zip:part) in $zipManifest/zip:part
        let $file as node()+ := xdmp:zip-get($inputFile, string($part)),
            $XXX := xdmp:log(xs:anyURI(concat($packageUri, "/", replace(string($part), "\\", "/")))),
            $fileUri as xs:anyURI := xs:anyURI(concat($packageUri, "/", replace(string($part), "\\", "/")))
        return (
            xdmp:log(concat("PART: ", string($part), "; COUNT: ", count($file))),
            xdmp:document-insert($fileUri, $file[1]),
            element {QName("co.wlv.xml.aib", "file")} {
                attribute uri {$fileUri},
                attribute size {$part/@uncompressed-size},
                $part/@last-modified
            }
        )
    })
)
Social Bookmarks :  Add this post to Slashdot    Add this post to Digg    Add this post to Reddit    Add this post to Delicious    Add this post to Stumble it    Add this post to Google    Add this post to Technorati    Add this post to Bloglines    Add this post to Facebook    Add this post to Furl    Add this post to Windows Live    Add this post to Yahoo!

Export this post as PDF document  Export this post to PDF document

Add CA Certificate To Java Keystore

It seems Oracle has changed parameters for the Java keytool command...

keytool -importcert -file ca-20130221.cer -alias wlvds -keystore cacerts -keypass changeit

List certificates in a keystore...

.\bin\keytool.exe -list -cacerts
Tags : ,
Social Bookmarks :  Add this post to Slashdot    Add this post to Digg    Add this post to Reddit    Add this post to Delicious    Add this post to Stumble it    Add this post to Google    Add this post to Technorati    Add this post to Bloglines    Add this post to Facebook    Add this post to Furl    Add this post to Windows Live    Add this post to Yahoo!

Export this post as PDF document  Export this post to PDF document