Skip to content
Permalink
Browse files

fixed bug which prevented deleted pages to be reused;

added support for the storage of binary resources;
added "declare ..." to XQuery prolog.

svn path=/trunk/eXist-1.0/; revision=141
  • Loading branch information
wolfgangmm committed Nov 5, 2003
1 parent 991914f commit 542794bb5fd4ba67897c2c2677f4f663483ba69d
@@ -36,7 +36,7 @@ fi

JAVA_ENDORSED_DIRS="$EXIST_HOME"/lib/endorsed

JAVA_OPTIONS="$JAVA_OPTIONS -Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS"
JAVA_OPTIONS="$JAVA_OPTIONS -Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS -Dexist.start.debug=true"

# save LANG
if [ -n "$LANG" ]; then
@@ -54,7 +54,7 @@
- indent: should the serializer pretty-print (indent) xml?
-->
<serializer enable-xinclude="true" enable-xsl="false"
indent="false" add-exist-id="element" match-tagging-elements="true"
indent="false" add-exist-id="element" match-tagging-elements="false"
match-tagging-attributes="false"/>

<!-- settings for the indexer
@@ -0,0 +1,13 @@
xquery version "1.0";
declare default element namespace "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace d="http://purl.org/dc/elements/1.1/";

(: Find all publication dates and print out a list of titles
for each date :)
for $p in distinct-values(//d:date)
let $books := //Description[d:date &= $p]
return
<result>
<year titles="{count($books)}">{$p}</year>
{for $b in $books return $b/d:title}
</result>
@@ -0,0 +1,11 @@
xquery version "1.0";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace dc="http://purl.org/dc/elements/1.1/";

for $p in distinct-values(//dc:creator)
let $books := //rdf:Description[dc:creator&=$p]
return
<result>
<creator titles="{count($books)}">{$p}</creator>
{for $b in $books return $b/dc:title}
</result>
@@ -0,0 +1,10 @@
xquery version "1.0";

declare variable $x { //SPEECH[SPEAKER="HAMLET"] };

for $s in $x
let $t := $s/ancestor::SCENE/TITLE
return
<scene title="{$t}">
{$s}
</scene>
@@ -30,6 +30,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -82,6 +83,7 @@
import org.xmldb.api.base.Resource;
import org.xmldb.api.base.ResourceSet;
import org.xmldb.api.base.XMLDBException;
import org.xmldb.api.modules.BinaryResource;
import org.xmldb.api.modules.CollectionManagementService;
import org.xmldb.api.modules.XMLResource;
import org.xmldb.api.modules.XPathQueryService;
@@ -118,7 +120,8 @@
private final static int RECURSE_DIRS_OPT = 'd';
private final static int NO_GUI_OPT = 's';
private final static int TRACE_QUERIES_OPT = 'T';

private final static int OUTPUT_FILE_OPT = 'O';

private final static CLOptionDescriptor OPTIONS[] =
new CLOptionDescriptor[] {
new CLOptionDescriptor(
@@ -204,6 +207,11 @@
CLOptionDescriptor.ARGUMENT_REQUIRED,
RESULTS_OPT,
"max. number of query results to be displayed."),
new CLOptionDescriptor(
"output",
CLOptionDescriptor.ARGUMENT_REQUIRED,
OUTPUT_FILE_OPT,
"write output of command into given file (use with -x, -g)."),
new CLOptionDescriptor(
"option",
CLOptionDescriptor.ARGUMENTS_REQUIRED_2 | CLOptionDescriptor.DUPLICATES_ALLOWED,
@@ -559,15 +567,20 @@ protected boolean process(String line) {
System.err.println("wrong number of arguments.");
return true;
}
XMLResource res = retrieve(args[1]);
Resource res = retrieve(args[1]);
// display document
if (res != null) {
String data;
if(res.getResourceType().equals("XMLResource"))
data = (String) res.getContent();
else
data = new String((byte[])res.getContent());
if (startGUI) {
frame.setEditable(false);
frame.display((String) res.getContent());
frame.display(data);
frame.setEditable(true);
} else {
String content = (String) res.getContent();
String content = data;
more(content);
}
}
@@ -670,6 +683,16 @@ protected boolean process(String line) {
boolean r = parse(args[1]);
getResources();
return r;

} else if (args[0].equalsIgnoreCase("blob")) {
// put a document or directory into the database
if (args.length < 2) {
messageln("missing argument.");
return true;
}
storeBinary(args[1]);
getResources();

} else if (args[0].equalsIgnoreCase("rm")) {
// remove document
if (args.length < 2) {
@@ -1087,15 +1110,15 @@ public void run() {
}
}

protected final XMLResource retrieve(String resource) throws XMLDBException {
protected final Resource retrieve(String resource) throws XMLDBException {
return retrieve(resource, properties.getProperty("indent"));
}

protected final XMLResource retrieve(String resource, String indent) throws XMLDBException {
protected final Resource retrieve(String resource, String indent) throws XMLDBException {
current.setProperty(OutputKeys.INDENT, indent);
current.setProperty(OutputKeys.ENCODING, properties.getProperty("encoding"));
current.setProperty(EXistOutputKeys.EXPAND_XINCLUDES, properties.getProperty("expand-xincludes"));
XMLResource res = (XMLResource) current.getResource(resource);
Resource res = current.getResource(resource);
if (res == null) {
messageln("document not found.");
return null;
@@ -1110,7 +1133,7 @@ private final void remove(String pattern) throws XMLDBException {
return;
}
Resource resources[];
XMLResource res = (XMLResource) collection.getResource(pattern);
Resource res = collection.getResource(pattern);
if (res == null)
resources = CollectionScanner.scan(collection, "", pattern);
else {
@@ -1119,7 +1142,7 @@ private final void remove(String pattern) throws XMLDBException {
}
Collection parent;
for (int i = 0; i < resources.length; i++) {
message("removing document " + ((XMLResource) resources[i]).getDocumentId() + " ...");
message("removing document " + resources[i].getId() + " ...");
parent = resources[i].getParentCollection();
parent.removeResource(resources[i]);
messageln("done.");
@@ -1151,6 +1174,15 @@ private final void rmcol(String collection) throws XMLDBException {
messageln("done.");
}

private final void storeBinary(String fileName) throws XMLDBException {
File file = new File(fileName);
if(file.canRead()) {
BinaryResource resource = (BinaryResource)current.createResource(file.getName(), "BinaryResource");
resource.setContent(file);
current.storeResource(resource);
}
}

private final File[] findFiles(String pattern) {
String pathSep = System.getProperty("file.separator", "/");
String baseDir = ".", globExpr = pattern;
@@ -1460,7 +1492,7 @@ private final void mkcol(String collPath) throws XMLDBException {
*
*@param args Description of the Parameter
*/
public void run(String args[]) {
public void run(String args[]) throws Exception {
// read properties
properties = new Properties(defaultProps);
try {
@@ -1508,6 +1540,7 @@ public void run(String args[]) {
String optionQueryFile = null;
String optionXUpdate = null;
String optionResource = null;
String optionOutputFile = null;
List optionalArgs = new ArrayList();
for (int i = 0; i < size; i++) {
option = (CLOption) opt.get(i);
@@ -1547,6 +1580,9 @@ public void run(String args[]) {
case RESOURCE_OPT :
optionResource = option.getArgument();
break;
case OUTPUT_FILE_OPT :
optionOutputFile = option.getArgument();
break;
case PARSE_OPT :
doParse = true;
if (option.getArgumentCount() == 1)
@@ -1716,9 +1752,21 @@ public void run(String args[]) {
}
if (optionGet != null) {
try {
XMLResource res = retrieve(optionGet);
if (res != null)
System.out.println(res.getContent());
Resource res = retrieve(optionGet);
if(res != null) {
String data;
if(res.getResourceType().equals("XMLResource")) {
if(optionOutputFile != null)
writeOutputFile(optionOutputFile, res.getContent());
else
System.out.println(res.getContent().toString());
} else {
if(optionOutputFile != null)
writeOutputFile(optionOutputFile, res.getContent());
else
System.out.println(new String((byte[]) res.getContent()));
}
}
} catch (XMLDBException e) {
System.err.println(
"XMLDBException while trying to retrieve document: " + e.getMessage());
@@ -1748,15 +1796,23 @@ public void run(String args[]) {
e.printStackTrace();
}
}
} else if (optionXpath != null) {
} else if (optionXpath != null || optionQueryFile != null) {
if(optionQueryFile != null) {
BufferedReader reader = new BufferedReader(new FileReader(optionQueryFile));
StringBuffer buf = new StringBuffer();
String line;
while((line = reader.readLine()) != null)
buf.append(line);
optionXpath = buf.toString();
}
// if no argument has been found, read query from stdin
if (optionXpath.equals("stdin")) {
try {
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
StringBuffer buf = new StringBuffer();
String line;
while((line = stdin.readLine()) != null)
buf.append(line);
buf.append(line + '\n');
optionXpath = buf.toString();
} catch (IOException e) {
System.err.println("failed to read query from stdin");
@@ -1766,15 +1822,24 @@ public void run(String args[]) {
if (optionXpath != null) {
try {
ResourceSet result = find(optionXpath);
for (int i = 0; i < maxResults && i < result.getSize(); i++)
System.out.println(((Resource) result.getResource((long) i)).getContent());
if(maxResults <= 0)
maxResults = (int)result.getSize();
if(optionOutputFile == null) {
for (int i = 0; i < maxResults && i < result.getSize(); i++)
System.out.println(((Resource) result.getResource((long) i)).getContent());
} else {
FileWriter writer = new FileWriter(optionOutputFile, false);
for (int i = 0; i < maxResults && i < result.getSize(); i++)
writer.write(((Resource) result.getResource((long) i)).getContent().toString());
writer.close();
}
} catch (XMLDBException e) {
System.err.println("XMLDBException during query: " + e.getMessage());
e.printStackTrace();
}
}
} else if (optionQueryFile != null) {
testQuery(optionQueryFile);
// } else if (optionQueryFile != null) {
// testQuery(optionQueryFile);
} else if (optionXUpdate != null) {
try {
xupdate(optionResource, optionXUpdate);
@@ -1935,6 +2000,19 @@ else if (o instanceof org.exist.storage.TextSearchEngine)
}
}

private static void writeOutputFile(String fileName, Object data) throws Exception {
File file = new File(fileName);
if(data instanceof byte[]) {
FileOutputStream os = new FileOutputStream(file);
os.write((byte[])data);
os.close();
} else {
FileWriter writer = new FileWriter(file);
writer.write(data.toString());
writer.close();
}
}

private static String formatString(String s1, String s2, int width) {
StringBuffer buf = new StringBuffer(width);
if (s1.length() > width)

0 comments on commit 542794b

Please sign in to comment.
You can’t perform that action at this time.