URL checker
This commit is contained in:
@@ -6,6 +6,9 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
@@ -27,9 +30,13 @@ import androidx.annotation.NonNull;
|
|||||||
import com.jens.automation2.Action.Action_Enum;
|
import com.jens.automation2.Action.Action_Enum;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class ActivityManageActionTriggerUrl extends Activity
|
public class ActivityManageActionTriggerUrl extends Activity
|
||||||
{
|
{
|
||||||
@@ -39,7 +46,7 @@ public class ActivityManageActionTriggerUrl extends Activity
|
|||||||
CheckBox chkTriggerUrlUseAuthentication;
|
CheckBox chkTriggerUrlUseAuthentication;
|
||||||
RadioButton rbTriggerUrlMethodGet, rbTriggerUrlMethodPost;
|
RadioButton rbTriggerUrlMethodGet, rbTriggerUrlMethodPost;
|
||||||
TableLayout tlTriggerUrlAuthentication;
|
TableLayout tlTriggerUrlAuthentication;
|
||||||
TextView tvHttpParameterExplanation;
|
TextView tvHttpParameterExplanation, tvUrlValidator;
|
||||||
ArrayAdapter<String> httpParametersAdapter;
|
ArrayAdapter<String> httpParametersAdapter;
|
||||||
|
|
||||||
private ArrayList<String> httpParamsList = new ArrayList<>();
|
private ArrayList<String> httpParamsList = new ArrayList<>();
|
||||||
@@ -70,6 +77,7 @@ public class ActivityManageActionTriggerUrl extends Activity
|
|||||||
etParameterValue = (EditText)findViewById(R.id.etParameterValue);
|
etParameterValue = (EditText)findViewById(R.id.etParameterValue);
|
||||||
bAddHttpParam = (Button)findViewById(R.id.bAddHttpParam);
|
bAddHttpParam = (Button)findViewById(R.id.bAddHttpParam);
|
||||||
tvHttpParameterExplanation = (TextView)findViewById(R.id.tvHttpParameterExplanation);
|
tvHttpParameterExplanation = (TextView)findViewById(R.id.tvHttpParameterExplanation);
|
||||||
|
tvUrlValidator = (TextView)findViewById(R.id.tvUrlValidator);
|
||||||
|
|
||||||
etParameterName.setEnabled(false);
|
etParameterName.setEnabled(false);
|
||||||
etParameterValue.setEnabled(false);
|
etParameterValue.setEnabled(false);
|
||||||
@@ -173,6 +181,33 @@ public class ActivityManageActionTriggerUrl extends Activity
|
|||||||
});
|
});
|
||||||
updateListView();
|
updateListView();
|
||||||
|
|
||||||
|
etTriggerUrl.addTextChangedListener(new TextWatcher()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable editable)
|
||||||
|
{
|
||||||
|
if(etTriggerUrl.getText() != null && etTriggerUrl.getText().length() > 0)
|
||||||
|
{
|
||||||
|
if(Miscellaneous.isValidUrl(etTriggerUrl.getText().toString()))
|
||||||
|
tvUrlValidator.setText("");
|
||||||
|
else
|
||||||
|
tvUrlValidator.setText(getResources().getString(R.string.enter_valid_url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||||
{
|
{
|
||||||
// username,password,URL,etc.
|
// username,password,URL,etc.
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
@@ -133,6 +135,9 @@ public class Miscellaneous extends Service
|
|||||||
protected final static String httpMainData = "httpMainData";
|
protected final static String httpMainData = "httpMainData";
|
||||||
protected final static String doNoEncodingString = "NoEncoding";
|
protected final static String doNoEncodingString = "NoEncoding";
|
||||||
protected final static String httpEncoding = "UTF-8";
|
protected final static String httpEncoding = "UTF-8";
|
||||||
|
protected final static String URL_REGEX = "^(https?):\\/\\/([a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*)(:[0-9]{1,5})?([\\/\\?#].*)?$";
|
||||||
|
// protected final static String URL_REGEX = "^(https?|ftp):\\/\\/([a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*)(:[0-9]{1,5})?([\\/\\?#].*)?$";
|
||||||
|
protected final static Pattern URL_PATTERN = Pattern.compile(URL_REGEX, Pattern.CASE_INSENSITIVE);
|
||||||
public static Context startupContext;
|
public static Context startupContext;
|
||||||
|
|
||||||
public static final String lineSeparator = System.getProperty("line.separator");
|
public static final String lineSeparator = System.getProperty("line.separator");
|
||||||
@@ -2428,4 +2433,13 @@ public class Miscellaneous extends Service
|
|||||||
StackTraceElement callingFrame = Thread.currentThread().getStackTrace()[4];
|
StackTraceElement callingFrame = Thread.currentThread().getStackTrace()[4];
|
||||||
return callingFrame.getMethodName();
|
return callingFrame.getMethodName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isValidUrl(String input)
|
||||||
|
{
|
||||||
|
if (input == null || input.length() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Matcher matcher = URL_PATTERN.matcher(input);
|
||||||
|
return matcher.matches(); // Returns true if the entire string matches
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -35,6 +35,12 @@
|
|||||||
|
|
||||||
</EditText>
|
</EditText>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvUrlValidator"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/red" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
@@ -979,4 +979,5 @@
|
|||||||
<string name="examplesWriteSecureSettings">I do not keep a list of possible settings. Please find those settings on your own. See <a href="https://developer.android.com/reference/android/provider/Settings.Secure">here</a> for some (incomplete) examples.</string>
|
<string name="examplesWriteSecureSettings">I do not keep a list of possible settings. Please find those settings on your own. See <a href="https://developer.android.com/reference/android/provider/Settings.Secure">here</a> for some (incomplete) examples.</string>
|
||||||
<string name="httpParametersExplanation">If any parameter name starts with %1$s while method is POST, it will not be transmitted like the other parameters (with key=value), but transferred as main data. If the parameter ends with %2$s, no encoding will be performed.</string>
|
<string name="httpParametersExplanation">If any parameter name starts with %1$s while method is POST, it will not be transmitted like the other parameters (with key=value), but transferred as main data. If the parameter ends with %2$s, no encoding will be performed.</string>
|
||||||
<string name="target">Target</string>
|
<string name="target">Target</string>
|
||||||
|
<string name="enter_valid_url">Enter a valid URL.</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
* Added: Triggers and actions can now be cloned
|
* Added: Triggers and actions can now be cloned
|
||||||
|
* Added: URL checker for triggerUrl action
|
||||||
* Fixed: Crash when starting to add/edit a triggerURL action while the app or the system are set to the German language
|
* Fixed: Crash when starting to add/edit a triggerURL action while the app or the system are set to the German language
|
||||||
Reference in New Issue
Block a user