use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class FunStringToCodepoints method getCodePoints.
/**
* The method <code>getCodePoints</code>
*
* @param s a <code>String</code> value
* @return a <code>ValueSequence</code> value
*/
public static ValueSequence getCodePoints(final String s) {
final ValueSequence codepoints = new ValueSequence();
char ch;
IntegerValue next;
for (int i = 0; i < s.length(); i++) {
ch = s.charAt(i);
if (XMLCharUtil.isSurrogate(ch)) {
final int supp = XMLChar.supplemental(ch, s.charAt(++i));
next = new IntegerValue(supp);
} else {
next = new IntegerValue((int) ch);
}
codepoints.add(next);
}
return codepoints;
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class XQueryTest method importExternalClasspathMainModule.
@Test
public void importExternalClasspathMainModule() throws EXistException, IOException, PermissionDeniedException, XPathException, QName.IllegalQNameException {
final long timestamp = System.currentTimeMillis();
final BrokerPool brokerPool = BrokerPool.getInstance();
try (final DBBroker broker = brokerPool.getBroker()) {
final org.exist.source.Source source = SourceFactory.getSource(broker, "/", "resource:org/exist/xquery/external-classpath-main-module.xq", false);
final XQuery xquery = brokerPool.getXQueryService();
final XQueryPool queryPool = brokerPool.getXQueryPool();
CompiledXQuery compiled = null;
XQueryContext context = null;
try {
compiled = queryPool.borrowCompiledXQuery(broker, source);
if (compiled == null) {
context = new XQueryContext(brokerPool);
} else {
context = compiled.getContext();
context.prepareForReuse();
}
context.declareVariable(new QName("s"), new IntegerValue(timestamp));
if (compiled == null) {
compiled = xquery.compile(context, source);
}
final Sequence result = xquery.execute(broker, compiled, null, null);
assertEquals(1, result.getItemCount());
final Item item = result.itemAt(0);
assertTrue(Type.subTypeOf(item.getType(), Type.NODE));
final Source expected = Input.fromString("<echo>" + timestamp + "</echo>").build();
final Source actual = Input.fromNode((Node) item).build();
final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
assertFalse(diff.toString(), diff.hasDifferences());
} finally {
if (compiled != null) {
compiled.reset();
}
if (context != null) {
context.reset();
}
if (compiled != null) {
queryPool.returnCompiledXQuery(source, compiled);
}
}
}
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class MailStoreFunctions method getMailStore.
private Sequence getMailStore(Sequence[] args, Sequence contextSequence) throws XPathException {
Store store;
// was a session handle specified?
if (args[0].isEmpty()) {
throw (new XPathException(this, "Session handle not specified"));
}
// get the Session
long sessionHandle = ((IntegerValue) args[0].itemAt(0)).getLong();
Session session = MailModule.retrieveSession(context, sessionHandle);
if (session == null) {
throw (new XPathException(this, "Invalid Session handle specified"));
}
try {
String password = session.getProperty("mail." + session.getProperty("mail.store.protocol") + ".password");
if (password == null) {
password = session.getProperty("mail.password");
}
store = session.getStore();
store.connect(null, null, password);
} catch (MessagingException me) {
throw (new XPathException(this, "Failed to open mail store", me));
}
return (new IntegerValue(MailModule.storeStore(context, store)));
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class MailStoreFunctions method closeMailStore.
private Sequence closeMailStore(Sequence[] args, Sequence contextSequence) throws XPathException {
// was a store handle specified?
if (args[0].isEmpty()) {
throw (new XPathException(this, "Store handle not specified"));
}
// get the Store
long storeHandle = ((IntegerValue) args[0].itemAt(0)).getLong();
Store store = MailModule.retrieveStore(context, storeHandle);
if (store == null) {
throw (new XPathException(this, "Invalid Store handle specified"));
}
try {
store.close();
} catch (MessagingException me) {
throw (new XPathException(this, "Failed to close mail store", me));
} finally {
MailModule.removeStore(context, storeHandle);
}
return (Sequence.EMPTY_SEQUENCE);
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class MessageListFunctions method searchMessageList.
private Sequence searchMessageList(Sequence[] args, Sequence contextSequence) throws XPathException {
Message[] msgList;
// was a folder handle specified?
if (args[0].isEmpty() || args[1].isEmpty()) {
throw (new XPathException(this, "Folder handle or Search Terms not specified"));
}
// get the Folder
long folderHandle = ((IntegerValue) args[0].itemAt(0)).getLong();
Folder folder = MailModule.retrieveFolder(context, folderHandle);
if (folder == null) {
throw (new XPathException(this, "Invalid Folder handle specified"));
}
Node searchTermsXML = ((NodeValue) args[1].itemAt(0)).getNode();
try {
msgList = folder.search(parseSearchTerms(searchTermsXML));
prefetchMessages(folder, msgList);
} catch (MessagingException me) {
throw (new XPathException(this, "Failed to get mail list", me));
}
return (new IntegerValue(MailModule.storeMessageList(context, msgList, folderHandle)));
}
Aggregations