use of org.eclipse.jetty.http2.parser.Parser in project syncope by apache.
the class AbstractJPAJSONAnyDAO method findByDerAttrValue.
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
@Override
public <A extends Any<?>> List<A> findByDerAttrValue(final String table, final AnyUtils anyUtils, final DerSchema derSchema, final String value, final boolean ignoreCaseMatch) {
if (derSchema == null) {
LOG.error("No DerSchema");
return List.of();
}
Parser parser = new Parser(derSchema.getExpression());
// Schema keys
List<String> identifiers = new ArrayList<>();
// Literals
List<String> literals = new ArrayList<>();
// Get schema keys and literals
for (Token token = parser.getNextToken(); token != null && StringUtils.isNotBlank(token.toString()); token = parser.getNextToken()) {
if (token.kind == ParserConstants.STRING_LITERAL) {
literals.add(token.toString().substring(1, token.toString().length() - 1));
}
if (token.kind == ParserConstants.IDENTIFIER) {
identifiers.add(token.toString());
}
}
// Sort literals in order to process later literals included into others
literals.sort((l1, l2) -> {
if (l1 == null && l2 == null) {
return 0;
} else if (l1 != null && l2 == null) {
return -1;
} else if (l1 == null) {
return 1;
} else if (l1.length() == l2.length()) {
return 0;
} else if (l1.length() > l2.length()) {
return -1;
} else {
return 1;
}
});
// Split value on provided literals
List<String> attrValues = split(value, literals);
if (attrValues.size() != identifiers.size()) {
LOG.error("Ambiguous JEXL expression resolution: literals and values have different size");
return List.of();
}
Map<String, List<Object>> clauses = new LinkedHashMap<>();
// builder to build the clauses
StringBuilder bld = new StringBuilder();
// Contains used identifiers in order to avoid replications
Set<String> used = new HashSet<>();
// Create several clauses: one for eanch identifiers
for (int i = 0; i < identifiers.size(); i++) {
if (!used.contains(identifiers.get(i))) {
// verify schema existence and get schema type
PlainSchema schema = plainSchemaDAO.find(identifiers.get(i));
if (schema == null) {
LOG.error("Invalid schema '{}', ignoring", identifiers.get(i));
} else {
// clear builder
bld.delete(0, bld.length());
PlainAttrValue attrValue;
if (schema.isUniqueConstraint()) {
attrValue = anyUtils.newPlainAttrUniqueValue();
} else {
attrValue = anyUtils.newPlainAttrValue();
}
attrValue.setStringValue(attrValues.get(i));
bld.append('(').append(queryBegin(table)).append("WHERE ").append(attrValueMatch(anyUtils, schema, attrValue, ignoreCaseMatch)).append(')');
used.add(identifiers.get(i));
List<Object> queryParams = new ArrayList<>();
queryParams.add(schema.getKey());
queryParams.add(attrValues.get(i));
clauses.put(bld.toString(), queryParams);
}
}
}
LOG.debug("Generated where clauses {}", clauses);
return buildResult(anyUtils, findByDerAttrValue(table, clauses));
}
use of org.eclipse.jetty.http2.parser.Parser in project sonar-iac by SonarSource.
the class CloudformationParser method parse.
@Override
public FileTree parse(String source, @Nullable InputFileContext inputFileContext) {
LoadSettings settings = LoadSettings.builder().setParseComments(shouldParseComments(inputFileContext)).build();
StreamReader reader = new StreamReader(settings, source);
ScannerImpl scanner = new ScannerImpl(settings, reader);
Parser parser = new ParserImpl(settings, scanner);
Composer composer = new Composer(settings, parser);
List<Node> nodes = composerNodes(composer);
return CloudformationConverter.convertFile(nodes);
}
use of org.eclipse.jetty.http2.parser.Parser in project carbon-mediation by wso2.
the class HL7MessageBuilder method serializeHL7toXML.
private String serializeHL7toXML(Message message) throws AxisFault {
Parser xmlParser = new DefaultXMLParser();
xmlParser.setValidationContext(new NoValidation());
try {
return xmlParser.encode(message);
} catch (HL7Exception e) {
throw new AxisFault("Error on converting to HL7 XML: " + e.getMessage(), e);
}
}
use of org.eclipse.jetty.http2.parser.Parser in project carbon-mediation by wso2.
the class HL7EndpointManager method validateParameters.
private void validateParameters(InboundProcessorParams params, Map<String, Object> parameters) {
if (!params.getProperties().getProperty(MLLPConstants.PARAM_HL7_AUTO_ACK).equalsIgnoreCase("true") && !params.getProperties().getProperty(MLLPConstants.PARAM_HL7_AUTO_ACK).equalsIgnoreCase("false")) {
log.warn("Parameter inbound.hl7.AutoAck in HL7 inbound " + params.getName() + " is not valid. Default " + "value of true will be used.");
params.getProperties().setProperty(MLLPConstants.PARAM_HL7_AUTO_ACK, "true");
}
try {
Integer.valueOf(params.getProperties().getProperty(MLLPConstants.PARAM_HL7_TIMEOUT));
} catch (NumberFormatException e) {
log.warn("Parameter inbound.hl7.TimeOut in HL7 inbound " + params.getName() + " is not valid. Default timeout " + "of " + MLLPConstants.DEFAULT_HL7_TIMEOUT + " milliseconds will be used.");
params.getProperties().setProperty(MLLPConstants.PARAM_HL7_TIMEOUT, String.valueOf(MLLPConstants.DEFAULT_HL7_TIMEOUT));
}
try {
if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_PRE_PROC) != null) {
final HL7MessagePreprocessor preProcessor = (HL7MessagePreprocessor) Class.forName(params.getProperties().getProperty(MLLPConstants.PARAM_HL7_PRE_PROC)).newInstance();
Parser preProcParser = new PipeParser() {
public Message parse(String message) throws HL7Exception {
message = preProcessor.process(message, Axis2HL7Constants.MessageType.V2X, Axis2HL7Constants.MessageEncoding.ER7);
return super.parse(message);
}
};
parameters.put(MLLPConstants.HL7_PRE_PROC_PARSER_CLASS, preProcParser);
}
} catch (Exception e) {
log.error("Error creating message preprocessor for HL7 inbound " + params.getName() + ": ", e);
}
try {
if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_CHARSET) == null) {
params.getProperties().setProperty(MLLPConstants.PARAM_HL7_CHARSET, MLLPConstants.UTF8_CHARSET.displayName());
parameters.put(MLLPConstants.HL7_CHARSET_DECODER, MLLPConstants.UTF8_CHARSET.newDecoder());
} else {
parameters.put(MLLPConstants.HL7_CHARSET_DECODER, Charset.forName(params.getProperties().getProperty(MLLPConstants.PARAM_HL7_CHARSET)).newDecoder());
}
} catch (UnsupportedCharsetException e) {
parameters.put(MLLPConstants.HL7_CHARSET_DECODER, MLLPConstants.UTF8_CHARSET.newDecoder());
log.error("Unsupported charset '" + params.getProperties().getProperty(MLLPConstants.PARAM_HL7_CHARSET) + "' specified in HL7 inbound " + params.getName() + ". Default UTF-8 will be used instead.");
}
if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_VALIDATE) == null) {
params.getProperties().setProperty(MLLPConstants.PARAM_HL7_VALIDATE, "true");
}
if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE) == null) {
params.getProperties().setProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE, "false");
} else {
if (!params.getProperties().getProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE).equalsIgnoreCase("true") && !params.getProperties().getProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE).equalsIgnoreCase("false")) {
params.getProperties().setProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE, "false");
}
}
if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_PASS_THROUGH_INVALID_MESSAGES) == null) {
params.getProperties().setProperty(MLLPConstants.PARAM_HL7_PASS_THROUGH_INVALID_MESSAGES, "false");
} else {
if (!params.getProperties().getProperty(MLLPConstants.PARAM_HL7_PASS_THROUGH_INVALID_MESSAGES).equalsIgnoreCase("true") && !params.getProperties().getProperty(MLLPConstants.PARAM_HL7_PASS_THROUGH_INVALID_MESSAGES).equalsIgnoreCase("false")) {
params.getProperties().setProperty(MLLPConstants.PARAM_HL7_PASS_THROUGH_INVALID_MESSAGES, "false");
}
}
}
use of org.eclipse.jetty.http2.parser.Parser in project commons-jexl by apache.
the class Engine method parse.
/**
* Parses an expression.
*
* @param info information structure
* @param parsingf the set of parsing features
* @param src the expression to parse
* @param scope the script frame
* @return the parsed tree
* @throws JexlException if any error occurred during parsing
*/
protected ASTJexlScript parse(final JexlInfo info, final JexlFeatures parsingf, final String src, final Scope scope) {
final boolean cached = src.length() < cacheThreshold && cache != null;
JexlFeatures features = parsingf != null ? parsingf : DEFAULT_FEATURES;
// if (features.getNameSpaces().isEmpty() && !functions.isEmpty()) {
// features = new JexlFeatures(features).nameSpaces(functions.keySet());
// }
final Source source = cached ? new Source(features, src) : null;
ASTJexlScript script;
if (source != null) {
script = cache.get(source);
if (script != null) {
final Scope f = script.getScope();
if ((f == null && scope == null) || (f != null && f.equals(scope))) {
return script;
}
}
}
final JexlInfo ninfo = info == null && debug ? createInfo() : info;
// if parser not in use...
if (parsing.compareAndSet(false, true)) {
try {
// lets parse
script = parser.parse(ninfo, features, src, scope);
} finally {
// no longer in use
parsing.set(false);
}
} else {
// ...otherwise parser was in use, create a new temporary one
final Parser lparser = new Parser(new StringProvider(";"));
script = lparser.parse(ninfo, features, src, scope);
}
if (source != null) {
cache.put(source, script);
}
return script;
}
Aggregations