Reputation: 539
I'm fairly new to exide and exist-db so i'm getting used to it's gui and menus and ways of doing stuff. my problem is that i already have a project, a teacher downloaded it from his exist and gave it to me as a .rar.
the thing is that i want to import that project in a way that it keeps the same folder structure that it has. i've tried importing it through the collections menu but it ignores the folder structure and just uploads all the files in one folder
folder structure is as follows:
final:
-db
-contrib
-file
-file
-css
-somecss
-somecss
-js
-somejs
-somejs
-img
-img1.png
-xqueryelement.xq
-xqueryelement2.xq
-htmlelement.html
Upvotes: 1
Views: 1117
Reputation: 5294
Besides the approaches suggested by Ron and Loren, you could use a WebDAV client - probably the simplest. Or you can write a query (e.g., in eXide) using the xmldb:store-files-from-pattern()
function. All of the above are mentioned in the article, Getting Data into eXist-db.
If you're interested in using the xmldb:store-files-from-pattern()
function, here are specific directions. You'll use the variant of the function with the $preserve-structure
parameter. The direct link to the function documentation for this variant of the function is http://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/xmldb#store-files-from-pattern.5. Here are steps:
http://localhost:8080/exist/apps/eXide
on your local system). Log in, e.g., as the admin user, so that your query will be able to write to the database.Use this query:
xquery version "3.0";
let $collection-uri := '/db'
let $directory := '/path/to/files'
let $pattern := '**/*'
let $mime-type := ()
let $preserve-structure := true()
return
xmldb:store-files-from-pattern($collection-uri, $directory, $pattern, $mime-type, $preserve-structure)
Upvotes: 3
Reputation: 1347
If when the .rar file is extracted out and each folder contains "_ _ contents_ _.xml", then you can use the restore functionality from the java admin client.
If it does not, then you can use the following. (I have not tested the code and wrote it on the fly.) Launch eXide from the dashboard. Log in as admin and then copy the code below into the ide and then run it.
The code has some functions copied from Priscilla Walmsley's FUNCTX function module. http://www.xqueryfunctions.com/
xquery version "3.0";
declare namespace file="http://exist-db.org/xquery/file";
(:~
: Escapes regex special characters
:
: @author Priscilla Walmsley, Datypic
: @version 1.0
: @see http://www.xqueryfunctions.com/xq/functx_escape-for-regex.html
: @param $arg the string to escape
:)
declare function local:escape-for-regex( $arg as xs:string? ) as xs:string {
replace($arg, '(\.|\[|\]|\\|\||\-|\^|\$|\?|\*|\+|\{|\}|\(|\))','\\$1')
} ;
(:~
: The substring before the last occurrence of a delimiter
:
: @author Priscilla Walmsley, Datypic
: @version 1.0
: @see http://www.xqueryfunctions.com/xq/functx_substring-before-last.html
: @param $arg the string to substring
: @param $delim the delimiter
:)
declare function local:substring-before-last( $arg as xs:string?, $delim as xs:string ) as xs:string {
if (matches($arg, local:escape-for-regex($delim)))
then replace($arg,
concat('^(.*)', local:escape-for-regex($delim),'.*'),
'$1')
else ''
} ;
(:~
: The substring after the last occurrence of a delimiter
:
: @author Priscilla Walmsley, Datypic
: @version 1.0
: @see http://www.xqueryfunctions.com/xq/functx_substring-after-last.html
: @param $arg the string to substring
: @param $delim the delimiter
:)
declare function local:substring-after-last
( $arg as xs:string? ,
$delim as xs:string ) as xs:string {
replace ($arg,concat('^.*',local:escape-for-regex($delim)),'')
} ;
declare function local:import($base as xs:string, $path as xs:string) {
let $offset := fn:substring-after($path, $base)
return
if (file:is-directory($path))
then
let $created := xmldb:create-collection('/', '/')
let $coll := for $resource in file:list($path)
return local:import($base, $path || '/' || $resource)
return $path
else
let $collection : = local:substring-before-last($offset, '/')
let $resource : = local:substring-after-last($offset, '/')
let $stored := xmldb:store($collection, $resource,
file:read-binary($path), 'application/octet-stream')
let $permission := if (fn:ends-with($resource, ".xq"))
then sm:chmod($collection || '/' || $resource, 'rwxr-xr-x')
else ()
return $path
};
let $base := '/tmp/lctmp'
let $path := '/tmp/lctmp/db'
return local:import($base, $path)
Upvotes: 2
Reputation: 409
To upload folder structures in eXist, you have 2 options:
http://localhost:8080/exist/webstart/exist.jnlp
or via the link in the dashboard at http://localhost:8080/exist/apps/dashboard/index.html
; or via the pop-up menu in the quick-launch button (quick launch toolbar in the bottom right if you're on Windows). There you can add entire folders.Hope this helps,
Ron
Upvotes: 2