From: Olivier G. <og...@us...> - 2007-05-03 21:06:03
|
Update of /cvsroot/osmose-dev/osmose/src/osmose/application/dialog In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21458/osmose/src/osmose/application/dialog Modified Files: OSMDialogExport.java Log Message: Added export to OPML. Index: OSMDialogExport.java =================================================================== RCS file: /cvsroot/osmose-dev/osmose/src/osmose/application/dialog/OSMDialogExport.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** OSMDialogExport.java 30 Aug 2005 17:44:08 -0000 1.1.1.1 --- OSMDialogExport.java 3 May 2007 21:06:01 -0000 1.2 *************** *** 62,65 **** --- 62,66 ---- private boolean m_FormatTxt; private boolean m_FormatXml; + private boolean m_FormatOpml; private boolean m_FormatPdf; private boolean m_FormatRtf; *************** *** 68,71 **** --- 69,73 ---- public final static String TXT = "txt"; public final static String XML = "xml"; + public final static String OPML = "opml"; public final static String RTF = "rtf"; public final static String PDF = "pdf"; *************** *** 92,95 **** --- 94,98 ---- m_FormatTxt = ((Boolean)OSMUser.USER.getProperty("export.format.txt",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportFormatTxt")))).booleanValue(); m_FormatXml = ((Boolean)OSMUser.USER.getProperty("export.format.xml",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportFormatXml")))).booleanValue(); + m_FormatOpml = ((Boolean)OSMUser.USER.getProperty("export.format.opml",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportFormatOpml")))).booleanValue(); m_FormatPdf = ((Boolean)OSMUser.USER.getProperty("export.format.pdf",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportFormatPdf")))).booleanValue(); m_FormatRtf = ((Boolean)OSMUser.USER.getProperty("export.format.rtf",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportFormatRtf")))).booleanValue(); *************** *** 97,101 **** m_TxtMediaIncluded = ((Boolean)OSMUser.USER.getProperty("export.txt.media.included",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportTxtMediaIncluded")))).booleanValue(); m_PdfUrlIncluded = ((Boolean)OSMUser.USER.getProperty("export.pdf.url.included",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportPdfUrlIncluded")))).booleanValue(); ! m_Extensions = new String[]{TXT,XML,RTF,HTML,PDF}; m_HtmlImgIncluded = ((Boolean)OSMUser.USER.getProperty("export.html.img.included",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportHtmlImgIncluded")))).booleanValue(); m_HtmlVidIncluded = ((Boolean)OSMUser.USER.getProperty("export.html.vid.included",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportHtmlVidIncluded")))).booleanValue(); --- 100,104 ---- m_TxtMediaIncluded = ((Boolean)OSMUser.USER.getProperty("export.txt.media.included",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportTxtMediaIncluded")))).booleanValue(); m_PdfUrlIncluded = ((Boolean)OSMUser.USER.getProperty("export.pdf.url.included",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportPdfUrlIncluded")))).booleanValue(); ! m_Extensions = new String[]{TXT,XML,OPML,RTF,HTML,PDF}; m_HtmlImgIncluded = ((Boolean)OSMUser.USER.getProperty("export.html.img.included",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportHtmlImgIncluded")))).booleanValue(); m_HtmlVidIncluded = ((Boolean)OSMUser.USER.getProperty("export.html.vid.included",new Boolean(OSMApplication.Properties.getStringProp("OSM_ExportHtmlVidIncluded")))).booleanValue(); *************** *** 182,185 **** --- 185,189 ---- if(m_FormatTxt) ext=TXT; else if(m_FormatXml) ext=XML; + else if(m_FormatOpml) ext=OPML; else if(m_FormatPdf) ext=PDF; else if(m_FormatRtf) ext=RTF; *************** *** 220,223 **** --- 224,231 ---- rbXml.setSelected(m_FormatXml); rbXml.addKeyListener(this); + final JRadioButton rbOpml = new JRadioButton("OPML"); + rbOpml.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){m_FormatOpml = rbOpml.isSelected(); refreshExportFile(OPML);}}); + rbOpml.setSelected(m_FormatOpml); + rbOpml.addKeyListener(this); final JRadioButton rbPdf = new JRadioButton(OSMApplication.Localisation.getString("DEX_FormatPdfLabel")); rbPdf.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){m_FormatPdf = rbPdf.isSelected(); refreshExportFile(PDF); }}); *************** *** 274,277 **** --- 282,286 ---- bg.add(rbTxt); bg.add(rbXml); + bg.add(rbOpml); bg.add(rbPdf); bg.add(rbRtf); *************** *** 280,284 **** pFormat.add(rbTxt,new Rectangle(0,0,6,1)); pFormat.add(cbTxtMediaIncluded,new Rectangle(1,1,3,1)); ! pFormat.add(rbXml,new Rectangle(0,2,6,1)); pFormat.add(rbPdf,new Rectangle(0,3,6,1)); pFormat.add(cbPdfUrlIncluded,new Rectangle(1,4,3,1)); --- 289,294 ---- pFormat.add(rbTxt,new Rectangle(0,0,6,1)); pFormat.add(cbTxtMediaIncluded,new Rectangle(1,1,3,1)); ! pFormat.add(rbXml,new Rectangle(0,2,4,1)); ! pFormat.add(rbOpml,new Rectangle(4,2,2,1)); pFormat.add(rbPdf,new Rectangle(0,3,6,1)); pFormat.add(cbPdfUrlIncluded,new Rectangle(1,4,3,1)); *************** *** 299,302 **** --- 309,313 ---- m_FormatTxt=false; m_FormatXml=false; + m_FormatOpml=false; m_FormatPdf=false; m_FormatRtf=false; *************** *** 304,307 **** --- 315,319 ---- if(m_File.getPath().endsWith("."+TXT)) m_FormatTxt=true; else if(m_File.getPath().endsWith("."+XML)) m_FormatXml=true; + else if(m_File.getPath().endsWith("."+OPML)) m_FormatOpml=true; else if(m_File.getPath().endsWith("."+PDF)) m_FormatPdf=true; else if(m_File.getPath().endsWith("."+RTF)) m_FormatRtf=true; *************** *** 309,312 **** --- 321,325 ---- rbTxt.setSelected(m_FormatTxt); rbXml.setSelected(m_FormatXml); + rbOpml.setSelected(m_FormatOpml); rbPdf.setSelected(m_FormatPdf); rbRtf.setSelected(m_FormatRtf); *************** *** 417,420 **** --- 430,434 ---- OSMUser.USER.setProperty("export.format.txt",new Boolean(m_FormatTxt)); OSMUser.USER.setProperty("export.format.xml",new Boolean(m_FormatXml)); + OSMUser.USER.setProperty("export.format.opml",new Boolean(m_FormatOpml)); OSMUser.USER.setProperty("export.format.pdf",new Boolean(m_FormatPdf)); OSMUser.USER.setProperty("export.format.rtf",new Boolean(m_FormatRtf)); *************** *** 445,448 **** --- 459,464 ---- else if (m_FormatXml) exportToXML(); + else if (m_FormatOpml) + exportToOPML(); else if (m_FormatPdf) exportToPDF(); *************** *** 647,655 **** */ private boolean exportToPDF() ! { return false; } /** * Export data in rtf format.Not yet implemented. * @return Always false. --- 663,745 ---- */ private boolean exportToPDF() ! { return false; } /** + * Export data in opml format. + * @return true when no problem is encountered, false otherwise. + */ + private boolean exportToOPML() + { + String str = OSMFile.OSM_XML_PREFACE+"\n"; + str += OSMFile.OSM_OPML_PREFACE+"\n"; + str += OSMFile.getTag1(OSMFile.OSM_OPML_HEAD_TAG)+"\n"; + str += OSMFile.getTag1(OSMFile.OSM_OPML_NAME_TAG)+" "; + str += this.m_File.getName(); + str += OSMFile.getTag2(OSMFile.OSM_OPML_NAME_TAG)+"\n"; + str += OSMFile.getTag1(OSMFile.OSM_OPML_TITLE_TAG)+" "; + str += this.m_Document.getPresentation().getTitle(); + str += OSMFile.getTag2(OSMFile.OSM_OPML_TITLE_TAG)+"\n"; + str += OSMFile.getTag1(OSMFile.OSM_OPML_AUTHOR_TAG)+" "; + str += this.m_Document.getPresentation().getAuthorName(); + str += OSMFile.getTag2(OSMFile.OSM_OPML_AUTHOR_TAG)+"\n"; + str += OSMFile.getTag1(OSMFile.OSM_OPML_DATE_TAG)+" "; + str += this.m_Document.getPresentation().getVersionDate(); + str += OSMFile.getTag2(OSMFile.OSM_OPML_DATE_TAG)+"\n"; + str += OSMFile.getTag2(OSMFile.OSM_OPML_HEAD_TAG)+"\n"; + str += OSMFile.getTag1(OSMFile.OSM_OPML_BODY_TAG)+"\n"; + Enumeration eRoot = m_Document.elements(); + while(eRoot.hasMoreElements()) + { + OSMElement eltRoot = (OSMElement)eRoot.nextElement(); + int lastLevel = -1; + int nbToClose = 0; + Vector v = new Vector(); + v.add(eltRoot); + OSMElement.getSons(eltRoot, v); + for(int k = 0; k < v.size(); k++) + { + OSMElement elt = (OSMElement)v.get(k); + int newLevel = elt.getLevel(); + if(newLevel > lastLevel) + { + str += OSMFile.getTagopml1(OSMFile.OSM_OUTLINE_TAG,transformStringToXMLFormat(elt.getTitle()))+"\n"; + nbToClose++; + } + else if(newLevel == lastLevel) + { + str += OSMFile.getTagopml2(OSMFile.OSM_OUTLINE_TAG) + "\n" + OSMFile.getTagopml1(OSMFile.OSM_OUTLINE_TAG,elt.getTitle())+ "\n"; + } + else + { + int delta = lastLevel - newLevel + 1; + for(int i=0; i < delta; i++) + str += OSMFile.getTagopml2(OSMFile.OSM_OUTLINE_TAG)+ "\n" ; + nbToClose-=delta; + str += OSMFile.getTagopml1(OSMFile.OSM_OUTLINE_TAG,transformStringToXMLFormat(elt.getTitle()))+ "\n" ; + nbToClose++; + } + lastLevel = newLevel; + } + for(int i=0; i < nbToClose; i++) + str += OSMFile.getTagopml2(OSMFile.OSM_OUTLINE_TAG) + "\n"; + } + str += OSMFile.getTagopml2(OSMFile.OSM_OPML_BODY_TAG)+ "\n"; + str += OSMFile.getTagopml2(OSMFile.OSM_OPML_TAG); + try + { + FileOutputStream fos = new FileOutputStream(m_File); + fos.write(str.getBytes(OSMFile.OSM_OPML_ENCODING)); + fos.close(); + return true; + } + catch(Throwable e) + { + return false; + } + } + + /** * Export data in rtf format.Not yet implemented. * @return Always false. |