root/10030_split_mm_into_two_files.patch @ 56:eeb9c6a9510c

Revision 56:eeb9c6a9510c, 16.3 KB (checked in by Jiang Xin <worldhello.net AT gmail DOT com>, 3 years ago)

See #17: SourceForge? project is registered as freemind-mmx, so change package name to 'MMX Hack'.

  • freemind/main/XMLElement.java

    diff -r 962e66fc663a freemind/main/XMLElement.java
    a b  
    291291     */ 
    292292    private int parserLineNr; 
    293293 
     294    // OSSXP.COM: some attribute saved in .mmx file, instead of the default .mm file. 
     295    // three attlist. 0: WhiteList, 1: BlackList, 2:EmList 
     296    private String special_attlist[]; 
    294297 
     298    private void _addtoAttlist(int list, String att) 
     299    { 
     300        if (list >= special_attlist.length || list <0) 
     301                return; 
     302        this.special_attlist[list] += att; 
     303        this.special_attlist[list] += ":"; 
     304        return; 
     305    } 
     306     
     307    private boolean _isInAttlist(int list, String att) 
     308    { 
     309        if ( list >= special_attlist.length || list <0 || special_attlist[list].length()==0 ) { 
     310                return false; 
     311        } 
     312        return this.special_attlist[list].contains(att+':'); 
     313    } 
     314 
     315    public boolean isInWhiteAttlist(String att) 
     316    { 
     317        // WHITE list is not NULL 
     318        if ( this.special_attlist[0].length()!=0 ) { 
     319                return _isInAttlist(0, att); 
     320        } 
     321        // BLACK list is not NULL 
     322        if ( this.special_attlist[1].length()!=0 ) { 
     323                return ! _isInAttlist(1, att); 
     324        } 
     325        // Default return true; 
     326        return true; 
     327    } 
     328 
     329    public boolean isInBlackAttlist(String att) 
     330    { 
     331        // BLACK list is not NULL 
     332        if ( this.special_attlist[1].length()!=0 ) { 
     333                return _isInAttlist(1, att); 
     334        } 
     335        // WHITE list is not NULL 
     336        if ( this.special_attlist[0].length()!=0 ) { 
     337                return ! _isInAttlist(0, att); 
     338        } 
     339        // Default return false; 
     340        return false; 
     341    } 
     342 
     343    public boolean isInEmAttlist(String att) 
     344    { 
     345        return _isInAttlist(2, att); 
     346    } 
     347 
     348    public void addtoWhiteAttlist(String att) 
     349    { 
     350        _addtoAttlist(0, att); 
     351    } 
     352 
     353    public void addtoBlackAttlist(String att) 
     354    { 
     355        _addtoAttlist(1, att); 
     356    } 
     357 
     358    public void addtoEmAttlist(String att) 
     359    { 
     360        _addtoAttlist(2, att); 
     361    } 
     362     
    295363    /** 
    296364     * Creates and initializes a new XML element. 
    297365     * Calling the construction is equivalent to: 
     
    506574        this.children = new Vector(); 
    507575        this.entities = entities; 
    508576        this.lineNr = 0; 
     577        // OSSXP.COM: save some attributes out of .mm file. 
     578        this.special_attlist = new String[3]; 
     579        for (int i = 0; i < 3; i++) { 
     580                special_attlist[i] = ""; 
     581        } 
    509582        Enumeration enumerator = this.entities.keys(); 
    510583        while (enumerator.hasMoreElements()) { 
    511584            Object key = enumerator.nextElement(); 
     
    21832256        if (! this.attributes.isEmpty()) { 
    21842257            Iterator enumerator = this.attributes.keySet().iterator(); 
    21852258            while (enumerator.hasNext()) { 
    2186                 writer.write(' '); 
    21872259                String key = (String) enumerator.next(); 
    21882260                String value = (String) this.attributes.get(key); 
     2261 
     2262                // OSSXP.COM:  
     2263                if ( this.isInBlackAttlist(key) ) 
     2264                { 
     2265                        continue; 
     2266                } 
     2267 
     2268                writer.write(' '); 
     2269 
     2270                if ( this.isInEmAttlist(key) ) 
     2271                { 
     2272                        writer.write("\n\t"); 
     2273                } 
     2274 
    21892275                writer.write(key); 
    21902276                writer.write('='); writer.write('"'); 
    21912277                this.writeEncoded(writer, value); 
  • freemind/modes/MindMapNode.java

    diff -r 962e66fc663a freemind/modes/MindMapNode.java
    a b  
    250250     * @param saveChildren if true, the save recurses to all of the nodes children. 
    251251     */ 
    252252    public XMLElement save(Writer writer, MindMapLinkRegistry registry, boolean saveHidden, boolean saveChildren) throws IOException; 
     253    public XMLElement save(Writer writer, MindMapLinkRegistry registry, boolean saveHidden, boolean saveChildren, int managed_attr) throws IOException; 
    253254 
    254255    // fc, 10.2.2005: 
    255256    /** State icons are icons that are not saved. They indicate that 
  • freemind/modes/NodeAdapter.java

    diff -r 962e66fc663a freemind/modes/NodeAdapter.java
    a b  
    5656import freemind.main.FreeMindCommon; 
    5757import freemind.main.FreeMindMain; 
    5858import freemind.main.HtmlTools; 
     59import freemind.main.Resources; 
    5960import freemind.main.Tools; 
    6061import freemind.main.XMLElement; 
    6162import freemind.modes.attributes.Attribute; 
     
    957958            return controller.getNodeID(this); 
    958959        } 
    959960 
    960     public XMLElement save(Writer writer, MindMapLinkRegistry registry, boolean saveInvisible, boolean saveChildren) throws IOException { 
     961        /** 
     962         * @param writer 
     963         * @param registry 
     964         * @param managed_attr =0|1|2 
     965         *         0 (default): save to .mm  file. (do not save certain attributes, such as node's fold status) 
     966         *         1          : save to .mmx file. (only save auxiliary attributes, such as node's fold status) 
     967         *         2          : all-in-one .mm file. the default behavior of vanilla freemind. 
     968         * @return 
     969         */ 
     970        public XMLElement save(Writer writer, MindMapLinkRegistry registry, boolean saveInvisible, boolean saveChildren) throws IOException { 
     971                return save(writer, registry, saveInvisible, saveChildren, 0); 
     972        } 
     973 
     974        public XMLElement save(Writer writer, MindMapLinkRegistry registry, boolean saveInvisible, boolean saveChildren, int managed_attr) throws IOException { 
    961975        // pre save event to save all contents of the node: 
    962976        getModeController().firePreSaveEvent(this); 
    963977        XMLElement node = new XMLElement(); 
    964978 
     979        // OSSXP.COM: new line before 'TEXT' attribute. 
     980        node.addtoEmAttlist("TEXT"); 
     981        // OSSXP.COM: according to the managed_attr parameter, save or not save certain keys of this NODE. 
     982        switch (managed_attr) 
     983        { 
     984        case 0: 
     985                // Save this node to .mm file without certain attributes. 
     986                if(Resources.getInstance().getBoolProperty("wh_save_extra_attrs_in_aux_file") && Resources.getInstance().getBoolProperty("wh_separate_attr_created")) node.addtoBlackAttlist("CREATED"); 
     987                if(Resources.getInstance().getBoolProperty("wh_save_extra_attrs_in_aux_file") && Resources.getInstance().getBoolProperty("wh_separate_attr_modified")) node.addtoBlackAttlist("MODIFIED"); 
     988                break; 
     989        case 1: 
     990                // Save this node to .mmx file. Only save certain attributes. 
     991                node.addtoWhiteAttlist("ID"); 
     992                if(Resources.getInstance().getBoolProperty("wh_save_extra_attrs_in_aux_file") && Resources.getInstance().getBoolProperty("wh_separate_attr_folded")) node.addtoWhiteAttlist("FOLDED"); 
     993                if(Resources.getInstance().getBoolProperty("wh_save_extra_attrs_in_aux_file") && Resources.getInstance().getBoolProperty("wh_separate_attr_created")) node.addtoWhiteAttlist("CREATED"); 
     994                if(Resources.getInstance().getBoolProperty("wh_save_extra_attrs_in_aux_file") && Resources.getInstance().getBoolProperty("wh_separate_attr_modified")) node.addtoWhiteAttlist("MODIFIED"); 
     995                break; 
     996        } 
     997 
    965998//      if (!isNodeClassToBeSaved()) { 
    966999        node.setName(XMLElementAdapter.XML_NODE); 
    9671000//        } else { 
     
    9701003//        } 
    9711004 
    9721005        /** fc, 12.6.2005: XML must not contain any zero characters. */ 
     1006        // OSSXP.COM: not save TEXT attributes in .mmx file 
     1007        if( node.isInWhiteAttlist("TEXT")) 
     1008        { 
    9731009        String text = this.toString().replace('\0', ' '); 
    9741010        if(!HtmlTools.isHtmlNode(text)) { 
    9751011            node.setAttribute(XMLElementAdapter.XML_NODE_TEXT,text); 
     
    9891025                        node.addChild(htmlElement); 
    9901026                 
    9911027        } 
     1028        } 
    9921029        // save additional info: 
    9931030        if (getAdditionalInfo() != null) { 
    9941031            node.setAttribute(XMLElementAdapter.XML_NODE_ENCRYPTED_CONTENT, 
     
    9961033        } 
    9971034        //      ((MindMapEdgeModel)getEdge()).save(doc,node); 
    9981035 
     1036        // OSSXP.COM: not save EDGE in .mmx 
     1037        if( node.isInWhiteAttlist("EDGE")) 
     1038        { 
    9991039        XMLElement edge = (getEdge()).save(); 
    10001040        if (edge != null) { 
    10011041               node.addChild(edge); } 
     1042        } 
    10021043 
    1003         if(getCloud() != null) { 
     1044        // OSSXP.COM: not save CLOUD in .mmx 
     1045        if( node.isInWhiteAttlist("CLOUD")) 
     1046        { 
     1047        if(getCloud() != null) { 
    10041048            XMLElement cloud = (getCloud()).save(); 
    10051049            node.addChild(cloud); 
    10061050        } 
     1051        } 
    10071052 
     1053        // OSSXP.COM: not save ARROWLINK in .mmx 
     1054        if( node.isInWhiteAttlist("ARROWLINK")) 
     1055        { 
    10081056        Vector linkVector = registry.getAllLinksFromMe(this); /* Puh... */ 
    10091057        for(int i = 0; i < linkVector.size(); ++i) { 
    10101058            if(linkVector.get(i) instanceof ArrowLinkAdapter) { 
     
    10121060                node.addChild(arrowLinkElement); 
    10131061            } 
    10141062        } 
     1063        } 
    10151064 
    1016         if (isFolded()) { 
    1017                node.setAttribute("FOLDED","true"); } 
    1018  
     1065        // OSSXP.COM: set FOLDED status of all nodes in .mm file to "true". Preserve orignal status in .mmx file.  
     1066        switch (managed_attr) 
     1067        { 
     1068        case 0: 
     1069                // Save this node to .mm file without certain attributes. 
     1070                if(Resources.getInstance().getBoolProperty("wh_save_extra_attrs_in_aux_file") && Resources.getInstance().getBoolProperty("wh_separate_attr_folded"))  
     1071         { 
     1072           if (!isRoot() && !isLeaf()) { 
     1073             node.setAttribute("FOLDED","true"); 
     1074                  } 
     1075           break; 
     1076         } 
     1077        case 1: 
     1078        case 2: 
     1079        default: 
     1080                if (isFolded()) { 
     1081                        node.setAttribute("FOLDED","true");  
     1082                } else { 
     1083                        node.setAttribute("FOLDED","false"); 
     1084                } 
     1085        } 
     1086         
    10191087        // fc, 17.12.2003: Remove the left/right bug. 
    10201088        //                       VVV  save if and only if parent is root. 
    10211089        if (!(isRoot()) && (getParentNode().isRoot())) { 
     
    10691137                                                                        .getLastModifiedAt())); 
    10701138        } 
    10711139        //font 
     1140        // OSSXP.COM: not save FONT in .mmx 
     1141        if( node.isInWhiteAttlist("FONT")) 
     1142        { 
    10721143        if (font!=null) { 
    10731144            XMLElement fontElement = new XMLElement(); 
    10741145            fontElement.setName("font"); 
     
    10841155            if (isUnderlined()) { 
    10851156                   fontElement.setAttribute("UNDERLINE","true"); } 
    10861157            node.addChild(fontElement); } 
     1158        } 
     1159        // OSSXP.COM: not save ICON in .mmx 
     1160        if( node.isInWhiteAttlist("ICON")) 
     1161        { 
    10871162        for(int i = 0; i < getIcons().size(); ++i) { 
    10881163            XMLElement iconElement = new XMLElement(); 
    10891164            iconElement.setName("icon"); 
    10901165            iconElement.setAttribute("BUILTIN", ((MindIcon) getIcons().get(i)).getName()); 
    10911166            node.addChild(iconElement); 
    10921167        } 
     1168        } 
    10931169 
     1170        // OSSXP.COM: not save HOOK in .mmx 
     1171        if( node.isInWhiteAttlist("HOOK")) 
     1172        { 
    10941173        for (Iterator i = getActivatedHooks().iterator(); i.hasNext();) { 
    10951174            XMLElement hookElement = new XMLElement(); 
    10961175            hookElement.setName("hook"); 
    10971176            ((PermanentNodeHook) i.next()).save(hookElement); 
    10981177            node.addChild(hookElement); 
    10991178        } 
     1179        } 
    11001180 
     1181        // OSSXP.COM: not save ATTRIBUTE in .mmx 
     1182        if( node.isInWhiteAttlist("ATTRIBUTE")) 
     1183        { 
    11011184        attributes.save(node); 
     1185        } 
    11021186        if (saveChildren && childrenUnfolded().hasNext()) { 
    11031187            node.writeWithoutClosingTag(writer); 
    11041188            //recursive 
    1105             saveChildren(writer, registry, this, saveInvisible); 
     1189            saveChildren(writer, registry, this, saveInvisible, managed_attr); 
    11061190            node.writeClosingTag(writer); 
    11071191        } else { 
    11081192            node.write(writer); 
     
    11141198                return map.getModeController(); 
    11151199        } 
    11161200 
     1201        // OSSXP.COM: PARAM managed_attr, controls whether or not save certain attrs (such as nodes's folded status) in .mm files.  
    11171202    private void saveChildren(Writer writer, MindMapLinkRegistry registry, NodeAdapter node, boolean saveHidden) throws IOException { 
     1203        saveChildren(writer, registry, node, saveHidden, 0); 
     1204    } 
     1205    private void saveChildren(Writer writer, MindMapLinkRegistry registry, NodeAdapter node, boolean saveHidden, int managed_attr) throws IOException { 
    11181206        for (ListIterator e = node.childrenUnfolded(); e.hasNext();) { 
    11191207            NodeAdapter child = (NodeAdapter) e.next(); 
    11201208            if(saveHidden || child.isVisible()) 
    1121                 child.save(writer, registry, saveHidden, true); 
     1209                child.save(writer, registry, saveHidden, true, managed_attr); 
    11221210            else 
    1123                 saveChildren(writer, registry, child, saveHidden); 
     1211                saveChildren(writer, registry, child, saveHidden, managed_attr); 
    11241212        } 
    11251213    } 
    11261214 
  • freemind/modes/mindmapmode/MindMapMapModel.java

    diff -r 962e66fc663a freemind/modes/mindmapmode/MindMapMapModel.java
    a b  
    254254                } 
    255255            // OSSXP.COM: save file using default character set. 
    256256            BufferedWriter fileout = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(file), FreeMind.DEFAULT_CHARSET ) ); 
    257             getXml(fileout); 
     257            // OSSXP.COM: save tree into .mm file, without some attrs(such as node fold status). 
     258            getXml(fileout, true, 0); 
     259             
     260            if(Resources.getInstance().getBoolProperty("wh_save_extra_attrs_in_aux_file")) 
     261            { 
     262              // OSSXP.COM: save variable attrs(such as node fold status) into .mmx file... 
     263              String ext = Tools.getExtension(file.getName()); 
     264              String mmxFileName = ""; 
     265              if(!ext.equals("mm"))  
     266              { 
     267                mmxFileName = "." + file.getName()+".mmx"; 
     268              } 
     269              else  
     270              { 
     271                mmxFileName = "." + Tools.removeExtension(file.getName()) + ".mmx"; 
     272              } 
     273              File mmxfile = new File(file.getParent(), mmxFileName);  
     274              BufferedWriter mmxfileout = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(mmxfile), FreeMind.DEFAULT_CHARSET ) ); 
     275              getXml(mmxfileout, true, 1); 
     276            } 
    258277 
    259278            if(!isInternal) { 
    260279                setFile(file); 
     
    279298 
    280299    /** writes the content of the map to a writer. 
    281300         * @throws IOException 
     301         * @param managed_attr =0|1|2 
     302         *         0 (default): save to .mm  file. (do not save certain attributes, such as node's fold status) 
     303         *         1          : save to .mmx file. (only save auxiliary attributes, such as node's fold status) 
     304         *         2          : all-in-one .mm file. the default behavior of vanilla freemind. 
    282305         */ 
    283         private void getXml(Writer fileout, boolean saveInvisible) throws IOException { 
     306        private void getXml(Writer fileout, boolean saveInvisible, int managed_attr) throws IOException { 
    284307                // OSSXP.COM: write xml declare. 
    285308                fileout.write("<?xml version=\"1.0\" encoding=\"" + FreeMind.DEFAULT_CHARSET + "\"?>\n"); 
    286309                fileout.write("<map "); 
    287310                fileout.write("version=\""+FreeMind.XML_VERSION+"\""); 
    288311                fileout.write(">\n"); 
    289                 fileout.write("<!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->\n"); 
    290                 getRegistry().save(fileout); 
    291                 (getRootNode()).save(fileout, this.getLinkRegistry(), saveInvisible, true); 
     312                // OSSXP.COM: add notice for this hacked version. 
     313                fileout.write("<!-- This file is saved using a hacked version of FreeMind. visit: http://freemind-mmx.sourceforge.net -->\n"); 
     314                fileout.write("<!-- Orignal FreeMind, can download from http://freemind.sourceforge.net -->\n"); 
     315                switch (managed_attr) 
     316                { 
     317                case 0: 
     318                        fileout.write("<!-- This .mm file is CVS/SVN friendly, some atts are saved in .mmx file. (from ossxp.com) -->\n"); 
     319                        break; 
     320                case 1: 
     321                        fileout.write("<!-- This .mmx files store some extra mm file attributes, which should not check in to CVS/SVN ! -->\n"); 
     322                        break; 
     323                case 2: 
     324                default: 
     325                        break; 
     326                } 
     327                if(managed_attr != 1) { 
     328                        getRegistry().save(fileout); 
     329                } 
     330                // OSSXP.COM: managed_attr control whether or not save nodes' fold status into .mm file. 
     331                (getRootNode()).save(fileout, this.getLinkRegistry(), saveInvisible, true, managed_attr); 
    292332                fileout.write("</map>\n"); 
    293333                fileout.close(); 
    294334        } 
    295335    public void getXml(Writer fileout) throws IOException{ 
    296         getXml(fileout, true); 
     336        getXml(fileout, true, 0); 
    297337    } 
    298338 
    299339    public void getFilteredXml(Writer fileout) throws IOException{ 
    300         getXml(fileout, false); 
     340        getXml(fileout, false, 0); 
    301341    } 
    302342 
    303343        /** 
Note: See TracBrowser for help on using the browser.