//Origin origin = Origin.create(filename, new Handler());
LOG.finest("Generating GEG into file: "+generatedGegFile+" while reading from file: "+glinkXMLURL);
//String encoding = "UTF-8";//inStream.getEncoding();
//Charset charset = Charset.forName(encoding);//inStream.getCharset();
SniffedInputStream inStream = new SniffedInputStream(in);
//String encoding = inStream.getEncoding();
Charset charset = inStream.getCharset();
if (inStream.getWarning()!=null)
{
LOG.warning(inStream.getWarning());
}
String charsetName = EnvironmentChecker.getProperty(this, "genj.gedcom.charset", null, "checking for forced charset for read of inputStream");
if (charsetName!=null) {
try {
charset = Charset.forName(charsetName);
//encoding = Gedcom.UTF8;
} catch (Throwable t) {
LOG.log(Level.WARNING, "Can't force charset "+charset, t);
}
}
InputStreamReader inReader = new InputStreamReader(inStream, charset);
generatedGegFile.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(generatedGegFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
OutputStreamWriter out = new OutputStreamWriter(bos, charset);
// 2) find a way to do a pull parser of the xml stream;
// looking for patterns which indicate where to insert the new GLink
// TODO: now read in from the InputStream 'in' and look for the pattern and write to generatedGegFile
GLinkPattern pattern = new GLinkPattern("</g:glinks>");
pattern.setCompareSize(pattern.getToMatch().length());
pattern.setNumberOfMatches(1);
GegPullHandler handler = new GegPullHandler();
handler.setInsertDelta( - (pattern.getToMatch().length()) - 5);
handler.setToName(toName);
handler.setToURL(toURL);
handler.setToRelation(toRelValue);
handler.setFromRelation(fromRelValue);
handler.setOutWriter(out);
handler.setAuthenticated(authenticated);
GLinkPullParser pullParser = new GLinkPullParser();
//pullParser.setOutputStream(bos);
//pullParser.setInputStream(in);
pullParser.setReader(inReader);
pullParser.addPullHander(pattern, handler);
pullParser.parse();
inStream.close();
inReader.close();
in.close();
out.flush();
out.close();
bos.flush();