| Feed Contents | |||
|---|---|---|---|
| Tip n Trick: How to use the new image crop function | by dizzzz | 5-3-2011 22:59 | |
| Tip n Trick: prevent REST browsing | by dizzzz | 26-5-2011 16:01 | |
| Tip n Trick: File locks under Windows | by dizzzz | 24-9-2011 17:01 | |
| Tip n Trick: collation ordering in xquery | by dizzzz | 24-9-2011 17:01 | |
| Tip n Trick: upload and validate XML | by dizzzz | 24-9-2011 17:02 | |
Tip n Trick: How to use the new image crop function
xquery version "1.0" encoding "utf-8";
declare namespace response="http://exist-db.org/xquery/response";
declare namespace image="http://exist-db.org/xquery/image";
import module "http://exist-db.org/xquery/util";
let $pathToBinaryResource := '/db/img/ztj/a0001.png'
let $original-path := '/exist/img/cropped.png'
let $img := util:binary-doc( xs:anyURI($pathToBinaryResource ) )
return response:stream-binary(
(:
The maximum dimension of the cropped image. expressed in
pixels (x1, y1, x2, y2)
:)
image:crop($img, (200, 150, 240, 240 ),
'image/png' ), 'image/png' ,
xs:anyURI( $original-path )
)
Thanks to Christian Wittern @exist-open
- 0 Comments
- Add Comment
Tip n Trick: prevent REST browsing
Sometimes, on a production server, you may want to store the application within the database, but without allowing users to browse the database contents. By setting hidden=true, you can expose defined URLs to the outside world via URL rewriting while hiding the rest of the database.
Add the following code to EXistServlet in web.xml:
<init-param> <param-name>hidden</param-name> <param-value>false</param-value> </init-param>
If parameter "hidden" is set to true, direct access to the REST interface will be denied. Only requests coming from the URL rewriting will be processed.
this is available on eXist-db version 1.5 only (yet)
Tip n Trick: File locks under Windows
Problem: locked 'webapps' files
When eXist-db is running under windows, all files that are stored in the 'webapps' directory (e.g. .xql files, .css files etc) are locked by the Operating system. As a result these files cannot be edited anymore, until the database is stopped.
Work around
The webserver Jetty tries to buffer static content (html, xql css js etc), for this memory mapped files are used. Under Windows however, memory mapping of files result into a lock of these files.
This behaviour can be changed by editing the jetty configuration file tools/jetty/etc/webdefault.xml:
<init-param> <param-name>useFileMappedBuffer</param-name> <param-value>true</param-value> <!-- change to false --> </init-param>
References
Tip n Trick: collation ordering in xquery
Although sorting text seems to be a simple process, it actually is not the case. Many languages have 'special' characters which should be taken into account in the sorting process.
Collation provide a choice of four ordering strengths: PRIMARY, SECONDARY, TERTIARY and IDENTICAL. The actual implementation is 'locale' dependent:
- Primary: deals with base letters e.g. "a" vs "b"
- Secondary: differences in accented forms of the same base letter: "a" vs "รค"
- Tertiary: case differences, "a" vs "A"
- Identical: Primary, Secondary and Tertiary, but different in control characters.
In xquery the collection can be used as demonstrated in the following code example:
for $a in $b order by $a collation "?strength=tertiary" return $a
References
Tip n Trick: upload and validate XML
I needed to be able to validate an XML document while the document should not be stored in the eXist-db database. The following code snipped shows how to do this
declare namespace util = "http://exist-db.org/xquery/util";
declare namespace validation = "http://exist-db.org/xquery/validation";
(: get file as base64 data from request object :)
let $upload := request:get-uploaded-file-data("upload")
(: convert base64 to string :)
let $text := util:binary-to-string($upload)
(: parse into node :)
let $parsed := util:parse($text)
(: validate :)
let $report := validation:jaxv-report($parsed , xs:anyURI('/db/myschema.xsd'))
