https://freemind.sourceforge.io/wiki/index.php?title=User:Jiangxin/Patch_load_mm_file_with_mmx_file&feed=atom&action=history
User:Jiangxin/Patch load mm file with mmx file - Revision history
2024-03-29T02:34:52Z
Revision history for this page on the wiki
MediaWiki 1.38.7
https://freemind.sourceforge.io/wiki/index.php?title=User:Jiangxin/Patch_load_mm_file_with_mmx_file&diff=10755&oldid=prev
Jiangxin: remove spam.
2009-02-14T06:02:47Z
<p>remove spam.</p>
<a href="https://freemind.sourceforge.io/wiki/index.php?title=User:Jiangxin/Patch_load_mm_file_with_mmx_file&diff=10755&oldid=7657">Show changes</a>
Jiangxin
https://freemind.sourceforge.io/wiki/index.php?title=User:Jiangxin/Patch_load_mm_file_with_mmx_file&diff=7657&oldid=prev
Monluna: wow account,wow accounts,buy wow account,world warcraft account
2008-12-04T05:48:03Z
<p>wow account,wow accounts,buy wow account,world warcraft account</p>
<a href="https://freemind.sourceforge.io/wiki/index.php?title=User:Jiangxin/Patch_load_mm_file_with_mmx_file&diff=7657&oldid=7241">Show changes</a>
Monluna
https://freemind.sourceforge.io/wiki/index.php?title=User:Jiangxin/Patch_load_mm_file_with_mmx_file&diff=7241&oldid=prev
Jiangxin: add signature and time
2007-03-15T09:26:56Z
<p>add signature and time</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 09:26, 15 March 2007</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l13">Line 13:</td>
<td colspan="2" class="diff-lineno">Line 13:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>When I write the patch at 2005, I even don't know the basic knowledge of optimization of a XSLT. </div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>When I write the patch at 2005, I even don't know the basic knowledge of optimization of a XSLT. </div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">*<s>Warning: this patch is immature, and it can cause trouble if your FreeMind .mm file is as large as 200KB!</s></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">*<s>'''Java expert/FreeMind Funs, can you help me to make it usable.'''</s> Thank you.</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Last week when I feel it's time to upgrade to freemind 0.9, I overview and rewrite the xslt and the patch.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Last week when I feel it's time to upgrade to freemind 0.9, I overview and rewrite the xslt and the patch.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"><s>Warning</del>: <del style="font-weight: bold; text-decoration: none;">this patch is immature, and it can cause trouble if your FreeMind .mm file is as large as 200KB!</s></del></div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">-- [[User</ins>:<ins style="font-weight: bold; text-decoration: none;">Jiangxin|Jiangxin]] 02:26</ins>, <ins style="font-weight: bold; text-decoration: none;">15 Mar 2007 (PDT)</ins></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"><s>'''Java expert/FreeMind Funs</del>, <del style="font-weight: bold; text-decoration: none;">can you help me to make it usable.'''</s> Thank you.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==the XSLT==</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==the XSLT==</div></td></tr>
</table>
Jiangxin
https://freemind.sourceforge.io/wiki/index.php?title=User:Jiangxin/Patch_load_mm_file_with_mmx_file&diff=4322&oldid=prev
Jiangxin: fixed low performance xslt
2007-03-15T09:18:50Z
<p>fixed low performance xslt</p>
<a href="https://freemind.sourceforge.io/wiki/index.php?title=User:Jiangxin/Patch_load_mm_file_with_mmx_file&diff=4322&oldid=4321">Show changes</a>
Jiangxin
https://freemind.sourceforge.io/wiki/index.php?title=User:Jiangxin/Patch_load_mm_file_with_mmx_file&diff=4321&oldid=prev
Jiangxin: initial
2006-04-06T17:48:45Z
<p>initial</p>
<p><b>New page</b></p><div>==What is .mmx file?==<br />
.mmx file has the same file structure as FreeMind .mm file, but It only contains the unnecessary and frequently changed attributes. This file is '''NOT''' suitable for version control system.<br />
<br />
How the file is generated? Please see this link: [[User:Jiangxin/Patch_save_extra_attributes_outof_mmfile]].<br />
<br />
==Overview==<br />
'''Warning: this patch is immature, and it can cause trouble if your FreeMind .mm file is as large as 200KB!'''<br />
<br />
'''Java expert/FreeMind Funs, can you help me to make it usable.''' Thank you.<br />
<br />
===the XSLT===<br />
My implementation is using a XSLT file to join the .mmx file with .mm file in runtime. The XSLT is below:<br />
* file : ''freemind/modes/mindmapmode/freemind_join_mm_mmx.xslt''<br />
<pre><nowiki><br />
<xsl:stylesheet version="1.0"<br />
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><br />
<br />
<xsl:output method="xml" version="1.0" encoding="utf-8"<br />
indent="yes" /><br />
<br />
<xsl:param name="mmx_file" /><br />
<br />
<xsl:template match="map"><br />
<map><br />
<xsl:copy-of select="@*" /><br />
<xsl:apply-templates /><br />
</map><br />
</xsl:template><br />
<br />
<xsl:template match="node"><br />
<xsl:param name="mmx_node" select="document($mmx_file)" /><br />
<xsl:copy><br />
<xsl:choose><br />
<xsl:when test="$mmx_node//node[@ID=current()/@ID]"><br />
<xsl:for-each select="@*"><br />
<xsl:choose><br />
<xsl:when test="local-name(.) = 'FOLDED'"><br />
</xsl:when><br />
<xsl:otherwise><br />
<xsl:copy-of select="." /><br />
</xsl:otherwise><br />
</xsl:choose><br />
</xsl:for-each><br />
<xsl:copy-of<br />
select="$mmx_node//node[@ID=current()/@ID]/@*" /><br />
</xsl:when><br />
<xsl:otherwise><br />
<xsl:copy-of select="@*" /><br />
</xsl:otherwise><br />
</xsl:choose><br />
<xsl:apply-templates /><br />
</xsl:copy><br />
</xsl:template><br />
<br />
<xsl:template match="*"><br />
<xsl:copy-of select="."/><br />
</xsl:template><br />
<br />
</xsl:stylesheet><br />
</nowiki></pre><br />
<br />
=== Problem 1: too slow ===<br />
But is is very slow if .mm file and .mmx is as big as 200KB. I test my file using xsltproc like this.<br />
<pre><nowiki><br />
$ time xsltproc --stringparam mmx_file subject-forum.mmx freemind_join_mm_mmx.xslt subject-forum.mm > jx.mm<br />
<br />
real 4m33.148s<br />
user 4m30.093s<br />
sys 0m0.015s<br />
</nowiki></pre><br />
<br />
=== Problem 2: memery killer ===<br />
load without .mmx file, only 40MB memery usage. But if load .mm file with .mmx file, 80MB maybe. It terrible, where is Java GC? Just a tale of sun. (Sorry, I am not familiar with Java.)<br />
<br />
<br />
== My Immature Patch ==<br />
<pre><nowiki><br />
Index: freemind/freemind/modes/mindmapmode/MindMapMapModel.java<br />
===================================================================<br />
--- freemind/freemind/modes/mindmapmode/MindMapMapModel.java (.../tags/RELEASE-0-8-0) (revision 2)<br />
+++ freemind/freemind/modes/mindmapmode/MindMapMapModel.java (.../branches/WHFM-0-8-0) (working copy)<br />
@@ -519,21 +562,37 @@<br />
}<br />
// the resulting file is accessed by the reader:<br />
Reader reader = null;<br />
- if (mapStart.equals(expectedStartString)<br />
- || mapStart.equals(expectedAlternativeStartString)) {<br />
- // actual version:<br />
- reader = getActualReader(file);<br />
- } else {<br />
+ // join .mmx with .mm file<br />
+ reader = getActualReader(file);<br />
+<br />
+ if (! mapStart.equals(expectedStartString)<br />
+ && ! mapStart.equals(expectedAlternativeStartString)) {<br />
// older version:<br />
- reader = getUpdateReader(file);<br />
+ reader = getUpdateReader(reader, file.getName());<br />
}<br />
try {<br />
mapElement.parseFromReader(reader);<br />
@@ -573,14 +602,15 @@<br />
<br />
/** Creates a reader that pipes the input file through a XSLT-Script that<br />
* updates the version to the current.<br />
- * @param file<br />
+ * @param reader<br />
+ * @param filename<br />
* @return <br />
* @throws IOException<br />
*/<br />
- private Reader getUpdateReader(File file) throws IOException {<br />
+ private Reader getUpdateReader(Reader reader, String filename) throws IOException {<br />
StringWriter writer = null;<br />
InputStream inputStream = null;<br />
- logger.info("Updating the file "+file.getName()+" to the current version.");<br />
+ logger.info("Updating the file "+filename+" to the current version.");<br />
try{<br />
// try to convert map with xslt:<br />
URL updaterUrl=null;<br />
@@ -598,12 +629,12 @@<br />
// create an instance of TransformerFactory<br />
TransformerFactory transFact = TransformerFactory.newInstance();<br />
Transformer trans = transFact.newTransformer(xsltSource);<br />
- trans.transform(new StreamSource(file), result);<br />
- logger.info("Updating the file "+file.getName()+" to the current version. Done.");<br />
+ trans.transform(new StreamSource(reader), result);<br />
+ logger.info("Updating the file "+filename+" to the current version. Done.");<br />
} catch(Exception ex) {<br />
ex.printStackTrace();<br />
// exception: we take the file itself:<br />
- return getActualReader(file);<br />
+ return reader;<br />
} finally {<br />
if(inputStream!= null) {<br />
inputStream.close();<br />
@@ -618,12 +649,99 @@<br />
/** Creates a default reader that just reads the given file.<br />
* @param file<br />
* @return<br />
- * @throws FileNotFoundException<br />
+ * @throws IOException <br />
*/<br />
- private Reader getActualReader(File file) throws FileNotFoundException {<br />
- return new BufferedReader(new FileReader(file));<br />
+ private Reader getActualReaderXml(File file) throws IOException {<br />
+ try<br />
+ {<br />
+ TransformerFactory tf = TransformerFactory.newInstance();<br />
+ Transformer transformer = tf.newTransformer();<br />
+ DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();<br />
+ DocumentBuilder domBuilder = domFactory.newDocumentBuilder();<br />
+<br />
+ Document doc = domBuilder.parse(file);<br />
+ Source src = new DOMSource(doc);<br />
+ StringWriter buffwriter = new StringWriter();<br />
+ StreamResult result = new StreamResult(buffwriter);<br />
+ transformer.transform(src, result);<br />
+<br />
+ return new StringReader(buffwriter.toString());<br />
+ }<br />
+ catch(Exception exp)<br />
+ {<br />
+ exp.printStackTrace();<br />
+ }<br />
+<br />
+ return new BufferedReader(new FileReader(file)); <br />
}<br />
<br />
+ private Reader getActualReader(File file) throws IOException {<br />
+ // load .mmx file...<br />
+ String ext = Tools.getExtension(file.getName());<br />
+ String mmxFileName = "";<br />
+<br />
+ if(!ext.equals("mm")) <br />
+ {<br />
+ mmxFileName = file.getName()+".mmx";<br />
+ }<br />
+ else <br />
+ {<br />
+ mmxFileName = Tools.removeExtension(file.getName()) + ".mmx";<br />
+ }<br />
+ File mmxfile = new File(file.getParent(), mmxFileName);<br />
+ <br />
+ if (!mmxfile.exists())<br />
+ {<br />
+ return getActualReaderXml(file);<br />
+ }<br />
+<br />
+ URL updaterUrl = null;<br />
+ InputStream inputStream = null;<br />
+ Source xsltSource = null;<br />
+ StringWriter buffwriter = null;<br />
+ Result result = null;<br />
+ TransformerFactory tf = null;<br />
+ Transformer transformer = null;<br />
+ String mmxFileFullName = file.getParent() + "/" + mmxFileName;<br />
+ try {<br />
+ // try to convert map with xslt:<br />
+ updaterUrl = getFrame().getResource(<br />
+ "freemind/modes/mindmapmode/freemind_join_mm_mmx.xslt");<br />
+ if (updaterUrl == null) {<br />
+ throw new IllegalArgumentException(<br />
+ "freemind_join_mm_mmx.xslt not found.");<br />
+ }<br />
+ inputStream = updaterUrl.openStream();<br />
+ xsltSource = new StreamSource(inputStream);<br />
+ // get output:<br />
+ buffwriter = new StringWriter();<br />
+ result = new StreamResult(buffwriter);<br />
+ // create an instance of TransformerFactory<br />
+ tf = TransformerFactory.newInstance();<br />
+ transformer = tf.newTransformer(xsltSource);<br />
+ transformer.setParameter("mmx_file", mmxFileFullName);<br />
+ transformer.transform(new StreamSource(file), result);<br />
+<br />
+ } catch (Exception ex) {<br />
+ ex.printStackTrace();<br />
+ // exception: we take the file itself:<br />
+ return getActualReaderXml(file);<br />
+ } finally {<br />
+ if (inputStream != null) {<br />
+ inputStream.close();<br />
+ }<br />
+ if (buffwriter != null) {<br />
+ buffwriter.close();<br />
+ }<br />
+ inputStream = null;<br />
+ xsltSource = null;<br />
+ updaterUrl = null;<br />
+ result = null;<br />
+ transformer = null;<br />
+ tf = null;<br />
+ }<br />
+ return new StringReader(buffwriter.getBuffer().toString()); }<br />
+<br />
//<br />
// cut'n'paste<br />
//<br />
Index: freemind/freemind/modes/mindmapmode/freemind_join_mm_mmx.xslt<br />
===================================================================<br />
--- freemind/freemind/modes/mindmapmode/freemind_join_mm_mmx.xslt (.../tags/RELEASE-0-8-0) (revision 0)<br />
+++ freemind/freemind/modes/mindmapmode/freemind_join_mm_mmx.xslt (.../branches/WHFM-0-8-0) (revision 28)<br />
@@ -0,0 +1,45 @@<br />
+<xsl:stylesheet version="1.0"<br />
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><br />
+<br />
+ <xsl:output method="xml" version="1.0" encoding="utf-8"<br />
+ indent="yes" /><br />
+<br />
+ <xsl:param name="mmx_file" /><br />
+<br />
+ <xsl:template match="map"><br />
+ <map><br />
+ <xsl:copy-of select="@*" /><br />
+ <xsl:apply-templates /><br />
+ </map><br />
+ </xsl:template><br />
+<br />
+ <xsl:template match="node"><br />
+ <xsl:param name="mmx_node" select="document($mmx_file)" /><br />
+ <xsl:copy><br />
+ <xsl:choose><br />
+ <xsl:when test="$mmx_node//node[@ID=current()/@ID]"><br />
+ <xsl:for-each select="@*"><br />
+ <xsl:choose><br />
+ <xsl:when test="local-name(.) = 'FOLDED'"><br />
+ </xsl:when><br />
+ <xsl:otherwise><br />
+ <xsl:copy-of select="." /><br />
+ </xsl:otherwise><br />
+ </xsl:choose><br />
+ </xsl:for-each><br />
+ <xsl:copy-of<br />
+ select="$mmx_node//node[@ID=current()/@ID]/@*" /><br />
+ </xsl:when><br />
+ <xsl:otherwise><br />
+ <xsl:copy-of select="@*" /><br />
+ </xsl:otherwise><br />
+ </xsl:choose><br />
+ <xsl:apply-templates /><br />
+ </xsl:copy><br />
+ </xsl:template><br />
+<br />
+ <xsl:template match="*"><br />
+ <xsl:copy-of select="."/><br />
+ </xsl:template><br />
+<br />
+</xsl:stylesheet><br />
Index: freemind/build.xml<br />
===================================================================<br />
--- freemind/build.xml (.../tags/RELEASE-0-8-0) (revision 2)<br />
+++ freemind/build.xml (.../branches/WHFM-0-8-0) (working copy)<br />
@@ -284,6 +284,7 @@<br />
<include name="Resources*"/><br />
<include name="mindmap_menus.xml"/><br />
<include name="**/freemind_version_updater.xslt"/><br />
+ <include name="**/freemind_join_mm_mmx.xslt"/><br />
</fileset><br />
</jar><br />
</target><br />
</nowiki></pre></div>
Jiangxin