Search in sources :

Example 46 with IntegerValue

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;
}
Also used : IntegerValue(org.exist.xquery.value.IntegerValue) ValueSequence(org.exist.xquery.value.ValueSequence)

Example 47 with IntegerValue

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);
            }
        }
    }
}
Also used : Diff(org.xmlunit.diff.Diff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) QName(org.exist.dom.QName) IntegerValue(org.exist.xquery.value.IntegerValue) Node(org.w3c.dom.Node) XMLResource(org.xmldb.api.modules.XMLResource) EXistResource(org.exist.xmldb.EXistResource) Resource(org.xmldb.api.base.Resource) Sequence(org.exist.xquery.value.Sequence) Source(javax.xml.transform.Source) XQueryPool(org.exist.storage.XQueryPool) Item(org.exist.xquery.value.Item) DBBroker(org.exist.storage.DBBroker) BrokerPool(org.exist.storage.BrokerPool)

Example 48 with IntegerValue

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)));
}
Also used : XPathException(org.exist.xquery.XPathException) MessagingException(jakarta.mail.MessagingException) IntegerValue(org.exist.xquery.value.IntegerValue) Store(jakarta.mail.Store) Session(jakarta.mail.Session)

Example 49 with IntegerValue

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);
}
Also used : XPathException(org.exist.xquery.XPathException) MessagingException(jakarta.mail.MessagingException) IntegerValue(org.exist.xquery.value.IntegerValue) Store(jakarta.mail.Store)

Example 50 with IntegerValue

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)));
}
Also used : NodeValue(org.exist.xquery.value.NodeValue) Message(jakarta.mail.Message) XPathException(org.exist.xquery.XPathException) MessagingException(jakarta.mail.MessagingException) IntegerValue(org.exist.xquery.value.IntegerValue) Node(org.w3c.dom.Node) Folder(jakarta.mail.Folder)

Aggregations

IntegerValue (org.exist.xquery.value.IntegerValue)63 Sequence (org.exist.xquery.value.Sequence)33 XPathException (org.exist.xquery.XPathException)32 BrokerPool (org.exist.storage.BrokerPool)11 DBBroker (org.exist.storage.DBBroker)11 Test (org.junit.Test)11 Txn (org.exist.storage.txn.Txn)8 MessagingException (jakarta.mail.MessagingException)7 StringInputSource (org.exist.util.StringInputSource)7 NamingException (javax.naming.NamingException)6 DirContext (javax.naming.directory.DirContext)6 QName (org.exist.dom.QName)6 Source (org.exist.source.Source)6 StringSource (org.exist.source.StringSource)6 InputStream (java.io.InputStream)5 Map (java.util.Map)5 StringValue (org.exist.xquery.value.StringValue)5 ValueSequence (org.exist.xquery.value.ValueSequence)5 Folder (jakarta.mail.Folder)4 Image (java.awt.Image)4