Próbowałem na wiele sposobów i w końcu zastanawiam się czy to możliwe. Do czego doszedłem to to, że wszystko co mi potrzebne znajduje się w metodzie public InputStream resourceRequested(DocumentInfo docInfo) a dokładnie to
if (((docInfo.getExpectedContentType()==DocumentInfo.TYPE_HTML) && (CACHE_HTML) && ((params==null) || (params.equals(""))) ||
((docInfo.getExpectedContentType()==DocumentInfo.TYPE_IMAGE) && (CACHE_IMAGES)) ||
((docInfo.getExpectedContentType()==DocumentInfo.TYPE_CSS) && (CACHE_CSS))))
{
useCache=true;
InputStream imageIS=getResourcefromCache(url);
if (imageIS!=null) {
return imageIS;
}
}
// Handle the file protocol
if (url.startsWith("file://")) {
return getFileStream(docInfo);
}
Funkcja getResourcefromCache wygląda tak
public static ByteArrayInputStream getResourcefromCache(String url) {
loadCacheIndex();
int index=cacheIndex.indexOf(url);
System.out.println("Index - "+index);
if (index==-1) { //Image not in cache
System.out.println("Resource not found in cache - "+url);
return null;
}
try {
RecordStore rms = RecordStore.openRecordStore("files", true);
System.out.println("otworzyłem recordStore ");
byte[] buf=rms.getRecord(index+1);
rms.closeRecordStore();
System.out.println("Resource found in cache "+url);
if (buf!=null) {
return new ByteArrayInputStream(buf);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
a loadCacheIndex()
private static void loadCacheIndex() {
try {
cacheIndex=new Vector();
RecordStore rms = RecordStore.openRecordStore("files", true);
int num=rms.getNumRecords();
for(int i=0;i<num;i++) {
byte[] buf=rms.getRecord(i+1);
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf));
dis.readUTF();
String url=dis.readUTF();
System.out.println("cacheIndex url:"+url);
cacheIndex.addElement(url);
System.out.println("cacheIndex:"+cacheIndex.elementAt(i).toString());
}
rms.closeRecordStore();
} catch (Exception e) {
e.printStackTrace();
}
}
Kod wstawiony powyżej jest troche pozmieniany przeze mnie m.in. te dwie ostatnie funkcje są wklejone z klasy Storage do HttpRequestHandler. Teraz nie wiem jak powinny być zapisane ścieżki do plików (które znajdują się w rms) w tagu img src czy powinny się zaczynać od file:/// czy http:// czy bez niczego? Żaden sposób nie działa. Pliki graficzne które mają być wczytane są zapisane do rms o nazwie files w kolejnosci dane, nazwa. Po uruchomieniu w konsoli wyświetla mi się:
cacheIndex url:dobrefinanse24.jpg
cacheIndex:dobrefinanse24.jpg
cacheIndex url:dobrapozyczka.jpg
cacheIndex:dobrapozyczka.jpg
Index - -1
Resource not found in cache - http://adserver.o2.pl/mailing.php?cid=53292
Wychodzi na to że ten getResourceFromCache(url) czyta tylko liniki typu <a href=http://adserver.o2.pl/mailing.php?cid=53292><img src=file:///dobrapozyczka.jpg></a>
czyli tylko protokół http:// w ogóle nie bierze pod uwagę linków w img src jakkolwiek bym tego pliku nie zaadresował. W takiej postaci jaką mam teraz, pliki się nie wczytują, w ogóle nie próbują się wczytać.
Trochę brakuje mi wiedzy nie wiem jak to rozwiązać. Proszę o podpowiedź.