jericho Html parser error in jsp page - java

I have write code as
String sourceUrlString="http://some url";
Source source=new Source(new URL(sourceUrlString));
Element INFORM = source.getElementById("main").getAllElementsByClass("game").get(i-1);
String INFORM = INFORM.replaceAll("\\s",""); //shows error here
sendResponse(resp,+INFORM);
Now i want the text fetch from Element INFORM is Neglect white space how can i do so? above mentioned String INFORM Show error Duplicate local variable INFORM);
e.g
text fetch by Element INFORM is "my name is satish"
but it must send response as
"mynameissatish"

You have the name INFORM used twice - and thats not possible!
String sourceUrlString = "http://some url";
Source source = new Source(new URL(sourceUrlString));
Element INFORM = source.getElementById("main").getAllElementsByClass("game").get(i-1);
String response = INFORM.replaceAll("\\s",""); // ! Use another name here !
sendResponse(resp, respone); // or use '+' - not shure if 1 or 2 args

Related

How to parse String to MbMessageAssembly? In Java Compute node IIB

I am quite new to this, and I am struggling with one issue.
In Java Compute Node, through IIB, I am checking if one field has one or more values, and for each additional value I am creating a new duplicate message, except for value, these additional values are overriding.
This is working fine as a expect, see example:
Input :...
</leg_flight_no><lineNumber>2</lineNumber><shipper_name>BMW AG</shipper_name> <shipper_reference_hu>1111111;22222222;333333333</shipper_reference_hu></root>
Modified message 1:...
</leg_flight_no><lineNumber>2</lineNumber><shipper_name>BMW AG</shipper_name> <shipper_reference_hu>1111111</shipper_reference_hu></root>
Modified message 2:..
</leg_flight_no><lineNumber>2</lineNumber><shipper_name>BMW AG</shipper_name> <shipper_reference_hu>22222222</shipper_reference_hu></root>
Modified message3 :...
</leg_flight_no><lineNumber>2</lineNumber><shipper_name>BMW AG</shipper_name> <shipper_reference_hu>333333333</shipper_reference_hu></root>
But I am struggling to propagate this message out from the Java Compute node. I understand that I cant propagate messages of type String, so I am trying to parse this as a MbMessageAssemble outAssemble. This is my code:
String newMessage = inData.replace(wholeValues, outData); // replace one value with another
MbMessage outMessage = new MbMessage();
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly, outMessage);
copyMessageHeaders(inMessage, outMessage);
MbElement outRoot = outMessage.getRootElement();
MbElement outParser = outRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
MbElement outBodyEl2 = outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", newMessage.getBytes());
alt.propagate(outAssembly);
But this is propagate an empty message, so the newMessage is not parsed to outAssembly. Can anybody with this experience help me with this?
I figured it out. For future, here is your answer
String newMessage = "this is some test";
MbMessage outMessage=new MbMessage();
outMessage.getRootElement().createElementAsLastChild(MbBLOB.PARSER_NAME).createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", newMessage.getBytes());
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly, outMessage);
out.propagate(outAssembly);

How to parse JSON Array to Webview Android

