import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.Writer; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import org.ini4j.Ini; /** * A transformer which can turn the .ini file you can export your Miranda contacts as into a FOAF file. */ public class ContactListTransformer { //Mapping between protocol names in the .ini and FOAF-properties for identifiers from those protocols static Map propNames = new HashMap(); static { propNames.put("JABBER", "jabberID"); propNames.put("ICQ", "icqChatID"); //The following keys I just assumed, I don't have those protocols in my contact list propNames.put("MSN", "msnChatID"); propNames.put("AIM", "aimChatID"); propNames.put("YAHOO", "yahooChatID"); } /** * Read an .ini file from inputPath, transform it into FOAF and output that to outputPath, * using myURI as the URIref of the person this is the contact list of. */ public static void transform(String inputPath, String outputPath, String myURI) throws IOException { //Read file FileReader in = new FileReader(inputPath); Ini ini = new Ini(); ini.load(in); in.close(); //Open output file PrintWriter out = new PrintWriter( new FileWriter(outputPath) ); //List for collecting group names, groups will be output later List groups = new ArrayList(); //Header out.println(""); out.println(""); out.println(); out.println("\t"); out.println("\t\t"); out.println("\t\t"); out.println("\t"); out.println(); out.println("\t"); //Go through sections of the .ini which are the single contacts Collection values = ini.values(); for (Ini.Section section : values) { //When there's an entry Hidden=1, don't add this contact String hidden = section.get("Hidden"); if (hidden != null && hidden.equals("1")) continue; //Collect properties of contact String id = section.get("ID"); String nick = section.get("CListNick"); String protocol = section.get("Proto"); String groupName = section.get("CListGroup"); //Start writing contact info out.println("\t\t"); out.println("\t\t\t"); //Output nick if there is one if (nick != null && !nick.equals("")) out.println("\t\t\t\t" + nick + ""); //Output ID with the appropriate property if we have one for this protocol String propName = propNames.get(protocol); if (propName != null) out.println("\t\t\t\t<" + propName + ">" + id + ""); //Output group membership if (groupName != null) { int groupNo; //See if we had this group before if (!groups.contains(groupName)) { groups.add(groupName); groupNo = groups.size() - 1; } else groupNo = groups.lastIndexOf(groupName); //The group will be a b-node pointed to with the identifier "groupN" where N is the index of the group entry in the list out.println("\t\t\t\t"); } //Done with this contact out.println("\t\t\t"); out.println("\t\t"); } //Done with all contact relations out.println("\t"); out.println(); //Output groups for (int i = 0, len = groups.size(); i < len; i++) { out.println("\t"); out.println("\t\t" + groups.get(i) + ""); out.println("\t"); } //Footer out.println(); out.print(""); //Close file out.close(); } public static void main(String[] args) throws IOException { transform("ContactList.ini", "im_contacts.rdf", "http://simon-reinhardt.de/#me"); } }