Skip to content
Snippets Groups Projects
Commit 40d03d3a authored by Goik Martin's avatar Goik Martin
Browse files

Providing topic tid's in mapping file

parent 00c36c17
No related branches found
No related tags found
No related merge requests found
......@@ -7,11 +7,14 @@ import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import javax.ws.rs.client.*;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Map;
......@@ -51,13 +54,22 @@ public class Id2Topic {
final SAXBuilder saxBuilder = new SAXBuilder();
if (0 == args.length) {
System.err.println("Usage: id2topic <docbook2topic file>");
System.err.println("Usage: id2topic <docbook2topic basefilename>");
} else {
final File inputFile = new File(args[0]);
final File inputFile = new File(args[0] + ".xml");
try {
final Document document = saxBuilder.build(inputFile);
handleDocbok2idMap(document.getRootElement());
final Format outFormat = Format.getPrettyFormat();
// Serialize to console
final XMLOutputter printer = new XMLOutputter(outFormat);
final String outputFileName = args[0] + ".tid.xml";
final FileWriter outputFile = new FileWriter(outputFileName);
printer.output(document.getRootElement(), outputFile);
} catch (JDOMException e) {
System.err.println("Unable to parse " + config.getString("dobook2topicFileName"));
} catch (IOException e) {
......@@ -68,15 +80,17 @@ public class Id2Topic {
}
static void handleDocbok2idMap(final Element map) {
String mapPrefix = map.getAttributeValue("prefix");
for (final Element entry : map.getChildren("entry")) {
createTopic(entry.getAttributeValue("id"),
final int tid = createTopic(mapPrefix + ":" + entry.getAttributeValue("id"),
entry.getChildText("title"),
entry.getChildText("content"));
entry.setAttribute("tid", "" + tid);
}
}
static void createTopic(String hdmId, String title, String content) {
static int createTopic(String hdmId, String title, String content) {
int tid = db.hdmIdExists(hdmId);
if (tid < 0) { // No related topic
......@@ -96,9 +110,12 @@ public class Id2Topic {
final Map<String, Object> payload = (Map<String, Object>) response.get(KEY_PAYLOAD);
final Map<String, Object> topicData = (Map<String, Object>) payload.get(KEY_TOPICDATA);
db.addHdmId((int) topicData.get("tid"), hdmId);
int newTid = (int) topicData.get("tid");
db.addHdmId(newTid, hdmId);
return newTid;
} else {
System.out.println("hdmId '" + hdmId + "' already present, no action");
System.out.println("hdmId '" + hdmId + "' already present, just adding tid");
return tid;
// Possibly aligning title and content with lecture notes?
// Difficult: Incomplete NodeBB write API --> required MongoDB fiddling
......
......@@ -13,10 +13,9 @@
<xsl:include href="common.xsl"/>
<xsl:output indent="yes" method="xml"/>
<xsl:variable name="hdmTopicIdPrefix" select="'goiklecture'"/>
<xsl:template match="/">
<map>
<map prefix="goiklecture">
<xsl:apply-templates select=".//d:qandaset"/>
</map>
</xsl:template>
......@@ -25,8 +24,6 @@
<entry >
<xsl:attribute name="id">
<xsl:value-of select="$hdmTopicIdPrefix"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="@xml:id"/>
</xsl:attribute>
......
......@@ -79,7 +79,7 @@ SAXONCMD=java -cp "${DBOOK_XSL}/tools/lib/saxon9he.jar:/usr/share/java/xercesImp
-xsl:${DBOOK_XSL_PREPROCESS}/Xsl/docbook2docbook.xsl > ${*}.xml
${SAXONCMD} -s:$*.xml \
-xsl:${DBOOK_XSL_PREPROCESS}/Xsl/docbook2topics.xsl ${dbookXslWebhelpParam} > ${*}.topics.xml
${CMDID2TOPIC} ${*}.topics.xml
${CMDID2TOPIC} ${*}.topics # Only basename without .xml extension
${SAXONCMD} -s:$*.xml \
-xsl:${DBOOK_XSL_PREPROCESS}/Xsl/docbook2html.xsl > ${*}.html.xml
${SAXONCMD} -s:$*.xml \
......@@ -172,7 +172,7 @@ clean:
rm -rf ${BUILDROOT}
diff:
diff -r --brief targetReference/ target|grep -v pdf
diff -r --brief targetReference/ target|grep -v pdf || exit 0
#end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment