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));
}
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);
}
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");
}
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;
}
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);
}
}
Aggregations