I have this JSON data
"posts":[{
"date":"2016-02-10 10:28:42",
"categories":[{}],
"tags":[],
"author":{"name":"admin"},
"custom_fields":{
"ref_number":["ITB NUMBER: ITB\/002\/2016"],
"deadline":["26 February, 2016"],
"entity":["Refugees (xxx)"]
}
I want to pass entitywith the code below in my JSONParser.java
Post post = new Post();
// Configure the Post object
post.setTitle(postObject.optString("title"));
post.setDate(postObject.optString("date", "N/A"));
post.setContent(postObject.optString("content", "N/A"));
post.setCfs(postObject.getJSONObject("custom_fields").optJSONArray("entity").getString(0));
to my Webview. using the code below in my PostFragment.java
id = args.getInt("id");
//Title and date pass successfully
title = args.getString("title");
String date = args.getString("date");
//but the entity displays null
entity = args.getString("entity");
//author is passed and it displays well/successfully
String author = args.getString("author");
// Construct HTML content
// html for entity to webview
html += "<h2>" + entity + "</h2>";
html += "<h3>" + title + "</h3>";
// The actual content
html += content;
am able to pass and display title and content, however when i try entity it shows null in webview
Where am i going wrong
Try:
entity = args.getString("custom_fields.entity");
Hope it helps!
Your question is not clear , as per my understanding you need Refugee element
The JSON you have posted is not valid.
As per my understanding elements of entity is also an JSONObject , so the parser should be like this
.optJSONArray("entity").getJSONObject(i); // i is poistion
This will give you ith element of entity array

Selenium Web Driver - Error communicating with remote browser after searching

thanks for your time.
I have the following code (Using this to test the filter/search on my web app):
(Don't worry so much about the words I'm searching etc, I just want to get the browser working after pressing search):
// Store my words
String sWordOne = "HTML1";
String sWordTwo = "WONT2";
String sWordThree = "WONTWORK3";
// Add These Entries
Business_Surveys_Survey.Surveys_AddIndividualSql(sWordOne, "I have added this to check spelling", "Questions Tab Spelling");
Business_Surveys_Survey.Surveys_AddIndividualSql(sWordTwo, "I have added this to check spelling", "Questions Tab Spelling");
Business_Surveys_Survey.Surveys_AddIndividualSql(sWordThree, "I have added this to check spelling", "Questions Tab Spelling");
navigateToSurveysManageSurveys();
WebElement sSearchBtn = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_btnSearch"));
WebElement sSearchBoxText = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_txtSearchBox"));
String sExpectedMessage = "Displaying 3 Records";
String sDisplayingXRecords = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_upSurveysList")).getText().trim();
String sSurveysOne = sDisplayingXRecords.substring(0, 20);
assertThat(sSurveysOne, containsString(sExpectedMessage));
sSearchBoxText.sendKeys("<HTML>");
sSearchBtn.click();
sSearchBoxText.clear();
String sDisplayingXRecordsOne = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_upSurveysList")).getText().trim();
String sDisplayingSurveys = sDisplayingXRecordsOne.substring(0, 20);
String sExpectedMessageTwo = "Displaying 1 Record";
assertThat(sDisplayingSurveys, containsString(sExpectedMessageTwo));
Business_Surveys_Survey.Surveys_NukeSurveyListbox();
Everytime it executes the following:
sSearchBoxText.sendKeys("<HTML>");
sSearchBtn.click();
it breaks and I can't talk to the browser via webdriver:
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
I thought maybe its because im adding in some HTML tags, but even when I search for a basic word, same result. I've tried just sending the return key in the box and pressing the search button on the page.
Any idea's? I have a suspicion its the following,
navigateToSurveysManageSurveys();
WebElement sSearchBtn = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_btnSearch"));
WebElement sSearchBoxText = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_txtSearchBox"));
If it is can you please explain what I have done wrong and how I should be handling this better?
Thanks for your time

Is it possible to display text on a rich text item in a DocumentContext?

I have a form that runs a java agent on the WebQueryOpen event. This agent pulls data from a DB2 database and then puts them into the computed text fields I have placed on the form and are displayed whenever I open the form in the browser. This is working for me. However, when I try to use RichTextFields I get a ClassCastException error. No document is actually saved, I just open the form in the browser using this domino URL - https://company.com/database.nsf/sampleform?OpenForm
Sample code of simple text field - Displayed with w/o problems
Document sampledoc = agentContext.getDocumentContext();
String samplestr = "sample data from db2";
sampledoc.replaceItemValue("sampletextfield", samplestr);
When I tried using rich text field
Document sampledoc = agentContext.getDocumentContext();
String samplestr = "sample data from db2";
RichTextItem rtsample = (RichTextItem)sampledoc.getFirstItem('samplerichtextfield');
rtsample.appendText(samplestr); // ClassCastException error
Basically, I wanted to use rich text field so that it could accommodate more characters in case I pull a very long string data.
Screenshot of the field (As you can see it's a RichText)
The problem is that you're trying to access a regular Item as a RichTextItem.
The RichTextItem are special fields that are created with its own method just like this:
RichTextItem rtsample = (RichTextItem)sampledoc.createRichTextItem('samplerichtextfield');
It's different to the regular Items that can be created with a simple sampledoc.replaceItemValue(etc).
So, if you want to know if a item is RichTextItem and if it does not exist, create it, you can do this:
RichTextItem rti = null;
Item item = doc.getFirstItem("somefield");
if (item != null) {
if (item instanceof RichTextItem) {
//Yay!
rti = (RichTextItem) item;
} else {
//:-(
}
} else {
rti = doc.createRichTextItem("somefield");
//etc.
}

url harvester string manipulation

I'm doing a recursive url harvest.. when I find an link in the source that doesn't start with "http" then I append it to the current url. Problem is when I run into a dynamic site the link without an http is usually a new parameter for the current url. For example if the current url is something like http://www.somewebapp.com/default.aspx?pageid=4088 and in the source for that page there is a link which is default.aspx?pageid=2111. In this case I need do some string manipulation; this is where I need help.
pseudocode:
if part of the link found is a contains a substring of the current url
save the substring
save the unique part of the link found
replace whatever is after the substring in the current url with the unique saved part
What would this look like in java? Any ideas for doing this differently? Thanks.
As per comment, here's what I've tried:
if (!matched.startsWith("http")) {
String[] splitted = url.toString().split("/");
java.lang.String endOfURL = splitted[splitted.length-1];
boolean b = false;
while (!b && endOfURL.length() > 5) { // f.bar shortest val
endOfURL = endOfURL.substring(0, endOfURL.length()-2);
if (matched.contains(endOfURL)) {
matched = matched.substring(endOfURL.length()-1);
matched = url.toString().substring(url.toString().length() - matched.length()) + matched;
b = true;
}
}
it's not working well..
I think you are doing this the wrong way. Java has two classes URL and URI which are capable of parsing URL/URL strings much more accurately than a "string bashing" solution. For example the URL constructor URL(URL, String) will create a new URL object in the context of an existing one, without you needing to worry whether the String is an absolute URL or a relative one. You would use it something like this:
URL currentPageUrl = ...
String linkUrlString = ...
// (Exception handling not included ...)
URL linkUrl = new URL(currentPageUrl, linkUrlString);

Categories

Resources