<< Previous | Home

Moving files in MarkLogic

xquery version "1.0-ml";

(:
https://developer.marklogic.com/recipe/move-a-document/
:)
declare function local:renameFile($uri as xs:string, $new as xs:string) {
    xdmp:log($uri || " => " || $new),
    let $lock := ($uri, $new) ! xdmp:lock-for-update(.)
    let $prop-ns := fn:namespace-uri-from-QName(xs:QName("prop:properties"))
    let $properties :=
      xdmp:document-properties($uri)/node()/node()
        [ fn:namespace-uri(.) ne $prop-ns ]
    return (
      xdmp:document-insert(
        $new,
        fn:doc($uri),
        xdmp:document-get-permissions($uri),
        xdmp:document-get-collections($uri)
      ),
      xdmp:document-delete($uri),
      xdmp:document-set-properties($new, $properties)
    )
};

for $uri as xs:string in cts:uri-match("directory-in-marklogic/*.xml")
let $new as xs:string := "/" || $uri
return 
    local:renameFile($uri, $new)
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

Hashing Files with sha256

Windows:

certutil -hashfile C:\path\to\file.exe SHA256

MarkLogic:

let $binary as binary() := xdmp:document-get("C:\path\to\file.exe")/binary()
return
    xdmp:sha256($binary)
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

A Tiny Scrap of JavaScript

Fifteen years ago, when "Web 2.0" was a thing, Ben Nolan's Behaviour.js enlightened me to the virtues of declarative programming.  Developing for a web-browser really lends itself to this approach.  Using "sheets" to target particular JavaScript code at selected DOM elements provides a way to separate, in a consistent way, the behaviorial aspects of a web-page.  For a while I'd subscribed to his advice to use JQuery instead, and this was incredibly effective but always felt like I was cheating.  Including JQuery in a web-page for a tiny bit of convenience was just heavy handed.  Now, 15 years later, I've finally weened myself off of that crutch too.  Below is a tiny scrap of JavaScript that leverages the native JavaScript Document.querySelectorAll() function...

function attachBehaviors(behaviors) {
    Object.entries(behaviors).forEach(([selector, behavior], index) => {
        document.querySelectorAll(selector).forEach(elm => {
            behavior.call(this, index, elm);
        });
    });
}
export {attachBehaviors};

With this function available, now pass a "sheet"...

attachBehaviors({
    'a.externallink': function(idx, elm) {
        elm.addEventListener('click', function(evt) {
            evt.preventDefault();
            window.open(evt.target.href);
        });
    },
    'form#uploadForm': function(idx, elm) {
        elm.addEventListener('submit', function(evt) {
            evt.preventDefault();
            processFiles();
        });
    }
});
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