In the server impl file:
@Override
*public* String getMapURL(String theURL) {
URL url = *null*;
String s = *null*;
String retstr = "";
*try* {
url = *new* URL(theURL);
BufferedReader reader = *new*
BufferedReader(*new*InputStreamReader(url.openStream()));
*while* ((s = reader.readLine()) != *null*) {
retstr += s + "\n";
}
*return* retstr;
} *catch* (MalformedURLException e) {
e.printStackTrace();
} *catch* (IOException e) {
e.printStackTrace();
}
*return* retstr;
}
}
Call from the client with the name of the URL that you want.
On the client side, you can parse with stuff similar to this:
*protected* MapWidget createMapWidget(String mapString, *int* width,
*int*height, TextArea ta) {
Document doc = XMLParser.*parse*(mapString);
Element root = doc.getDocumentElement();
NodeList tempNodes = root.getElementsByTagName("temp");
String s = *new* String("");
AreaWidget[] areas = *new* AreaWidget[tempNodes.getLength()];
*for* (*int* i=0; i<tempNodes.getLength(); i++) {
Element tempElement = (Element) tempNodes.item(i);
String theTemp = getElementText(tempElement, "number");
String theDescription = getElementText(tempElement, "description");
String theXStart = getElementText(tempElement, "xstart");
theXStart = String.*valueOf*(Math.*round*(Float.*parseFloat*(theXStart) *
width));
String theXStop = getElementText(tempElement, "xstop");
theXStop = String.*valueOf*(Math.*round*(Float.*parseFloat*(theXStop) *
width));
String theYStart = getElementText(tempElement, "ystart");
theYStart = String.*valueOf*(Math.*round*(Float.*parseFloat*(theYStart) *
height));
String theYStop = getElementText(tempElement, "ystop");
theYStop = String.*valueOf*(Math.*round*(Float.*parseFloat*(theYStop) *
height));
String theArea = theXStart + "," + theYStart + "," + theXStop + "," +
theYStop;
s += theTemp + "\n";
s += theDescription + "\n";
s += theXStart += "\n";
s += theXStop += "\n";
s += theYStart += "\n";
s += theYStop += "\n";
s += theArea += "\n";
areas[i] = *new* AreaWidget("rect", theArea, theTemp,
*new*SolarSystemCommand(theTemp));
}
ta.setText(s);
MapWidget map = *new* MapWidget(areas);
*return* map;
}
*private* String getElementText( Element item, String value) {
String result = "";
NodeList itemList = item.getElementsByTagName(value);
*if* (itemList.getLength() > 0 && itemList.item(0).hasChildNodes()) {
result = itemList.item(0).getFirstChild().getNodeValue();
}
*return* result;
}
In this example, I am parsing an XML file that describes an image map to be
applied to a jpg which I retrieve.
The XML contains entries like this:
<temperatures>
<temp>
<number>044</number>
<description>Test *Temp* Sensor OTA 4,3: TTS(4,3)</description>
<xstart>0.508</xstart>
<xstop>0.566</xstop>
<ystart>0.477</ystart>
<ystop>0.532</ystop>
</temp>
<temp>
<number>081</number>
<description>Test *Temp* Sensor OTA 7,5: TTS(7,5)</description>
<xstart>0.731</xstart>
<xstop>0.795</xstop>
<ystart>0.332</ystart>
<ystop>0.387</ystop>
</temp>
<temp>
<number>066</number>
<description>Test *Temp* Sensor OTA 3,1: TTS(3,1)</description>
<xstart>0.434</xstart>
<xstop>0.496</xstop>
<ystart>0.622</ystart>
<ystop>0.685</ystop>
</temp>
.....
</temperatures>
The rectangles are percentages offsets from the top left corner of the image
(values range between 0 and 1)... by multiplying by the size of the image
(width and height) you can create an image map.
On Wed, Feb 10, 2010 at 9:59 AM, Russ <[email protected]> wrote:
> Thanks, but I'm really just looking for a basic tutorial or example on
> how to grab remote XML data using GWT's
> com.google.gwt.xml.client.XMLParser
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.