PageRenderTime 63ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/patches/pending_history/history.diff

https://github.com/zet/bombus
diff | 919 lines | 885 code | 34 blank | 0 comment | 0 complexity | 5a839aaab4a71c9eb36e52c7210f8c3e MD5 | raw file
  1. Index: trunk/src/Client/Config.java
  2. ===================================================================
  3. --- trunk/src/Client/Config.java (revision 1209)
  4. +++ trunk/src/Client/Config.java (working copy)
  5. @@ -66,7 +66,7 @@
  6. public boolean ghostMotor=getBooleanProperty("moto_e398",false);
  7. public boolean blFlash=!ghostMotor; //true;
  8. - public boolean msgLog=getBooleanProperty("msg_log",false);
  9. + //public boolean msgLog=getBooleanProperty("msg_log",false);
  10. public boolean muc119=getBooleanProperty("muc_119",true); // before muc 1.19 use muc#owner instead of muc#admin
  11. @@ -147,6 +147,14 @@
  12. public int messageCollapsedLength=512;
  13. + public String msgPath="";
  14. + public boolean msgLog=false;
  15. + public boolean msgLogPresence=false;
  16. + public boolean msgLogConf=false;
  17. + public boolean msgLogConfPresence=false;
  18. + public boolean cp1251=true;
  19. + public boolean transliterateFilenames=false;
  20. +
  21. // runtime values
  22. public boolean allowMinimize=false;
  23. public int profile=0;
  24. @@ -154,6 +162,7 @@
  25. public boolean istreamWaiting;
  26. +
  27. // Singleton
  28. private static Config instance;
  29. @@ -287,6 +296,14 @@
  30. eventDelivery=inputStream.readBoolean();
  31. messageCollapsedLength=inputStream.readInt();
  32. +
  33. + msgPath=inputStream.readUTF();
  34. + msgLog=inputStream.readBoolean();
  35. + msgLogPresence=inputStream.readBoolean();
  36. + msgLogConfPresence=inputStream.readBoolean();
  37. + msgLogConf=inputStream.readBoolean();
  38. + cp1251=inputStream.readBoolean();
  39. + transliterateFilenames=inputStream.readBoolean();
  40. inputStream.close();
  41. } catch (Exception e) {
  42. @@ -382,6 +399,14 @@
  43. outputStream.writeBoolean(eventDelivery);
  44. outputStream.writeInt(messageCollapsedLength);
  45. +
  46. + outputStream.writeUTF(msgPath);
  47. + outputStream.writeBoolean(msgLog);
  48. + outputStream.writeBoolean(msgLogPresence);
  49. + outputStream.writeBoolean(msgLogConfPresence);
  50. + outputStream.writeBoolean(msgLogConf);
  51. + outputStream.writeBoolean(cp1251);
  52. + outputStream.writeBoolean(transliterateFilenames);
  53. } catch (Exception e) { e.printStackTrace(); }
  54. Index: trunk/src/Client/Contact.java
  55. ===================================================================
  56. --- trunk/src/Client/Contact.java (revision 1209)
  57. +++ trunk/src/Client/Contact.java (working copy)
  58. @@ -26,6 +26,10 @@
  59. */
  60. package Client;
  61. +//#if FILE_IO && HISTORY
  62. +//# import Client.HistoryAppend;
  63. +//# import Conference.MucContact;
  64. +//#endif
  65. import com.alsutton.jabber.JabberDataBlock;
  66. import images.RosterIcons;
  67. import ui.Colors;
  68. @@ -212,13 +216,13 @@
  69. if (m.isPresence())
  70. if (msgs.size()==1)
  71. if ( ((Msg)msgs.firstElement()).isPresence())
  72. - if (origin!=ORIGIN_GROUPCHAT) first_replace=true;
  73. -//#if USE_SIEMENS_FILES
  74. + if (origin!=ORIGIN_GROUPCHAT) first_replace=true;
  75. +//#if FILE_IO && HISTORY
  76. //# Config cf=Config.getInstance();
  77. -//#
  78. -//# if (cf.msgLog && group.index!=Groups.TYPE_TRANSP && group.index!=Groups.TYPE_SEARCH_RESULT)
  79. +//# if (cf.msgLog && cf.msgPath==null) {
  80. +//# } else
  81. +//# if (cf.msgLog && group.index!=Groups.TYPE_TRANSP && group.index!=Groups.TYPE_SEARCH_RESULT)
  82. //# {
  83. -//# String histRecord=(nick==null)?getBareJid():nick;
  84. //# String fromName=StaticData.getInstance().account.getUserName();
  85. //# if (m.messageType!=Msg.MESSAGE_TYPE_OUT) fromName=toString();
  86. //# boolean allowLog=false;
  87. @@ -231,8 +235,9 @@
  88. //# if (origin>=ORIGIN_GROUPCHAT && cf.msgLogConf) allowLog=true;
  89. //# if (origin<ORIGIN_GROUPCHAT) allowLog=true;
  90. //# }
  91. +//# if (origin!=ORIGIN_GROUPCHAT && this instanceof MucContact)
  92. +//# allowLog=false;
  93. //# if (allowLog)
  94. -//# //if (!first_replace || !m.)
  95. //# {
  96. //# StringBuffer body=new StringBuffer(m.getDayTime());
  97. //# body.append(" <");
  98. @@ -244,9 +249,12 @@
  99. //# }
  100. //# body.append(m.getBody());
  101. //# body.append("\r\n");
  102. -//# io.NvStorage.appendFile("Log_"+histRecord, body.toString());
  103. +//#
  104. +//# String histRecord=(nick==null)?getBareJid():nick;
  105. +//#
  106. +//# new HistoryAppend(body, histRecord);
  107. //# }
  108. -//# }
  109. +//# }
  110. //#endif
  111. if (first_replace) {
  112. msgs.setElementAt(m,0);
  113. Index: trunk/src/Client/HistoryAppend.java
  114. ===================================================================
  115. --- trunk/src/Client/HistoryAppend.java (revision 0)
  116. +++ trunk/src/Client/HistoryAppend.java (revision 0)
  117. @@ -0,0 +1,82 @@
  118. +/*
  119. + * HistoryAppend.java
  120. + *
  121. + * Created on 19.06.2007, 9:24
  122. + * Copyright (c) 2006-2007, Daniel Apatin (ad), http://apatin.net.ru
  123. + * This program is free software; you can redistribute it and/or
  124. + * modify it under the terms of the GNU General Public License
  125. + * as published by the Free Software Foundation; either version 2
  126. + * of the License, or (at your option) any later version.
  127. + *
  128. + * You can also redistribute and/or modify this program under the
  129. + * terms of the Psi License, specified in the accompanied COPYING
  130. + * file, as published by the Psi Project; either dated January 1st,
  131. + * 2005, or (at your option) any later version.
  132. + *
  133. + * This program is distributed in the hope that it will be useful,
  134. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  135. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  136. + * GNU General Public License for more details.
  137. + *
  138. + * You should have received a copy of the GNU General Public License
  139. + * along with this library; if not, write to the Free Software
  140. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  141. + *
  142. + */
  143. +
  144. +package Client;
  145. +
  146. +import Client.Config;
  147. +import io.file.FileIO;
  148. +import java.io.IOException;
  149. +import java.io.OutputStream;
  150. +//#ifdef TRANSLIT
  151. +//# import util.Translit;
  152. +//#endif
  153. +import util.strconv;
  154. +
  155. +public class HistoryAppend {
  156. +
  157. + private Config cf=Config.getInstance();
  158. +
  159. +
  160. +//#if FILE_IO
  161. + private int filePos;
  162. + private FileIO file;
  163. + private OutputStream os;
  164. +//#endif
  165. +
  166. + public HistoryAppend(StringBuffer body, String histRecord) {
  167. +
  168. + byte[] bodyMessage;
  169. +
  170. + if (cf.cp1251) {
  171. + bodyMessage=strconv.convUnicodeToCp1251(body.toString()).getBytes();
  172. + } else {
  173. + bodyMessage=body.toString().getBytes();
  174. + }
  175. +//#ifdef TRANSLIT
  176. +//# String filename=cf.msgPath+((cf.transliterateFilenames)?Translit.translit(histRecord):histRecord)+".txt";
  177. +//#else
  178. + String filename=cf.msgPath+histRecord+".txt";
  179. +//#endif
  180. + file=FileIO.createConnection(filename);
  181. + try {
  182. + os = file.openOutputStream(0);
  183. + try {
  184. + os.write(bodyMessage);
  185. + filePos+=bodyMessage.length;
  186. + } catch (IOException ex) { }
  187. + os.close();
  188. + os.flush();
  189. + file.close();
  190. + } catch (IOException ex) {
  191. + try {
  192. + file.close();
  193. + } catch (IOException ex2) { }
  194. + }
  195. + filename=null;
  196. + body=null;
  197. + bodyMessage=null;
  198. + }
  199. +}
  200. \ No newline at end of file
  201. Index: trunk/src/Client/HistoryConfig.java
  202. ===================================================================
  203. --- trunk/src/Client/HistoryConfig.java (revision 0)
  204. +++ trunk/src/Client/HistoryConfig.java (revision 0)
  205. @@ -0,0 +1,155 @@
  206. +/*
  207. + * HistoryConfig.java
  208. + *
  209. + * Created on 18.06.2007., 15:35
  210. + * Copyright (c) 2006-2007, Daniel Apatin (ad), http://apatin.net.ru
  211. + * This program is free software; you can redistribute it and/or
  212. + * modify it under the terms of the GNU General Public License
  213. + * as published by the Free Software Foundation; either version 2
  214. + * of the License, or (at your option) any later version.
  215. + *
  216. + * You can also redistribute and/or modify this program under the
  217. + * terms of the Psi License, specified in the accompanied COPYING
  218. + * file, as published by the Psi Project; either dated January 1st,
  219. + * 2005, or (at your option) any later version.
  220. + *
  221. + * This program is distributed in the hope that it will be useful,
  222. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  223. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  224. + * GNU General Public License for more details.
  225. + *
  226. + * You should have received a copy of the GNU General Public License
  227. + * along with this library; if not, write to the Free Software
  228. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  229. + *
  230. + */
  231. +
  232. +package Client;
  233. +
  234. +import Client.Config;
  235. +import Client.StaticData;
  236. +//#if FILE_IO
  237. +import io.file.browse.Browser;
  238. +import io.file.browse.BrowserListener;
  239. +//#endif
  240. +import javax.microedition.lcdui.*;
  241. +import locale.SR;
  242. +import ui.controls.TextFieldCombo;
  243. +
  244. +public class HistoryConfig implements
  245. + CommandListener
  246. +//#if FILE_IO
  247. + ,ItemCommandListener
  248. + , BrowserListener
  249. +//#endif
  250. +{
  251. + private Display display;
  252. + private Displayable parentView;
  253. +
  254. + Form f;
  255. +//#if FILE_IO
  256. + ChoiceGroup history;
  257. + TextField historyFolder;
  258. +
  259. + Command cmdSetHistFolder=new Command(SR.MS_SELECT_PATH, Command.ITEM,11);
  260. +//#endif
  261. +
  262. + Command cmdOk=new Command(SR.MS_OK,Command.OK,1);
  263. + Command cmdCancel=new Command(SR.MS_CANCEL, Command.BACK,99);
  264. +
  265. + Config cf;
  266. + boolean his[];
  267. +
  268. + /** Creates a new instance of ConfigForm */
  269. + public HistoryConfig(Display display) {
  270. + this.display=display;
  271. + parentView=display.getCurrent();
  272. +
  273. + cf=Config.getInstance();
  274. +
  275. + f=new Form(SR.MS_HISTORY_SETTINGS);
  276. +
  277. +//#if FILE_IO
  278. + history=new ChoiceGroup(SR.MS_HISTORY, Choice.MULTIPLE); //locale
  279. + history.append(SR.MS_SAVE_HISTORY, null); //locale
  280. + history.append(SR.MS_SAVE_PRESENCES,null); //locale
  281. + history.append(SR.MS_SAVE_HISTORY_CONF, null); //locale
  282. + history.append(SR.MS_SAVE_PRESENCES_CONF, null); //locale
  283. + history.append(SR.MS_1251_CORRECTION, null); //locale
  284. +//#ifdef TRANSLIT
  285. +//# history.append(SR.MS_1251_TRANSLITERATE_FILENAMES, null); //locale
  286. +//#endif
  287. +
  288. + boolean his[]={
  289. + cf.msgLog,
  290. + cf.msgLogPresence,
  291. + cf.msgLogConf,
  292. + cf.msgLogConfPresence,
  293. + cf.cp1251
  294. +//#ifdef TRANSLIT
  295. +//# , cf.transliterateFilenames
  296. +//#endif
  297. + };
  298. + this.his=his;
  299. +
  300. + history.setSelectedFlags(his);
  301. + f.append(history);
  302. +
  303. + historyFolder=new TextFieldCombo(SR.MS_HISTORY_PATH, null, 128, 0, "history_path", display);
  304. + historyFolder.setString(cf.msgPath);
  305. + historyFolder.addCommand(cmdSetHistFolder);
  306. + f.append(historyFolder);
  307. + historyFolder.setItemCommandListener(this);
  308. +//#endif
  309. +
  310. + f.addCommand(cmdOk);
  311. + f.addCommand(cmdCancel);
  312. +
  313. + f.setCommandListener(this);
  314. +
  315. + display.setCurrent(f);
  316. + }
  317. +
  318. + public void commandAction(Command c, Displayable d) {
  319. + if (c==cmdOk) {
  320. +//#if FILE_IO
  321. + history.getSelectedFlags(his);
  322. + cf.msgLog=his[0];
  323. + cf.msgLogPresence=his[1];
  324. + cf.msgLogConf=his[2];
  325. + cf.msgLogConfPresence=his[3];
  326. + cf.cp1251=his[4];
  327. +//#ifdef TRANSLIT
  328. +//# cf.transliterateFilenames=his[5];
  329. +//#endif
  330. + cf.msgPath=historyFolder.getString();
  331. +//#endif
  332. +
  333. + cf.saveToStorage();
  334. +
  335. + StaticData.getInstance().roster.reEnumRoster();
  336. + destroyView();
  337. + }
  338. + if (c==cmdCancel) destroyView();
  339. + }
  340. +
  341. +//#if FILE_IO
  342. + public void commandAction(Command command, Item item) {
  343. +
  344. + if (command==cmdSetHistFolder) {
  345. + new Browser(null, display, this, true);
  346. + }
  347. + }
  348. +//#endif
  349. +
  350. + public void destroyView(){
  351. + if (display!=null)
  352. + display.setCurrent(parentView);
  353. + }
  354. +
  355. +//#if FILE_IO
  356. + public void BrowserFilePathNotify(String pathSelected) {
  357. + historyFolder.setString(pathSelected);
  358. + }
  359. +//#endif
  360. +}
  361. \ No newline at end of file
  362. Index: trunk/src/Client/RosterToolsMenu.java
  363. ===================================================================
  364. --- trunk/src/Client/RosterToolsMenu.java (revision 1209)
  365. +++ trunk/src/Client/RosterToolsMenu.java (working copy)
  366. @@ -56,8 +56,10 @@
  367. addItem(SR.MS_ROOT, 4);
  368. addItem(SR.MS_FILE_TRANSFERS, 5);
  369. //#endif
  370. +//#if (FILE_IO && HISTORY)
  371. +//# addItem(SR.MS_HISTORY_SETTINGS, 6);
  372. +//#endif
  373. -
  374. /*addItem("Break connection", 10);*/
  375. @@ -97,6 +99,11 @@
  376. new io.file.transfer.TransferManager(display);
  377. return;
  378. //#endif
  379. +//#if (FILE_IO && HISTORY)
  380. +//# case 6: //history
  381. +//# new HistoryConfig(display);
  382. +//# return;
  383. +//#endif
  384. //case 10:
  385. // StaticData.getInstance().roster.connectionTerminated(new Exception("Simulated break"));
  386. Index: trunk/src/io/file/FileComMotorolaIo.java
  387. ===================================================================
  388. --- trunk/src/io/file/FileComMotorolaIo.java (revision 1209)
  389. +++ trunk/src/io/file/FileComMotorolaIo.java (working copy)
  390. @@ -61,6 +61,12 @@
  391. }
  392. return fileConnection.openOutputStream();
  393. }
  394. +
  395. + public OutputStream openOutputStream(long pos_eof) throws IOException {
  396. + if (fileConnection==null) openFile();
  397. + if (!fileConnection.exists()) fileConnection.create();
  398. + return fileConnection.openOutputStream();
  399. + }
  400. public InputStream openInputStream() throws IOException {
  401. if (fileConnection==null) openFile();
  402. @@ -91,10 +97,14 @@
  403. Vector rd=new Vector(list.length + 1);
  404. for (int i = 0; i < list.length; i++) {
  405. - if (directoriesOnly & !list[i].endsWith("/")) continue;
  406. - int st=(list[i].startsWith("/")) ? 1 : 0;
  407. + if (directoriesOnly & !list[i].endsWith("/")) continue;
  408. + int st=(list[i].startsWith("/")) ? 1 : 0;
  409. rd.addElement(list[i].substring(st+fileName.length()));
  410. }
  411. return rd;
  412. }
  413. +
  414. + public void delete() throws IOException{
  415. + fileConnection.delete();
  416. + }
  417. }
  418. Index: trunk/src/io/file/FileIO.java
  419. ===================================================================
  420. --- trunk/src/io/file/FileIO.java (revision 1209)
  421. +++ trunk/src/io/file/FileIO.java (working copy)
  422. @@ -90,8 +90,13 @@
  423. public abstract void close() throws IOException;
  424. + public abstract void delete() throws IOException;
  425. +
  426. public abstract long fileSize() throws IOException;
  427. protected abstract Vector rootDirs();
  428. +
  429. protected abstract Vector dirs(boolean directoriesOnly) throws IOException;
  430. +
  431. + public abstract OutputStream openOutputStream(long pos_eof) throws IOException;
  432. }
  433. Index: trunk/src/io/file/FileJSR75.java
  434. ===================================================================
  435. --- trunk/src/io/file/FileJSR75.java (revision 1209)
  436. +++ trunk/src/io/file/FileJSR75.java (working copy)
  437. @@ -60,7 +60,19 @@
  438. }
  439. return fileConnection.openOutputStream();
  440. }
  441. +
  442. + public void delete() throws IOException{
  443. + if (fileConnection==null) openFile();
  444. + fileConnection.delete();
  445. + }
  446. + public OutputStream openOutputStream(long pos_eof) throws IOException {
  447. + if (fileConnection==null) openFile();
  448. + if (!fileConnection.exists()) fileConnection.create();
  449. + pos_eof=fileConnection.fileSize();
  450. + return fileConnection.openOutputStream(pos_eof);
  451. + }
  452. +
  453. public InputStream openInputStream() throws IOException{
  454. if (fileConnection==null) openFile();
  455. return fileConnection.openInputStream();
  456. Index: trunk/src/io/file/FileSiemens.java
  457. ===================================================================
  458. --- trunk/src/io/file/FileSiemens.java (revision 1209)
  459. +++ trunk/src/io/file/FileSiemens.java (working copy)
  460. @@ -34,14 +34,12 @@
  461. import java.io.OutputStream;
  462. import java.util.Vector;
  463. -public class FileSiemens extends FileIO{
  464. +public class FileSiemens extends FileIO {
  465. private File f;
  466. private int fd;
  467. public FileSiemens(String fileName) {
  468. - //System.out.println("Siemens fs accessor for "+fileName);
  469. - // Siemens requires backslashes
  470. this.fileName=fileName=fileName.replace('/', '\\');//.substring(1);
  471. }
  472. @@ -63,9 +61,6 @@
  473. //System.out.println("Siemens root");
  474. Vector rd = new Vector();
  475. rd.addElement("0:/");
  476. - rd.addElement("1:/");
  477. - rd.addElement("2:/");
  478. - rd.addElement("3:/");
  479. rd.addElement("4:/");
  480. return rd;
  481. }
  482. @@ -89,13 +84,22 @@
  483. public OutputStream openOutputStream() throws IOException {
  484. openFile();
  485. - return new FileSiemensOutputStream(f, fd);
  486. + return new FileSiemensOutputStream(f, fd, 0);
  487. }
  488. public InputStream openInputStream() throws IOException {
  489. openFile();
  490. return new FileSiemensInputStream(f, fd);
  491. - }
  492. + }
  493. +
  494. + public OutputStream openOutputStream(long pos_eof) throws IOException {
  495. + openFile();
  496. + return new FileSiemensOutputStream(f, fd, pos_eof);
  497. + }
  498. +
  499. + public void delete() throws IOException{
  500. + f.delete(fileName);
  501. + }
  502. }
  503. class FileSiemensInputStream extends InputStream {
  504. @@ -121,8 +125,14 @@
  505. private int fileDescriptor;
  506. private File f;
  507. - public FileSiemensOutputStream(File f, int fd) {
  508. - this.f=f; this.fileDescriptor=fd;
  509. + public FileSiemensOutputStream(File f, int fd, long Seek) {
  510. + this.f=f;
  511. + this.fileDescriptor=fd;
  512. + try {
  513. + this.f.seek(fd, f.length(fd));
  514. + } catch (IOException ex) {
  515. + ex.printStackTrace();
  516. + }
  517. }
  518. public void write(int i) throws IOException {
  519. Index: trunk/src/locale/SR.java
  520. ===================================================================
  521. --- trunk/src/locale/SR.java (revision 1209)
  522. +++ trunk/src/locale/SR.java (working copy)
  523. @@ -124,7 +124,7 @@
  524. public static String MS_HEAP_MONITOR = loadString( "heap monitor" );
  525. public static String MS_MESSAGE = loadString( "Message" );
  526. public static String MS_OTHER = loadString( "<Other>" );
  527. - public static String MS_HISTORY = loadString( "history -" );
  528. + public static String MS_HISTORY = loadString( "History" );
  529. public static String MS_APPEND = loadString( "Append" );
  530. public static String MS_ACTIVE_CONTACTS = loadString( "Active Contacts" );
  531. public static String MS_SELECT_NICKNAME = loadString( "Select nickname" );
  532. @@ -341,6 +341,17 @@
  533. public static String MS_SAVE_TO = loadString( "Save to" );
  534. public static String MS_SENDER = loadString( "Sender:" );
  535. public static String MS_FILE_SIZE = loadString( "size:" );
  536. +
  537. + public static String MS_HISTORY_SETTINGS = loadString( "History settings" );
  538. + public static String MS_HISTORY_PATH = loadString( "History path" );
  539. + public static String MS_1251_CORRECTION = loadString( "1251 correction" );
  540. + public static String MS_SAVE_PRESENCES_CONF = loadString( "save conf presences" );
  541. + public static String MS_SAVE_HISTORY_CONF = loadString( "save conf history" );
  542. + public static String MS_SAVE_PRESENCES = loadString( "save presences" );
  543. + public static String MS_SAVE_HISTORY = loadString( "save history" );
  544. + public static String MS_SELECT_PATH = loadString( "Select path" );
  545. + public static String MS_1251_TRANSLITERATE_FILENAMES = loadString( "transliterate filenames" );
  546. +
  547. public static String MS_XMLLANG;
  548. public static String MS_IFACELANG;
  549. Index: trunk/src/util/Translit.java
  550. ===================================================================
  551. --- trunk/src/util/Translit.java (revision 0)
  552. +++ trunk/src/util/Translit.java (revision 0)
  553. @@ -0,0 +1,332 @@
  554. +/*
  555. + * Translit.java
  556. + *
  557. + * Created on 25.04.2007, 10:30
  558. + *
  559. + * Copyright (c) 2006-2007, Daniel Apatin (ad), http://apatin.net.ru
  560. + *
  561. + * This program is free software; you can redistribute it and/or
  562. + * modify it under the terms of the GNU General Public License
  563. + * as published by the Free Software Foundation; either version 2
  564. + * of the License, or (at your option) any later version.
  565. + *
  566. + * You can also redistribute and/or modify this program under the
  567. + * terms of the Psi License, specified in the accompanied COPYING
  568. + * file, as published by the Psi Project; either dated January 1st,
  569. + * 2005, or (at your option) any later version.
  570. + *
  571. + * This program is distributed in the hope that it will be useful,
  572. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  573. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  574. + * GNU General Public License for more details.
  575. + *
  576. + * You should have received a copy of the GNU General Public License
  577. + * along with this library; if not, write to the Free Software
  578. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  579. + */
  580. +
  581. +package util;
  582. +
  583. +public class Translit {
  584. +
  585. + static char Translit_chars[][] = new char[106][6];
  586. + static int Translit_count[] = new int[106];
  587. + static boolean full=false;
  588. +
  589. + static void fillarrays()
  590. + {
  591. + int i = 40;
  592. + int j = 0;
  593. + Translit_chars[i] = "A".toCharArray();
  594. + Translit_count[i] = 1;
  595. + j++;
  596. + i++;
  597. + Translit_chars[i] = "B".toCharArray();
  598. + Translit_count[i] = 1;
  599. + j++;
  600. + i++;
  601. + Translit_chars[i] = "V".toCharArray();
  602. + Translit_count[i] = 1;
  603. + j++;
  604. + i++;
  605. + Translit_chars[i] = "G".toCharArray();
  606. + Translit_count[i] = 1;
  607. + j++;
  608. + i++;
  609. + Translit_chars[i] = "D".toCharArray();
  610. + Translit_count[i] = 1;
  611. + j++;
  612. + i++;
  613. + Translit_chars[i] = "E".toCharArray();
  614. + Translit_count[i] = 1;
  615. + j++;
  616. + i++;
  617. + Translit_chars[25] = "Yo".toCharArray();
  618. + Translit_count[25] = 2;
  619. + j++;
  620. + Translit_chars[i] = "Zh".toCharArray();
  621. + Translit_count[i] = 2;
  622. + j++;
  623. + i++;
  624. + Translit_chars[i] = "Z".toCharArray();
  625. + Translit_count[i] = 1;
  626. + j++;
  627. + i++;
  628. + Translit_chars[i] = "I".toCharArray();
  629. + Translit_count[i] = 1;
  630. + j++;
  631. + i++;
  632. + Translit_chars[i] = "J".toCharArray();
  633. + Translit_count[i] = 1;
  634. + j++;
  635. + i++;
  636. + Translit_chars[i] = "K".toCharArray();
  637. + Translit_count[i] = 1;
  638. + j++;
  639. + i++;
  640. + Translit_chars[i] = "L".toCharArray();
  641. + Translit_count[i] = 1;
  642. + j++;
  643. + i++;
  644. + Translit_chars[i] = "M".toCharArray();
  645. + Translit_count[i] = 1;
  646. + j++;
  647. + i++;
  648. + Translit_chars[i] = "N".toCharArray();
  649. + Translit_count[i] = 1;
  650. + j++;
  651. + i++;
  652. + Translit_chars[i] = "O".toCharArray();
  653. + Translit_count[i] = 1;
  654. + j++;
  655. + i++;
  656. + Translit_chars[i] = "P".toCharArray();
  657. + Translit_count[i] = 1;
  658. + j++;
  659. + i++;
  660. + Translit_chars[i] = "R".toCharArray();
  661. + Translit_count[i] = 1;
  662. + j++;
  663. + i++;
  664. + Translit_chars[i] = "S".toCharArray();
  665. + Translit_count[i] = 1;
  666. + j++;
  667. + i++;
  668. + Translit_chars[i] = "T".toCharArray();
  669. + Translit_count[i] = 1;
  670. + j++;
  671. + i++;
  672. + Translit_chars[i] = "U".toCharArray();
  673. + Translit_count[i] = 1;
  674. + j++;
  675. + i++;
  676. + Translit_chars[i] = "F".toCharArray();
  677. + Translit_count[i] = 1;
  678. + j++;
  679. + i++;
  680. + Translit_chars[i] = "H".toCharArray();
  681. + Translit_count[i] = 1;
  682. + j++;
  683. + i++;
  684. + Translit_chars[i] = "C".toCharArray();
  685. + Translit_count[i] = 1;
  686. + j++;
  687. + i++;
  688. + Translit_chars[i] = "Ch".toCharArray();
  689. + Translit_count[i] = 2;
  690. + j++;
  691. + i++;
  692. + Translit_chars[i] = "Sh".toCharArray();
  693. + Translit_count[i] = 2;
  694. + j++;
  695. + i++;
  696. + Translit_chars[i] = "Sch".toCharArray();
  697. + Translit_count[i] = 3;
  698. + j++;
  699. + i++;
  700. + Translit_chars[i] = "\"".toCharArray();
  701. + Translit_count[i] = 1;
  702. + j++;
  703. + i++;
  704. + Translit_chars[i] = "Y".toCharArray();
  705. + Translit_count[i] = 1;
  706. + j++;
  707. + i++;
  708. + Translit_chars[i] = "'".toCharArray();
  709. + Translit_count[i] = 1;
  710. + j++;
  711. + i++;
  712. + Translit_chars[i] = "E".toCharArray();
  713. + Translit_count[i] = 1;
  714. + j++;
  715. + i++;
  716. + Translit_chars[i] = "Yu".toCharArray();
  717. + Translit_count[i] = 2;
  718. + j++;
  719. + i++;
  720. + Translit_chars[i] = "Ya".toCharArray();
  721. + Translit_count[i] = 2;
  722. + j++;
  723. + i++;
  724. + Translit_chars[i] = "a".toCharArray();
  725. + Translit_count[i] = 1;
  726. + j++;
  727. + i++;
  728. + Translit_chars[i] = "b".toCharArray();
  729. + Translit_count[i] = 1;
  730. + j++;
  731. + i++;
  732. + Translit_chars[i] = "v".toCharArray();
  733. + Translit_count[i] = 1;
  734. + j++;
  735. + i++;
  736. + Translit_chars[i] = "g".toCharArray();
  737. + Translit_count[i] = 1;
  738. + j++;
  739. + i++;
  740. + Translit_chars[i] = "d".toCharArray();
  741. + Translit_count[i] = 1;
  742. + j++;
  743. + i++;
  744. + Translit_chars[i] = "e".toCharArray();
  745. + Translit_count[i] = 1;
  746. + j++;
  747. + i++;
  748. + Translit_chars[105] = "yo".toCharArray();
  749. + Translit_count[105] = 2;
  750. + j++;
  751. + Translit_chars[i] = "zh".toCharArray();
  752. + Translit_count[i] = 2;
  753. + j++;
  754. + i++;
  755. + Translit_chars[i] = "z".toCharArray();
  756. + Translit_count[i] = 1;
  757. + j++;
  758. + i++;
  759. + Translit_chars[i] = "i".toCharArray();
  760. + Translit_count[i] = 1;
  761. + j++;
  762. + i++;
  763. + Translit_chars[i] = "j".toCharArray();
  764. + Translit_count[i] = 1;
  765. + j++;
  766. + i++;
  767. + Translit_chars[i] = "k".toCharArray();
  768. + Translit_count[i] = 1;
  769. + j++;
  770. + i++;
  771. + Translit_chars[i] = "l".toCharArray();
  772. + Translit_count[i] = 1;
  773. + j++;
  774. + i++;
  775. + Translit_chars[i] = "m".toCharArray();
  776. + Translit_count[i] = 1;
  777. + j++;
  778. + i++;
  779. + Translit_chars[i] = "n".toCharArray();
  780. + Translit_count[i] = 1;
  781. + j++;
  782. + i++;
  783. + Translit_chars[i] = "o".toCharArray();
  784. + Translit_count[i] = 1;
  785. + j++;
  786. + i++;
  787. + Translit_chars[i] = "p".toCharArray();
  788. + Translit_count[i] = 1;
  789. + j++;
  790. + i++;
  791. + Translit_chars[i] = "r".toCharArray();
  792. + Translit_count[i] = 1;
  793. + j++;
  794. + i++;
  795. + Translit_chars[i] = "s".toCharArray();
  796. + Translit_count[i] = 1;
  797. + j++;
  798. + i++;
  799. + Translit_chars[i] = "t".toCharArray();
  800. + Translit_count[i] = 1;
  801. + j++;
  802. + i++;
  803. + Translit_chars[i] = "u".toCharArray();
  804. + Translit_count[i] = 1;
  805. + j++;
  806. + i++;
  807. + Translit_chars[i] = "f".toCharArray();
  808. + Translit_count[i] = 1;
  809. + j++;
  810. + i++;
  811. + Translit_chars[i] = "h".toCharArray();
  812. + Translit_count[i] = 1;
  813. + j++;
  814. + i++;
  815. + Translit_chars[i] = "c".toCharArray();
  816. + Translit_count[i] = 1;
  817. + j++;
  818. + i++;
  819. + Translit_chars[i] = "ch".toCharArray();
  820. + Translit_count[i] = 2;
  821. + j++;
  822. + i++;
  823. + Translit_chars[i] = "sh".toCharArray();
  824. + Translit_count[i] = 2;
  825. + j++;
  826. + i++;
  827. + Translit_chars[i] = "sch".toCharArray();
  828. + Translit_count[i] = 3;
  829. + j++;
  830. + i++;
  831. + Translit_chars[i] = "\"".toCharArray();
  832. + Translit_count[i] = 1;
  833. + j++;
  834. + i++;
  835. + Translit_chars[i] = "y".toCharArray();
  836. + Translit_count[i] = 1;
  837. + j++;
  838. + i++;
  839. + Translit_chars[i] = "'".toCharArray();
  840. + Translit_count[i] = 1;
  841. + j++;
  842. + i++;
  843. + Translit_chars[i] = "e".toCharArray();
  844. + Translit_count[i] = 1;
  845. + j++;
  846. + i++;
  847. + Translit_chars[i] = "yu".toCharArray();
  848. + Translit_count[i] = 2;
  849. + j++;
  850. + i++;
  851. + Translit_chars[i] = "ya".toCharArray();
  852. + Translit_count[i] = 2;
  853. + j++;
  854. + i++;
  855. + }
  856. +
  857. + public static String translit(String s)
  858. + {
  859. + if (!full) fillarrays();
  860. + char ac[] = new char[s.length() * 3];
  861. + char ac1[] = s.toCharArray();
  862. + int l = -1;
  863. + for(int i = 0; i <= s.length() - 1; i++)
  864. + {
  865. + char c = ac1[i];
  866. + if((c >= '\u0410') & (c <= '\u044F') || (c == '\u0401' || c == '\u0451'))
  867. + {
  868. + int k = c - 1000;
  869. + for(int j = 0; j < Translit_count[k]; j++)
  870. + {
  871. + l++;
  872. + ac[l] = Translit_chars[c - 1000][j];
  873. + }
  874. +
  875. + } else
  876. + {
  877. + l++;
  878. + ac[l] = ac1[i];
  879. + }
  880. + }
  881. +
  882. + return new String(ac, 0, l + 1);
  883. + }
  884. +
  885. +}