use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class TestHTTPSamplersAgainstHttpMirrorServer method getBoundaryStringFromContentType.
private String getBoundaryStringFromContentType(String requestHeaders) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
String regularExpression = "^" + HTTPConstants.HEADER_CONTENT_TYPE + ": multipart/form-data; boundary=(.+)$";
Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
if (localMatcher.contains(requestHeaders, pattern)) {
MatchResult match = localMatcher.getMatch();
String matchString = match.group(1);
// Header may contain ;charset= , regexp extracts it so computed boundary is wrong
int indexOf = matchString.indexOf(';');
if (indexOf >= 0) {
return matchString.substring(0, indexOf);
} else {
return matchString;
}
} else {
return null;
}
}
use of org.apache.oro.text.regex.Perl5Matcher in project canal by alibaba.
the class SimpleDdlParser method parseRename.
private static DdlResult parseRename(String queryString, String schmeaName, String pattern) {
Perl5Matcher matcher = new Perl5Matcher();
if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
DdlResult orign = parseTableName(matcher.getMatch().group(1), schmeaName);
DdlResult target = parseTableName(matcher.getMatch().group(2), schmeaName);
if (orign != null && target != null) {
return new DdlResult(target.getSchemaName(), target.getTableName(), orign.getSchemaName(), orign.getTableName());
}
}
return null;
}
use of org.apache.oro.text.regex.Perl5Matcher in project intellij-plugins by JetBrains.
the class GherkinPsiUtil method buildParameterRanges.
@Nullable
public static List<TextRange> buildParameterRanges(@NotNull GherkinStep step, @NotNull AbstractStepDefinition definition, final int shiftOffset) {
final List<TextRange> parameterRanges = new ArrayList<>();
final Pattern pattern = definition.getPattern();
if (pattern == null)
return null;
final Perl5Matcher matcher = new Perl5Matcher();
if (matcher.contains(step.getStepName(), pattern)) {
final MatchResult match = matcher.getMatch();
final int groupCount = match.groups();
for (int i = 1; i < groupCount; i++) {
final int start = match.beginOffset(i);
final int end = match.endOffset(i);
if (start >= 0 && end >= 0) {
parameterRanges.add(new TextRange(start, end).shiftRight(shiftOffset));
}
}
}
int k = step.getText().indexOf(step.getStepName());
k += step.getStepName().length();
if (k < step.getText().length() - 1) {
String text = step.getText().substring(k + 1);
boolean inParam = false;
int paramStart = 0;
int i = 0;
while (i < text.length()) {
if (text.charAt(i) == '<') {
paramStart = i;
inParam = true;
}
if (text.charAt(i) == '>' && inParam) {
parameterRanges.add(new TextRange(paramStart, i + 1).shiftRight(shiftOffset + step.getStepName().length() + 1));
inParam = false;
}
i++;
}
}
return parameterRanges;
}
use of org.apache.oro.text.regex.Perl5Matcher in project tdi-studio-se by Talend.
the class AbstractMapComponent method hasOrRenameEntry.
/**
*
* ggu Comment method "hasOrRenameEntry".
*
*/
protected boolean hasOrRenameEntry(IExternalMapEntry entry, String oldName, String newName, boolean renameAction) {
if (entry == null || oldName == null || newName == null && renameAction) {
throw new NullPointerException();
}
if (entry.getExpression() != null) {
Pattern pattern = getRenamePattern(oldName);
if (pattern != null) {
PatternMatcher matcher = new Perl5Matcher();
((Perl5Matcher) matcher).setMultiline(true);
if (renameAction) {
Perl5Substitution substitution = getRenameSubstitution(newName);
String expression = renameDataIntoExpression(pattern, matcher, substitution, entry.getExpression());
entry.setExpression(expression);
} else {
if (hasDataIntoExpression(pattern, matcher, entry.getExpression())) {
return true;
}
}
}
}
return false;
}
use of org.apache.oro.text.regex.Perl5Matcher in project tdi-studio-se by Talend.
the class JSONFileOutputStep1Form method addFieldsListeners.
@Override
protected void addFieldsListeners() {
jsonFilePath.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent event) {
if (jsonFilePath.getResult() == null) {
return;
}
String text = jsonFilePath.getText();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), true);
text = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, text));
}
// getConnection().setJSONFilePath(PathUtils.getPortablePath(JSONXsdFilePath.getText()));
if (JSONFileOutputStep1Form.this.tempPath == null) {
JSONFileOutputStep1Form.this.tempPath = JSONUtil.changeJsonToXml(text);
}
File file = new File(text);
if (file.exists()) {
List<ATreeNode> treeNodes = new ArrayList<ATreeNode>();
valid = treePopulator.populateTree(JSONUtil.changeJsonToXml(text), treeNode);
checkFieldsValue();
if (!valid) {
return;
}
if (treeNodes.size() > 0) {
treeNode = treeNodes.get(0);
}
updateConnection(text);
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
jsonFilePath.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent event) {
String text = jsonFilePath.getText();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), true);
text = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, text));
}
if (getConnection().getJSONFilePath() != null && !getConnection().getJSONFilePath().equals(text)) {
getConnection().getLoop().clear();
getConnection().getRoot().clear();
getConnection().getGroup().clear();
xsdPathChanged = true;
} else {
xsdPathChanged = false;
}
if (Path.fromOSString(jsonFilePath.getText()).toFile().isFile()) {
getConnection().setJSONFilePath(PathUtils.getPortablePath(jsonFilePath.getText()));
} else {
getConnection().setJSONFilePath(jsonFilePath.getText());
}
// updateConnection(text);
StringBuilder fileContent = new StringBuilder();
BufferedReader in = null;
File file = null;
if (tempJSONPath != null && getConnection().getFileContent() != null && getConnection().getFileContent().length > 0 && !isModifing) {
file = new File(tempJSONPath);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e2) {
ExceptionHandler.process(e2);
}
FileOutputStream outStream;
try {
outStream = new FileOutputStream(file);
outStream.write(getConnection().getFileContent());
outStream.close();
} catch (FileNotFoundException e1) {
ExceptionHandler.process(e1);
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
} else {
file = new File(text);
}
String str;
try {
Charset guessCharset = CharsetToolkit.guessEncoding(file, 4096);
in = new BufferedReader(new InputStreamReader(new FileInputStream(file), guessCharset.displayName()));
while ((str = in.readLine()) != null) {
fileContent.append(str + "\n");
// for encoding
if (str.contains("encoding")) {
String regex = "^<\\?JSON\\s*version=\\\"[^\\\"]*\\\"\\s*encoding=\\\"([^\\\"]*)\\\"\\?>$";
Perl5Compiler compiler = new Perl5Compiler();
Perl5Matcher matcher = new Perl5Matcher();
Pattern pattern = null;
try {
pattern = compiler.compile(regex);
if (matcher.contains(str, pattern)) {
MatchResult matchResult = matcher.getMatch();
if (matchResult != null) {
encoding = matchResult.group(1);
}
}
} catch (MalformedPatternException malE) {
ExceptionHandler.process(malE);
}
}
}
fileContentText.setText(new String(fileContent));
} catch (Exception e) {
String msgError = "File" + " \"" + jsonFilePath.getText().replace("\\\\", "\\") + "\"\n";
if (e instanceof FileNotFoundException) {
msgError = msgError + "is not found";
} else if (e instanceof EOFException) {
msgError = msgError + "have an incorrect character EOF";
} else if (e instanceof IOException) {
msgError = msgError + "is locked by another soft";
} else {
msgError = msgError + "doesn't exist";
}
fileContentText.setText(msgError);
if (!isReadOnly()) {
updateStatus(IStatus.ERROR, msgError);
}
} finally {
try {
if (in != null) {
in.close();
}
} catch (Exception exception) {
ExceptionHandler.process(exception);
}
}
if (getConnection().getEncoding() == null || "".equals(getConnection().getEncoding())) {
getConnection().setEncoding(encoding);
if (encoding != null && !"".equals(encoding)) {
encodingCombo.setText(encoding);
} else {
encodingCombo.setText("UTF-8");
}
}
// }
if (file.exists()) {
valid = treePopulator.populateTree(JSONUtil.changeJsonToXml(text), treeNode);
updateConnection(text);
}
checkFieldsValue();
isModifing = true;
}
});
encodingCombo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
getConnection().setEncoding(encodingCombo.getText());
checkFieldsValue();
}
});
commonNodesLimitation.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
String str = commonNodesLimitation.getText();
if ((!str.matches("\\d+")) || (Integer.valueOf(str) < 0)) {
commonNodesLimitation.setText(String.valueOf(treePopulator.getLimit()));
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, commonNodesLimitation.getText()));
} else {
treePopulator.setLimit(Integer.valueOf(str));
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, str));
}
if (JSONFileOutputStep1Form.this.tempPath == null) {
JSONFileOutputStep1Form.this.tempPath = JSONUtil.changeJsonToXml(jsonFilePath.getText());
}
File file = new File(JSONFileOutputStep1Form.this.tempPath);
if (file.exists()) {
valid = treePopulator.populateTree(JSONFileOutputStep1Form.this.tempPath, treeNode);
}
checkFieldsValue();
}
});
commonNodesLimitation.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
commonNodesLimitation.setText(String.valueOf(TreePopulator.getLimit()));
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, commonNodesLimitation.getText()));
}
});
outputFilePath.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
getConnection().setOutputFilePath(PathUtils.getPortablePath(outputFilePath.getText()));
checkFieldsValue();
}
});
}
Aggregations