Reader text = new InputStreamReader(urlToStreamTransformer.transform(url), "iso-8859-1");
//Reader text = new InputStreamReader(getClass().getResourceAsStream("/wpinfos/boerse/" + information.getIsin() + ".html"), "iso-8859-1");
BoostedReader reader;
if ( text == null)
return false;
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "<h1>", true);
reader = new BoostedReader(reader, BoostedReader.Type.READ_UP_TO_END, "</h1>", true);
reader.readUpToEnd();
String assetname = reader.getSubtextWithoutEnding().toString().trim();
if (assetname.equals(""))
return false;
else
{
information.setAssetname(assetname);
currentMarketPrice.setAssetname(assetname);
}
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "<h4>", false);
reader = new BoostedReader(reader, BoostedReader.Type.READ_UP_TO_END, "</h4>", true);
reader.readUpToEnd();
String assetinfo = reader.getSubtextWithoutEnding().toString().trim();
String type = null;
String FONDS = "Fonds";
String SHARE = "Aktie";
String ANLEIHE = "Anleihe";
String ANLAGEPRODUKT = "Anlageprodukt";
String ETF = "ETF";
if (assetinfo.equals(""))
;//skip
else
{
//assetinfo examples
//Fonds, ISIN DE0008471400, WKN 847140, DZ7U
//Aktie, ISIN DE0007100000, WKN 710000, DAI
String[] parts = assetinfo.split(",");
information.setType(parts[0]);
if (FONDS.equals(parts[0]))
type = FONDS;
else if (SHARE.equals(parts[0]))
type = SHARE;
else if (ANLEIHE.equals(parts[0]))
type = ANLEIHE;
else if (ANLAGEPRODUKT.equals(parts[0]))
type = ANLAGEPRODUKT;
else if (ETF.equals(parts[0]))
type = ETF;
String isin = parts[1].trim();
String ISIN = "ISIN";
if (isin.startsWith(ISIN))
{
isin = isin.substring(ISIN.length() + 1);
information.setIsin(isin);
}
}
try
{
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, ">Letzter Preis", false);//Es kann manchmal ein * danach kommen, manchmal nicht
reader.readUpToEnd();
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "<b>", false);
reader.readUpToEnd();
reader = new BoostedReader(reader, BoostedReader.Type.READ_UP_TO_END, "</b>", true);
/*
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "Letzter Preis</td>", false);
reader.readUpToEnd();
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, ">", false);
reader = new BoostedReader(reader, BoostedReader.Type.READ_UP_TO_END, "</td>", true);
*/
reader.readUpToEnd();
String price = reader.getSubtextWithoutEnding().toString().trim();
price = price.replace(".", "");
price = price.replace(',', '.');
String currency = "EUR"; //is this always so?
BigDecimal resultPrice = new BigDecimal(price);
resultPrice = resultPrice.multiply(information.getPriceNotation());
BigDecimal marketPriceValue = exchangeRateManager.change(resultPrice, currency);
marketPrice.setCurrency( exchangeRateManager.getTargetCurrency());
currentMarketPrice.setCurrency( exchangeRateManager.getTargetCurrency());
marketPrice.setPrice(marketPriceValue);
currentMarketPrice.setPrice(marketPriceValue);
GregorianCalendar date = new GregorianCalendar();//use date from html
marketPrice.setValueDate( date);
currentMarketPrice.setValueDate(date);
}
catch (Exception ex)
{
getLog().debug("could not get price of " + information.getIsin() + ": " + ex);
}
//writeErrorMessage( getClass().getName(), "No curreny and price", "not yet implemented");
String info;
if (type == SHARE)
{
try
{
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "<span>Land</span>", false);
reader.readUpToEnd();
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "<span>", false);
reader = new BoostedReader(reader, BoostedReader.Type.READ_UP_TO_END, "</span>", true);
reader.readUpToEnd();
info = reader.getSubtextWithoutEnding().toString();
if ( ! info.equals(""))
information.setRegion(info);
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "<span>Sektor</span>", false);
reader.readUpToEnd();
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "<span>", false);
reader = new BoostedReader(reader, BoostedReader.Type.READ_UP_TO_END, "</span>", true);
reader.readUpToEnd();
info = reader.getSubtextWithoutEnding().toString();
if ( ! info.equals(""))
information.setSector(info);
}
catch (Exception ex)
{
//just go on
}
}
else if ( type == FONDS)
{
try
{
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "Fondstyp</td>", false);
reader.readUpToEnd();
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, ">", false);
reader = new BoostedReader(reader, BoostedReader.Type.READ_UP_TO_END, "</td>", true);
reader.readUpToEnd();
info = reader.getSubtextWithoutEnding().toString().trim();
if (info.contains(" "))
{
info = info.split(" ")[0];
if ( ! info.equals(""))
information.setSector(info);
}
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "Region/Land</td>", false);
reader.readUpToEnd();
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, ">", false);
reader = new BoostedReader(reader, BoostedReader.Type.READ_UP_TO_END, "</td>", true);
reader.readUpToEnd();
info = reader.getSubtextWithoutEnding().toString().trim();
if ( ! (info.equals("") || info.equals("-")))
information.setSector(info);
}
catch (IllegalStateException ex)
{
getLog().debug("exception in Fonds: " + ex);
//sometimes there is no additional information, so it's ok, try to get the info otherwise
}
}
else if ( type == ANLEIHE)
{
try
{
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, "Typ</td>", false);
reader.readUpToEnd();
reader = new BoostedReader(text, BoostedReader.Type.READ_UP_TO_END, ">", false);
reader = new BoostedReader(reader, BoostedReader.Type.READ_UP_TO_END, "</td>", true);
reader.readUpToEnd();
info = reader.getSubtextWithoutEnding().toString().trim();
if ( ! (info.equals("") || info.equals("-")))
information.setSector(info);
}
catch (IllegalStateException ex)
{
getLog().debug("exception in Anleihe: " + ex);
//sometimes there is no additional information, so it's ok, try to get the info otherwise
}
}
else
{
getLog().debug("no details for type: " + type);
}
getLog().debug(getClass().getSimpleName()+ ".updateInformation " + pageID +": " + information.getIsin() + ": true");
reader.close();
return true;
}
catch (Exception ex)
{
lastException = ex;