in src/main/java/com/atlassian/uwc/exporters/MediaWikiExporter.java [310:407]
private void getMediaWikiPages() throws SQLException {
ResultSet pagedata = null;
try {
//get pages
String pageSql = "select " +
COL_ID + ", " +
COL_NAMESPACE +", " +
COL_TITLE + ", " +
COL_LATEST + " " +
"from " + prefix + PAGE_TABLE + " " +
getNamespaceWhereClause() + ";";
pagedata = sql(pageSql);
try {
while (pagedata.next()) {
if (!this.running) return;
// page data
String id = pagedata.getString(COL_ID);
String latest = pagedata.getString(COL_LATEST);
String namespace = pagedata.getString(COL_NAMESPACE);
byte[] bytes2 = pagedata.getBytes(COL_TITLE); //get bytes, 'cause we might have unicode issues
String title = null;
try {
title = getTitle(bytes2);
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//get all the revision ids we need
Vector<String> allRevs = new Vector<String>();
if (gettingHistory()) {
allRevs = getAllRevIds(id); //handle histories
}
else {
allRevs.add(latest); //just the latest revision id
}
//user timestamp data
HashMap<String,String[]>revUdmfMap = null;
String udmfSql = "select " + COL_REV_USER + "," + COL_REV_DATE + "," + COL_REV +
" from " + prefix + REV_TABLE +
" where " + COL_REV_PAGE + "='" + id + "';";
if (gettingUserdate()) {
revUdmfMap = getUserDateMap(udmfSql); //rev_id -> [username,timestamp]
}
int numRevs = 1;
for (String rev : allRevs) {
//get the text id
String textIdSql = "select " + COL_REV_TEXT + " from " + prefix + REV_TABLE +
" where " + COL_REV + "='" + rev + "';";
ResultSet revdata = sql(textIdSql);
String textid = "";
while (revdata.next()) {
textid = revdata.getString(COL_REV_TEXT);
}
//get the text
String textSql = "select " + COL_TEXT + " from " + prefix + TEXT_TABLE +
" where " + COL_TEXT_ID + "='" + textid + "';";
ResultSet textdata = sql(textSql);
String text = "";
while (textdata.next() ) {
if (!this.running) return;
byte[] bytes = textdata.getBytes(COL_TEXT);
try {
text = new String(bytes, encoding);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (gettingUserdate()) { //date for udmf framework: usernames and timestamps
if (!this.running) return;
String userdate = getUserDateData(rev, revUdmfMap);
text = userdate + text;
}
//save the data into a local object
MediaWikiPage mwpage = new MediaWikiPage(title, text, namespace, id, (numRevs++)+"");
//next: 1) handle URL decoding when converting, 2) handle other getMEdiawikiPages method, 3)refactor
//next: refactor you can use the jdb URL to set the UTF-8 encoding?
//output the file to the system
createFileLocally(mwpage);
revdata.close();
textdata.close();
}
}
} catch (SQLException e) {
log.error("Problem while examining data.");
e.printStackTrace();
}
} finally {
pagedata.close();
}
}