1717import java .nio .file .Files ;
1818import java .sql .SQLException ;
1919import java .util .Iterator ;
20- import java .util .List ;
2120import java .util .Map ;
2221import java .util .Set ;
2322import java .util .concurrent .ConcurrentHashMap ;
2423
25- import javax .xml .parsers .ParserConfigurationException ;
26-
2724import com .maxprograms .remotetm .utils .Utils ;
2825import com .maxprograms .swordfish .tm .InternalDatabase ;
29- import com .maxprograms .swordfish .tm .Match ;
30- import com .maxprograms .xml .Element ;
31-
32- import org .xml .sax .SAXException ;
3326
3427public class TmManager {
3528
36- static final String MEMORIES = "memories" ;
29+ public static final String MEMORIES = "memories" ;
3730 static final String CLOSED = "Memory is closed" ;
3831
3932 private TmManager () {
@@ -43,16 +36,6 @@ private TmManager() {
4336 private static Map <String , InternalDatabase > databases ;
4437 private static Map <String , Integer > count ;
4538
46- public static int storeTMX (String memory , String tmx , String project , String client , String subject )
47- throws IOException , SQLException , SAXException , ParserConfigurationException {
48- if (!isOpen (memory )) {
49- openMemory (memory );
50- }
51- int imported = databases .get (memory ).storeTMX (tmx , project , client , subject );
52- Files .deleteIfExists (new File (tmx ).toPath ());
53- return imported ;
54- }
55-
5639 public static void createMemory (String memory ) throws SQLException , IOException {
5740 File memoriesFolder = new File (RemoteTM .getWorkFolder (), MEMORIES );
5841 if (!memoriesFolder .exists ()) {
@@ -87,7 +70,7 @@ public static void removeMemory(String memory) throws SQLException, IOException
8770
8871 public static void close (String memory ) throws SQLException , IOException {
8972 if (!isOpen (memory )) {
90- return ;
73+ throw new IOException ( CLOSED ) ;
9174 }
9275 if (databases .containsKey (memory )) {
9376 int users = count .get (memory );
@@ -102,21 +85,7 @@ public static void close(String memory) throws SQLException, IOException {
10285 }
10386 }
10487
105- public static String exportMemory (String memory , String name , Set <String > languages , String srcLang )
106- throws SQLException , IOException {
107- if (!isOpen (memory )) {
108- openMemory (memory );
109- }
110- File tempFolder = new File (RemoteTM .getWorkFolder (), "tmp" );
111- File tmx = new File (tempFolder , name + ".tmx" );
112- if (tmx .exists ()) {
113- Files .delete (tmx .toPath ());
114- }
115- databases .get (memory ).exportMemory (tmx .getAbsolutePath (), languages , srcLang );
116- return tmx .getName ();
117- }
118-
119- public static void openMemory (String memory ) throws SQLException , IOException {
88+ public static void setOpen (String memory ) throws SQLException , IOException {
12089 if (databases == null ) {
12190 databases = new ConcurrentHashMap <>();
12291 count = new ConcurrentHashMap <>();
@@ -141,86 +110,10 @@ public static void closeMemories() throws SQLException, IOException {
141110 }
142111 }
143112
144- public static Set <String > getAllClients (String memory ) throws IOException , SQLException {
145- if (!isOpen (memory )) {
146- openMemory (memory );
147- }
148- return databases .get (memory ).getAllClients ();
149- }
150-
151- public static Set <String > getAllLanguages (String memory ) throws SQLException , IOException {
152- if (!isOpen (memory )) {
153- openMemory (memory );
154- }
155- return databases .get (memory ).getAllLanguages ();
156- }
157-
158- public static Set <String > getAllProjects (String memory ) throws IOException , SQLException {
159- if (!isOpen (memory )) {
160- openMemory (memory );
161- }
162- return databases .get (memory ).getAllProjects ();
163- }
164-
165- public static Set <String > getAllSubjects (String memory ) throws IOException , SQLException {
166- if (!isOpen (memory )) {
167- openMemory (memory );
168- }
169- return databases .get (memory ).getAllSubjects ();
170- }
171-
172- public static void storeTu (String memory , Element tu ) throws SQLException , IOException {
173- if (!isOpen (memory )) {
174- openMemory (memory );
175- }
176- databases .get (memory ).storeTu (tu );
177- }
178-
179- public static Element getTu (String memory , String tuid )
180- throws IOException , SQLException , SAXException , ParserConfigurationException {
181- if (!isOpen (memory )) {
182- openMemory (memory );
183- }
184- return databases .get (memory ).getTu (tuid );
185- }
186-
187- public static void removeTu (String memory , String tuid ) throws IOException , SQLException {
188- if (!isOpen (memory )) {
189- openMemory (memory );
190- }
191- databases .get (memory ).removeTu (tuid );
192- }
193-
194113 public static void commit (String memory ) throws SQLException , IOException {
195114 if (!isOpen (memory )) {
196115 throw new IOException (CLOSED );
197116 }
198117 databases .get (memory ).commit ();
199118 }
200-
201- public static List <Match > searchTranslation (String memory , String searchStr , String srcLang , String tgtLang ,
202- int similarity , boolean caseSensitive )
203- throws IOException , SAXException , ParserConfigurationException , SQLException {
204- if (!isOpen (memory )) {
205- openMemory (memory );
206- }
207- return databases .get (memory ).searchTranslation (searchStr , srcLang , tgtLang , similarity , caseSensitive );
208- }
209-
210- public static List <Element > searchAll (String memory , String searchStr , String srcLang , int similarity ,
211- boolean caseSensitive ) throws IOException , SAXException , ParserConfigurationException , SQLException {
212- if (!isOpen (memory )) {
213- openMemory (memory );
214- }
215- return databases .get (memory ).searchAll (searchStr , srcLang , similarity , caseSensitive );
216- }
217-
218- public static List <Element > concordanceSearch (String memory , String searchStr , String srcLang , int limit ,
219- boolean isRegexp , boolean caseSensitive )
220- throws SQLException , SAXException , IOException , ParserConfigurationException {
221- if (!isOpen (memory )) {
222- openMemory (memory );
223- }
224- return databases .get (memory ).concordanceSearch (searchStr , srcLang , limit , isRegexp , caseSensitive );
225- }
226119}
0 commit comments