public static String normalizeName(final String name) { if(name == null){ return name; } return unquote(name.trim()).replaceAll("[^a-zA-Z_0-9 \\-_\\.]","_"); }
protected static List<Item> parseItemList(final List<String> attributes) { final List<Item> items = new ArrayList<>(); final Item item = new Item(); attributes.stream().forEach(attribute -> { if("ENDITEM".equals(attribute)){ addItem(items,item); } else { item.getAttributes().add(unescape(unquote(attribute))); } }); return items; }
private List<String> getOrderedItems(final Wini logicFileInfos, final String sectionName) { if(logicFileInfos.containsKey(sectionName)){ final Profile.Section section = logicFileInfos.get(sectionName); if(section != null) { final String orderedActionsList = MethodUtils.unquote(section.get("RunLogicActionOrder")); return Arrays.asList(orderedActionsList.split(",")); } } return Collections.emptyList(); }
public static String normalizeString(final String leftBrace, final String rightBrace, final String param) { if(param==null){ return ""; } return normalizeVariables(leftBrace, rightBrace, unescape(unquote(param))); }
/** * Find the url in the LR function and parse it to an URL Object * @param method represent the LR function * @param urlTag tag used to find the correct keywords in the function (also used for parsing) */ @VisibleForTesting protected static URL getUrlFromMethodParameters(final String leftBrace, final String rightBrace, MethodCall method, String urlTag) { Optional<String> urlParam = MethodUtils.getParameterWithName(method, urlTag); try { String urlString = MethodUtils.unquote(urlParam.orElseThrow(IllegalArgumentException::new)); //the +1 is for the "=" that follows the url tag return getUrlFromParameterString(leftBrace, rightBrace, urlString.substring(urlTag.length()+1)); }catch (IllegalArgumentException e) { LOGGER.error("Cannot find URL in WebUrl Node:"+method.getName() + "\nThe error is : " + e); } return null; }
private List<Element> buildGoToNextIterations(final MethodCall method, final ExitStatus exitStatus) { ImmutableList.Builder<Element> builder = ImmutableList.builder(); buildJavaScriptIfNeeded(exitStatus).ifPresent(builder::add); builder.add(ImmutableGoToNextIteration.builder() .name(MethodUtils.unquote(method.getName())) .build()); return builder.build(); }
private ImmutableList<Element> buildStopElements(final MethodCall method, final ExitStatus exitStatus) { ImmutableList.Builder<Element> builder = ImmutableList.builder(); buildJavaScriptIfNeeded(exitStatus).ifPresent(builder::add); builder.add(ImmutableStop.builder() .name(MethodUtils.unquote(method.getName())) .startNewVirtualUser(true) .build()); return builder.build(); }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size()!=2){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have 2 parameters"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String variableValue = MethodUtils.unquote(method.getParameters().get(0)); final String variableName = MethodUtils.unquote(method.getParameters().get(1)); final String name = "Set variable " + MethodUtils.normalizeName(variableName); return ImmutableList.of(ImmutableSaveString.builder().name(name).variableName(variableName).variableValue(variableValue).build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have at least 1 parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); return ImmutableList.of(ImmutableSaveString.builder() .name(MethodUtils.unquote(method.getName())) .variableName(SAP_ACTIVE_WINDOW) .variableValue(MethodUtils.unquote(method.getParameters().get(0))) .build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have at least 1 parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); return ImmutableList.of(ImmutableSaveString.builder() .name(MethodUtils.unquote(method.getName())) .variableName(SAP_ACTIVE_SESSION) .variableValue(MethodUtils.unquote(method.getParameters().get(0))) .build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); visitor.readUnsupportedFunction(method.getName(), ctx); final String returnValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); return ImmutableList.of(ImmutableEvalString.builder().name(MethodUtils.unquote(method.getName())).returnValue(returnValue).build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); Preconditions.checkNotNull(method.getParameters(), method.getName() + " method must have a parameter"); if(method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have a parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String returnValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); return ImmutableList.of(ImmutableEvalString.builder().name(MethodUtils.unquote(method.getName())).returnValue(returnValue).build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); Preconditions.checkNotNull(method.getParameters(), method.getName() + " method must have a parameter"); if(method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have a parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String returnValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); return ImmutableList.of(ImmutableEvalString.builder().name(MethodUtils.unquote(method.getName())).returnValue(returnValue).build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size()<2){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have at least 2 parameters"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String variableName = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); final String format = method.getParameters().get(1); final List<String> args = new ArrayList<>(); for(int index = 2; index < method.getParameters().size(); index++){ args.add(MethodUtils.getVariableName(method.getParameters().get(index))); } return ImmutableList.of(ImmutableSprintf.builder().name(MethodUtils.unquote(method.getName())).variableName(variableName).format(format).args(args).build()); } }
private static ImmutableCustomAction createSetTextCustomAction(final String name, final String objectId, final String objectName, final String objectType, final String value, final Type valueType) { return ImmutableCustomAction.builder() .name("SetText GuiTextField (" + name + ")") .type("SapSetText") .isHit(false) .parameters( ImmutableList.of(ImmutableCustomActionParameter.builder() .name("objectId").value(objectId).type(Type.TEXT).build(), ImmutableCustomActionParameter.builder() .name("objectName").value(objectName).type(Type.TEXT).build(), ImmutableCustomActionParameter.builder() .name("objectType").value(objectType).type(Type.TEXT).build(), ImmutableCustomActionParameter.builder() .name("value").value(MethodUtils.unquote(value)).type(valueType).build() )) .build(); }