use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class Hash method eval.
/* (non-Javadoc)
* @see org.exist.xquery.Expression#eval(org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
*/
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
boolean base64 = false;
final String message = args[0].itemAt(0).getStringValue();
final String algorithm = args[1].itemAt(0).getStringValue();
if (args.length > 2) {
base64 = args[2].effectiveBooleanValue();
}
String md = null;
try {
md = MessageDigester.calculate(message, algorithm, base64);
} catch (final IllegalArgumentException ex) {
throw new XPathException(ex.getMessage());
}
return (new StringValue(md));
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class BaseConversionFunctions method eval.
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
if (isCalledAs(qnIntToOctal.getLocalPart())) {
final int i = args[0].toJavaObject(Integer.class);
final String octal = i == 0 ? "0" : "0" + Integer.toOctalString(i);
return new StringValue(octal);
} else if (isCalledAs(qnOctalToInt.getLocalPart())) {
final String octal = args[0].toString();
return new IntegerValue(Integer.parseInt(octal, 8));
} else {
throw new XPathException("Unknown function call: " + getSignature());
}
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class BaseConverter method eval.
/* (non-Javadoc)
* @see org.exist.xquery.Expression#eval(org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
*/
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
int intValue;
String stringValue;
final String number = args[0].itemAt(0).getStringValue();
final int intBase = ((IntegerValue) args[1].itemAt(0)).getInt();
if (isCalledAs("base-to-integer")) {
intValue = Integer.parseInt(number, intBase);
return new IntegerValue(intValue);
} else {
switch(Base.getBase(intBase)) {
case BINARY:
stringValue = Integer.toBinaryString(Integer.parseInt(number));
break;
case OCTAL:
stringValue = Integer.toOctalString(Integer.parseInt(number));
break;
// break;
case HEXADECIMAL:
stringValue = Integer.toHexString(Integer.parseInt(number));
break;
default:
{
logger.error("Unhandled base for conversion target in integer-to-base().");
throw new XPathException("Unhandled base for conversion target in integer-to-base().");
}
}
return new StringValue(stringValue);
}
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class PermissionsFunction method functionModeToOctal.
private Sequence functionModeToOctal(final String modeStr) throws XPathException {
try {
final int mode = AbstractUnixStylePermission.simpleSymbolicModeToInt(modeStr);
final String octal = mode == 0 ? "0" : "0" + Integer.toOctalString(mode);
return new StringValue(octal);
} catch (final SyntaxException se) {
throw new XPathException(se.getMessage(), se);
}
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class GetAttributeNames method eval.
@Override
public Sequence eval(final Sequence[] args, @Nonnull final SessionWrapper session) throws XPathException {
final Optional<Enumeration<String>> maybeAttributeNames = withValidSession(session, SessionWrapper::getAttributeNames);
if (!maybeAttributeNames.isPresent()) {
return Sequence.EMPTY_SEQUENCE;
}
final Enumeration<String> attributeNames = maybeAttributeNames.get();
if (!attributeNames.hasMoreElements()) {
return Sequence.EMPTY_SEQUENCE;
}
final ValueSequence result = new ValueSequence();
while (attributeNames.hasMoreElements()) {
final String attributeName = attributeNames.nextElement();
result.add(new StringValue(attributeName));
}
return result;
}
Aggregations