Search in sources :

Example 46 with StringValue

use of org.exist.xquery.value.StringValue in project exist by eXist-db.

the class BaseConversionFunctionsTest method octalToInt.

@Test
public void octalToInt() throws XPathException {
    final XQueryContext mckContext = EasyMock.createMock(XQueryContext.class);
    final BaseConversionFunctions baseConversionFunctions = new BaseConversionFunctions(mckContext, BaseConversionFunctions.FNS_OCTAL_TO_INT);
    Sequence[] args = { new StringValue("0777") };
    final Sequence result = baseConversionFunctions.eval(args, null);
    assertEquals(1, result.getItemCount());
    assertEquals(511, (int) result.itemAt(0).toJavaObject(int.class));
}
Also used : XQueryContext(org.exist.xquery.XQueryContext) Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue) Test(org.junit.Test)

Example 47 with StringValue

use of org.exist.xquery.value.StringValue in project exist by eXist-db.

the class ExtTestAssumptionFailedFunction method assumptionMapAsAssumptionViolationException.

public AssumptionViolatedException assumptionMapAsAssumptionViolationException(final MapType assumptionMap) throws XPathException {
    final Sequence seqName = assumptionMap.get(new StringValue("name"));
    final String name;
    if (seqName != null && !seqName.isEmpty()) {
        name = seqName.itemAt(0).getStringValue();
    } else {
        name = "";
    }
    final Sequence seqValue = assumptionMap.get(new StringValue("value"));
    final String value;
    if (seqValue != null && !seqValue.isEmpty()) {
        value = seqValue.itemAt(0).getStringValue();
    } else {
        value = "";
    }
    return new AssumptionViolatedException("Assumption %" + name + " does not hold for: " + value);
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue)

Example 48 with StringValue

use of org.exist.xquery.value.StringValue in project exist by eXist-db.

the class ExtTestFailureFunction method expectedToString.

private String expectedToString(final MapType expected) throws XPathException, SAXException, IOException {
    final Sequence seqExpectedValue = expected.get(new StringValue("value"));
    if (!seqExpectedValue.isEmpty()) {
        return seqToString(seqExpectedValue);
    }
    final Sequence seqExpectedXPath = expected.get(new StringValue("xpath"));
    if (!seqExpectedXPath.isEmpty()) {
        return "XPath: " + seqToString(seqExpectedXPath);
    }
    final Sequence seqExpectedError = expected.get(new StringValue("error"));
    if (!seqExpectedError.isEmpty()) {
        return "Error: " + seqToString(seqExpectedError);
    }
    throw new IllegalStateException("Could not extract expected value");
}
Also used : Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue)

Example 49 with StringValue

use of org.exist.xquery.value.StringValue in project exist by eXist-db.

the class FindUserFunction method eval.

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    final DBBroker broker = getContext().getBroker();
    final Subject currentUser = broker.getCurrentSubject();
    final SecurityManager securityManager = broker.getBrokerPool().getSecurityManager();
    final Sequence result;
    if (isCalledAs(qnListUsers.getLocalPart())) {
        result = new ValueSequence();
        if (currentUser.getName().equals(SecurityManager.GUEST_USER)) {
            result.add(new StringValue(SecurityManager.GUEST_USER));
        } else {
            addUserNamesToSequence(securityManager.findAllUserNames(), result);
        }
    } else {
        if (currentUser.getName().equals(SecurityManager.GUEST_USER)) {
            throw new XPathException("You must be an authenticated user");
        }
        if (isCalledAs(qnUserExists.getLocalPart())) {
            final String username = args[0].getStringValue();
            result = BooleanValue.valueOf(securityManager.hasAccount(username));
        } else {
            result = new ValueSequence();
            final String startsWith = args[0].getStringValue();
            final List<String> usernames;
            if (isCalledAs(qnFindUsersByUsername.getLocalPart())) {
                usernames = securityManager.findUsernamesWhereUsernameStarts(startsWith);
            } else if (isCalledAs(qnFindUsersByName.getLocalPart())) {
                usernames = securityManager.findUsernamesWhereNameStarts(startsWith);
            } else if (isCalledAs(qnFindUsersByNamePart.getLocalPart())) {
                usernames = securityManager.findUsernamesWhereNamePartStarts(startsWith);
            } else {
                throw new XPathException("Unknown function");
            }
            addUserNamesToSequence(usernames, result);
        }
    }
    return result;
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) XPathException(org.exist.xquery.XPathException) ValueSequence(org.exist.xquery.value.ValueSequence) ValueSequence(org.exist.xquery.value.ValueSequence) Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue) Subject(org.exist.security.Subject)

Example 50 with StringValue

use of org.exist.xquery.value.StringValue in project exist by eXist-db.

the class GetPrincipalMetadataFunction method getPrincipalMetadata.

private Sequence getPrincipalMetadata(final Principal principal, final String metadataAttributeNamespace) {
    final AXSchemaType axSchemaType = AXSchemaType.valueOfNamespace(metadataAttributeNamespace);
    String metadataValue = null;
    if (axSchemaType != null) {
        metadataValue = principal.getMetadataValue(axSchemaType);
    } else {
        final EXistSchemaType exSchemaType = EXistSchemaType.valueOfNamespace(metadataAttributeNamespace);
        if (exSchemaType != null) {
            metadataValue = principal.getMetadataValue(exSchemaType);
        }
    }
    if (metadataValue == null || metadataValue.isEmpty()) {
        return Sequence.EMPTY_SEQUENCE;
    } else {
        return new StringValue(metadataValue);
    }
}
Also used : EXistSchemaType(org.exist.security.EXistSchemaType) StringValue(org.exist.xquery.value.StringValue) AXSchemaType(org.exist.security.AXSchemaType)

Aggregations

StringValue (org.exist.xquery.value.StringValue)96 Sequence (org.exist.xquery.value.Sequence)49 XPathException (org.exist.xquery.XPathException)40 ValueSequence (org.exist.xquery.value.ValueSequence)27 IOException (java.io.IOException)11 PermissionDeniedException (org.exist.security.PermissionDeniedException)10 Item (org.exist.xquery.value.Item)10 XQueryContext (org.exist.xquery.XQueryContext)8 Txn (org.exist.storage.txn.Txn)7 AnyURIValue (org.exist.xquery.value.AnyURIValue)7 QName (org.exist.dom.QName)6 LockException (org.exist.util.LockException)6 NodeValue (org.exist.xquery.value.NodeValue)6 Path (java.nio.file.Path)5 EXistException (org.exist.EXistException)5 TriggerException (org.exist.collections.triggers.TriggerException)5 DocumentImpl (org.exist.dom.persistent.DocumentImpl)5 StoredNode (org.exist.dom.persistent.StoredNode)5 NotificationService (org.exist.storage.NotificationService)5 MimeType (org.exist.util.MimeType)5