Username and Pass code using parallel arrays - java

I am trying to create a pass code and username login for an app that I am designing. At the moment I am required to have four users, and four separate pass codes that are relevant to each user.
this code needs to be run in an android emulator.
Would anyone have a simple array structure that would be easy to follow?

As Hristo said, you should use a HashMap
Map<String, String> myMap = new HashMap<String, String>();
myMap.put("DmcG", "somePassword");
...
String password = myMap.get("DmcG");

Why don't you try using Hashmap? Its structure is < Key, Value >. You can implement it by using the key for username and its value for password. Hope that helps!

Related

HTML Parsing library in java

I am working on Selenium with java client. I am getting the Html as the string using the method driver.getPageSource() .
Can you please suggest to me, do we have any open source which is used to convert the Html to Java Object?
Based on that above question, I am expecting functionality like below:
getTextBoxIds() - It will list of the all the text box Ids as the HashMap() ids as the key, and value is the TextBox value.
getSelectBoxIds()
getDivIds()
Note: As of now I am checking the expected data using the contain(), indexOf(), lastIndexOf() methods.
Regards,
Vasanth D
Don't do that! Selenium does it for you (and much more).
Once you're on the page you wanted to get to, you can get all the data you need:
/** Maps IDs of all textboxes to their value attribute. */
public Map<String,String> getTextBoxIds() {
Map<String,String> textboxIds = new HashMap<>();
// find all textboxes
List<WebElement> textboxes = driver.findElements(By.cssSelector("input[type='text']"));
// map id of each textbox to its value
for (WebElement textbox : textboxes) {
textboxIds.put(textbox.getAttribute("id"), textbox.getAttribute("value"));
}
return textboxIds;
}
and so on and so forth. Look at Selenium's documentation to find out more.
Also, JavaDocs.

How do you send checkbox data in Jsoup

I am trying to post checkbox data with Jsoup and am having a little trouble. I thought that when multiple checkboxes are selected, they are sent as an array to the server but maybe that is not the case?
This is what I thought was correct:
HashMap<String, String> postData = new HashMap<String, String>();
postData.put("checkbox", "[box1,box2,box3]");
Jsoup.connect("somesite").data(postData).post();
This does not seem to work properly. However, if I send only a single checkbox then I get my expected results leading me to believe my understanding of how checkbox form data sends is incorrect.
This works:
postData.put("checkbox", "box2");
Maybe HashMap is the wrong type to use. According to the Jsoup documentation I could just call .data(key, value) multiple times but I was hoping for something a little cleaner than that.
If you have multiple checkboxes, then presumably each checkbox has its own name attribute. You should then call .data(name, value) for each such name.
AFAIK there's no way to "collapse" these calls to data into a single call.
Maybe You can try something like the following ?
HashMap<String,String> paramHM=new HashMap<String,String>();
ArrayList<String> checkboxVal=new ArrayList<Strnig>();
/ .. put request.getParametersValues() in this arraylist
org.jsoup.Connection jsoupConn=Jsoup.connect(web_api).data(paramHM);
// Multiple Call that
for(String item:checkboxVal){
jsoupConn=jsoupConn.data("checkbox",item);
}

Add a dynamic image in a ListView

So, basically i'm working with a ListView, looking like this for the moment :
(source: xooimage.com)
(As a new user I can't post images..)
I add each element of the list like that :
map = new HashMap<String, String>();
map.put("ing_name", "Mozzarella");
listItem.add(map);
map = new HashMap<String, String>();
map.put("ing_name", "Emmental");
listItem.add(map);
I would like to put a different picture for every element, to end up with something like that (I photoshoped it) :
(source: xooimage.com)
I tried some things, but couldn't find out one working.
Does someone know how to do it ?
Thanks. :-)
Try using the Simple adapter class. The below link might be helpful.
Simple adapter example
I hope it helps..

groups accociated with user in ITIM

I am working in JAVA application and authenticating user through ITIM api. How to get groups accociated with user through ITIM api?
The system user will have an attribute of ‘erroles’ through which we can get information of user groups/Roles.
Get DistinguishedName from Person object.
Make PersonMO object having constructor like new PersonMO(platform, subject, person.getDistinguishedName());
Make new AccountManager(platform, subject);
This will give accounts collection accountManager.getAccounts(personMO, LocaleCreator.getLocale());
Get getSystemUserDN(userId);. PersonDao class will help in getting this.
Make new SystemUserMO(m_platform, m_subject, new DistinguishedName(systemUserDN));
Get the roles/Groups from systemUserMO.getData().getRoles()
Cheers
Imran Tariq

Google Calendar(sharing)

I'm working with a Google Apps application. Actually, I want to the access another id without using a password for that. I used OAuth and it's working well. But I am not able to share the particular person's calendar. I tried the following code.
GoogleOAuthParameters oauthParam=new GoogleOAuthParameters();
oauthParam.setOAuthConsumerKey("xxxx.com");
oauthParam.setOAuthConsumerSecret("xxxxxxxxxxxxxxxxxxx");
oauthParam.setScope("http://www.google.com/calendar/feeds/");
URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/owncalendars full?xoauth_requestor_id=user#example.com");
CalendarService service=new CalendarService("calendar");
service.setOAuthCredentials(oauthParam,new OAuthHmacSha1Signer());
AclEntry entry = new AclEntry();
entry.setScope(new AclScope(AclScope.Type.USER,"any.user"));
entry.setRole(CalendarAclRole.READ);
AclEntry insertedEntry = service.insert(feedUrl, entry);
For this code I got the error:
com.google.gdata.util.InvalidEntryException: Bad Request
Calendar entry does not contain title
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:558)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
Inserting ACL entries instead of Calendar entries into the own calendars feed is not a good idea. Also, this API is now deprecated, use http://code.google.com/apis/calendar/v3/getting_started.html for the reference.

Categories