use of org.exist.xmldb.EXistResource in project exist by eXist-db.
the class NewResourceDialog method createResource.
private void createResource(final ResourceType resourceType, final String filename, final String moduleNamespace, final String moduleNamespacePrefix) {
final StringBuilder resourceContentBuilder = new StringBuilder();
try (final InputStream is = getClass().getResourceAsStream(resourceType.getTemplatePath());
final Reader reader = new InputStreamReader(is)) {
final char[] buf = new char[1024];
int read = -1;
while ((read = reader.read(buf)) > -1) {
resourceContentBuilder.append(buf, 0, read);
}
} catch (final IOException ioe) {
ClientFrame.showErrorMessage(ioe.getMessage(), ioe);
}
final String resourceContent;
if (resourceType == ResourceType.XQUERY_LIBRARY) {
resourceContent = resourceContentBuilder.toString().replaceAll("\\$NS", moduleNamespace).replaceAll("\\$PREFIX", moduleNamespacePrefix);
} else {
resourceContent = resourceContentBuilder.toString();
}
try {
final String resName = URIUtils.urlEncodeUtf8((isNullOrEmpty(filename) ? DEFAULT_FILENAME : filename) + "." + resourceType.getFileExtension());
final String resType = resourceType == ResourceType.XML_DOCUMENT ? XMLResource.RESOURCE_TYPE : BinaryResource.RESOURCE_TYPE;
final Collection collection = client.current;
final Resource resource = collection.createResource(resName, resType);
resource.setContent(resourceContent);
((EXistResource) resource).setMimeType(resourceType.getMimeType());
collection.storeResource(resource);
collection.close();
client.reloadCollection();
} catch (final XMLDBException xmldbe) {
ClientFrame.showErrorMessage(xmldbe.getMessage(), xmldbe);
}
}
use of org.exist.xmldb.EXistResource in project exist by eXist-db.
the class TransformTest method addXMLDocument.
private void addXMLDocument(Collection c, String doc, String id) throws XMLDBException {
Resource r = c.createResource(id, XMLResource.RESOURCE_TYPE);
r.setContent(doc);
((EXistResource) r).setMimeType("application/xml");
c.storeResource(r);
}
use of org.exist.xmldb.EXistResource in project exist by eXist-db.
the class CleanupTest method setup.
@Before
public void setup() throws XMLDBException {
final CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
collection = service.createCollection("test");
final Resource doc = collection.createResource("test-module.xql", "BinaryResource");
doc.setContent(TEST_MODULE);
((EXistResource) doc).setMimeType("application/xquery");
collection.storeResource(doc);
}
use of org.exist.xmldb.EXistResource in project exist by eXist-db.
the class XQueryTest method wrongAddNamespace_1807014.
/**
* @see http://sourceforge.net/support/tracker.php?aid=1807014
*/
@Test
public void wrongAddNamespace_1807014() throws XMLDBException {
Collection testCollection = getTestCollection();
Resource doc = testCollection.createResource("a.xqy", "BinaryResource");
doc.setContent("module namespace a = \"http://www.a.com\"; " + "declare function a:selectionList() as element(ul) { " + "<ul class=\"a\"/> " + "};");
((EXistResource) doc).setMimeType("application/xquery");
testCollection.storeResource(doc);
String query = "declare option exist:serialize 'indent=no';" + "import module namespace a = \"http://www.a.com\" at \"xmldb:exist://db/test/a.xqy\"; " + "<html xmlns=\"http://www.w3.org/1999/xhtml\"> " + "{ a:selectionList() } " + "</html>";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
assertEquals(query, "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + "<ul xmlns=\"\" class=\"a\"/></html>", result.getResource(0).getContent().toString());
}
use of org.exist.xmldb.EXistResource in project exist by eXist-db.
the class DocTest method storeResource.
private void storeResource(final Collection col, final String fileName, final String type, final String mimeType, final String content) throws XMLDBException {
Resource res = col.createResource(fileName, type);
res.setContent(content);
if (mimeType != null) {
((EXistResource) res).setMimeType(mimeType);
}
col.storeResource(res);
}
Aggregations