I have a class called ُCreatorUrl in flutter. In this class and other classes, strings including the names of database tables are specified.
How to protect data and strings in the flutter?
Is this a common way of programming?
Please help me.thank's
class CreatorUrl {
static Future<String> createLinkRequest(Map body,{int page:20}) async {
String blankUrl = 'http:mysite/myApi/api.php?x={"ApiKey":"SAZUChQJh8D7WRyJTc4BERedWd"';
switch (body['MOD']) {
case 'select':
blankUrl=blankUrl+',"MOD":"select","table":"${body['table']}","what":"*","sql":"${body['sql']}","limit":"0,${page==null?200:page}"}';
break;
case 'insert':
blankUrl=blankUrl+',"MOD":"insert","table":"${body['table']}","insert":"${body['insert']}"}';
break;
case 'delete':
break;
case 'update':
blankUrl=blankUrl+',"MOD":"update","table":"${body['table']}","update":"${body['update']}","sql":"${body['sql']}"}';
break;
case 'count':
blankUrl=blankUrl+',"MOD":"count","table":"${body['table']}","sql":"${body['sql']}"}';
break;
case 'sms':
blankUrl=blankUrl+',"MOD":"sms","mob":"${body['mob']}","text":"${body['text']}"}';
print("Im here s");
break;
}
return blankUrl;
}
}
This may be useful about your problem
Also read this document
Related
I am developing using aureliajs. By now I am working on a custom attribute which has marked to have dynamic options. For example consider following code:
import {dynamicOptions, inject} from 'aurelia-framework';
#dynamicOptions
#inject(Element)
export class SquareCustomAttribute {
constructor(element){
this.element = element;
}
propertyChanged(name, newValue, oldValue){
switch(name){
case 'fill':
this.element.style.backgroundColor = newValue;
break;
case 'size':
this.element.style.width = this.element.style.height = `${newValue}px`;
break;
default:
this.element.style[name] = newValue;
break;
}
}
}
now for example consider that I want to give the property fill, defaultBindingMode of twoWay, so I will try to add the #bindable property in class. So the code will change to this:
import {dynamicOptions, inject} from 'aurelia-framework';
#dynamicOptions
#inject(Element)
export class SquareCustomAttribute {
#bindable fill;
constructor(element){
this.element = element;
}
propertyChanged(name, newValue, oldValue){
switch(name){
case 'fill':
this.element.style.backgroundColor = newValue;
break;
case 'size':
this.element.style.width = this.element.style.height = `${newValue}px`;
break;
default:
this.element.style[name] = newValue;
break;
}
}
}
And binding stops working.
So, the first question is how to set defaultBindingMode for dynamicOptions?
And another little question. As aurelia.io says, Binding to a dynamic options attribute works exactly the same as binding to an options attribute in the DOM.. According to this sentence, I expect to bind dynamic options dash seperated and retrieve the in camel case on optionsChanged method. But dash seperated options bound from view, receives dash separated and camels, camels. Is this correct according to referenced sentence from aurelia.io?
Thanks to #bigopon, this issue is being followed up in this issue and I think any additional comment on that will be beneficial before making changes on aurelia-framework.
How can I get this type of usage out of my C++ compiler? Consider a very simple hierarchical state-machine, where you can specify the states are unique enum types (enum class). Here's some use-case pseudo code:
enum class lev0
{
start,
end
};
enum class lev1
{
start,
end
};
enum class lev2
{
start,
end
};
HSMSimple<lev0, lev1, lev2> hsm_lev0;
const HSMSimple<lev1, lev2>& hsm_lev1 = hsm_lev0.nextLevel;
const HSMSimple<lev2>& hsm_lev2 = hsm_lev1.nextLevel;
switch (hsm_lev0)
{
case lev0::start:
switch (hsm_lev1)
{
case lev1::start:
switch (hsm_lev2)
{
case lev2::start:
break;
case lev2::end:
break;
}
break;
case lev1::end:
break;
}
break;
case lev0::end:
break;
}
...
Ideas? I've tried a class as such:
template<typename arg1, typename ... TArgs>
class HSMSimple
{
public:
operator const arg1&() const { return m_lev1; }
operator arg1() { return m_lev1; }
const HSMSimple<TArgs>& nextLev() const { return m_nextLevel; }
HSMSimple<TArgs> nextLev() { return m_nextLevel; }
protected:
arg1 m_lev1;
HSMSimple<TArgs> m_nextLevel;
};
But the compiler says an instantiation must pack the args at that last line in the class. When I try writing 'HSMSimple< TArgs...> m_nextLevel;' just more chaos ensues. I feel like more trickery is needed, but can't figure out what.
I'm trying to make multiple Gtk::ToggleButton's to act as Gtk::RadioButton's. When one of the buttons is pressed that other switch off.
It would be as simple as creating a switch statement if Gtk::ToggleButton didn't handle switching (pressed or not pressed) on its own.
So, I'm planning to handle it's switching as regular button with calling signal_clicked().connect() which calls for function set_active(true/false) which makes button look pressed or not pressed.
Here is example of what I'm trying to do:
Event calls when button is clicked:
//enum {infoState, artState, editState, userState, exitState}; is initialised in header
artButt.signal_clicked().connect(sigc::bind<short int>(sigc::mem_fun(*this, &fooclass::toggleButton), artButt));
editButt.signal_clicked().connect(sigc::bind<short int>(sigc::mem_fun(*this, &fooclass::toggleButton), editButt));
Toggling button:
void fooClass::toggleButton()
{
//oldState and enum {infoState, artState, editState, userState, exitState}; are initialised in header
if(oldState != newState)
{
//disable old togglebutton
switch (oldState)
{
case infoState:
infoButt.set_active(false);
break;
case artState:
artButt.set_active(false);
break;
case editState:
editButt.set_active(false);
break;
case userState:
userButt.set_active(false);
break;
}
//enable new one
switch (newState)
{
case infoState:
userButt.set_active(false);
break;
case artState:
artButt.set_active(true);
break;
case editState:
editButt.set_active(true);
break;
case userState:
userButt.set_active(true);
break;
}
oldState = newState;
}
}
Just useGtk::RadioButton directly. With the draw-indicator property you can make them look like regular toggle buttons.
Ok, so here is my workaround. There is probably better way, so please if you know any post it here:
Firstly use Gtk::Button instead of Gtk::ToggleButton .
Secondly instead of set_active() use set_state_flags(). Gtk::STATE_FLAG_CHECKED when you want it to be enabled and GTK::STATE_FLAGS_NORMAL when you want it to be disabled.
So, this is how code should look like:
void Window::changeState()
{
if(oldState != state)
{
//delete old state
switch (oldState)
{
case infoState:
infoButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
case artState:
artButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
case editState:
editButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
case userState:
userButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
}
//move to new state
switch (state)
{
case infoState:
infoButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case artState:
artButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case editState:
head.editButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case userState:
userButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case exitState:
close();
break;
}
show_all_children();
oldState = state;
}
}
I've created a QWidget, which contains three QLineEdits. Then I added a overwrote the keyPressEvent so that this lineEdit_3 reacts on key press. Working good.
void MySuperWidget::keyPressEvent(QKeyEvent* keyEv)
{
switch (keyEv->key()) {
case Qt::Key_Up:
//.. stuff
break;
case Qt::Key_Down: {
//.. stuff
}
break;
default:
break;
}
}
BUT the first and second QLineEdit also react on keypress :(
I need somethng like this:
if (sender() != ui->lineEdit_3 ) {
keyEv->ignore();
}
In my application during releases, I'm forced to change id to xpath or class name or tag. So I can't use any of the element selection methods like driver.findElement(By.id()).
In the next build I might have to use driver.findElement(By.xpath()) OR driver.findElement(By.name()) for the same element location. This means I will have to visit each and every class file I have written and modify By.id() to the respective selector.
Is there any way to avoid this by parametrising or some other way to resolve this issue?
Thanks in advance.
Had similar issue so came up with this generic method
public WebElement getElement(Identifier identifier, String expression) {
By byElement = null;
switch (identifier) {
case xpath: {
byElement = By.xpath(expression);
break;
}
case id: {
byElement = By.id(expression);
break;
}
case name: {
byElement = By.name(expression);
break;
}
case classname: {
byElement = By.className(expression);
break;
}
case linktext: {
byElement = By.linkText(expression);
break;
}
case paritallinktext: {
byElement = By.partialLinkText(expression);
break;
}
case tagname: {
byElement = By.tagName(expression);
break;
}
}
WebElement element = driver.findElement(byElement);
return element;
}
public static enum Identifier {
xpath, id, name, classname, paritallinktext, linktext, tagname
};
You can also use properties file to store values. Like
# login
login.username.identifier=xpath
login.username.expression=//input[#id='userNameText']
and in Java you can write
SeleniumUtil.getElement(prop.getProperty("login.username.identifier"), prop.getProperty("login.username.expression")).click();
So you will not need to change any Java code
You can also make use of key=value in your locators as a good practice which was seen in Selenium 1.0 and accordingly the selector will be selected.
So you can have a common getByLocator method that returns you with the By class object, example code
public By getByLocator(String locator) {
By by = null;
if (locator.startsWith("class=")) {
by = By.className(locator.replace("class=", "").trim());
} else if (locator.startsWith("css=")) {
by = By.cssSelector(locator.replace("css=","").trim());
} else if (locator.startsWith("link=")) {
by = By.linkText(locator.replace("link=", "").trim());
} else if (locator.startsWith("//") or locator.startsWith("/")) {
by = By.xpath(locator);
} else if (locator.startsWith("id=")) {
by = By.id(locator.replace("id=", ""));
} else {
by = By.name(locator.replace("name=", ""));
}
return by;
}
Here I made use of link=, css=, id= as some of factors to identify the locator type and accordingly I got the By locator object.
The usage of this would be something like below
List<WebElement> element = driver.findElements(getByLocator("css= input[type=input]"));
You have to work on your framework. Make it more generic. My code handles the problem. I have used key and value concept. In my .properties file, I have defind the object like
Test_login_user=id||username
Test_login_pass=className||passwd
after that my code get the value and spits it from ||. Here I have mention the type of locator if its BY id then id||username etc.
public By extractWebElement(String keyobject){
if(keyobject.startsWith("name_")){
currentWebElement = By.name(actualLocator);
}else if(keyobject.startsWith("xpath_")){
currentWebElement =By.xpath(actualLocator);
}else if(keyobject.startsWith("linkText_")){
currentWebElement =By.linkText(actualLocator);
}else if(keyobject.startsWith("id_")){
currentWebElement =By.id(actualLocator);
}else if(keyobject.startsWith("cssSelector_")){
currentWebElement =By.cssSelector(actualLocator);
}else if(keyobject.startsWith("tagName_")){
currentWebElement =By.tagName(actualLocator);
}
return currentWebElement;
}
public String extractActualLocator(String locatorInSheet ){
int underScoreIndex = locatorInSheet.indexOf('_');
return locatorInSheet.substring(underScoreIndex+1);
}
Now actual locator is in the "currentWebElement", we can use this in our methods. See how my keywords are written
public String enterTextt(By object,String data){
APP_LOGS.debug("Writing in text box");
try{
***driver.findElement(object).sendKeys(data);***
}catch(Exception e){
return Constants.KEYWORD_FAIL+" Unable to write "+e.getMessage();
}
return Constants.KEYWORD_PASS;
}