Revision 986

View differences:

org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/DefaultScriptingHelpManager.java
1
package org.gvsig.scripting.impl;
2

  
3
import org.gvsig.scripting.HelpConfig;
4
import java.io.BufferedReader;
5
import java.io.File;
6
import java.io.FileNotFoundException;
7
import java.io.FileReader;
8
import java.io.IOException;
9
import java.io.Reader;
10
import java.io.Writer;
11
import java.net.MalformedURLException;
12
import java.net.URISyntaxException;
13
import java.net.URL;
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.HashMap;
17
import java.util.HashSet;
18
import java.util.Iterator;
19
import java.util.List;
20
import java.util.Map;
21
import java.util.Set;
22
import java.util.logging.Level;
23
import javax.help.HelpSet;
24
import javax.help.HelpSetException;
25
import org.apache.commons.io.FileUtils;
26
import org.apache.commons.io.FilenameUtils;
27
import org.apache.commons.io.IOUtils;
28
import org.gvsig.scripting.ScriptingHelpManager;
29
import org.gvsig.scripting.ScriptingManager;
30
import org.gvsig.tools.task.SimpleTaskStatus;
31
import org.slf4j.Logger;
32
import org.slf4j.LoggerFactory;
33

  
34
public class DefaultScriptingHelpManager implements ScriptingHelpManager {
35

  
36
    protected static final Logger logger = LoggerFactory.getLogger(DefaultScriptingHelpManager.class);
37

  
38
    private ScriptingManager manager;
39

  
40
    protected HelpSet helpSet = null;
41
    protected IndexerHelper indexer;
42
    protected MethodList methodsList;
43
    protected List<File> helpRoots = null;
44

  
45
    public DefaultScriptingHelpManager(ScriptingManager manager) {
46
        this.manager = manager;
47
        this.methodsList = new MethodList();
48
    }
49

  
50
    private void initializeHelpSet() {
51
        HelpSet helpSet = null;
52
        File f = new File(this.manager.getHomeFolder(), "help");
53
        if (!f.exists()) {
54
            try {
55
                FileUtils.forceMkdir(f);
56
            } catch (IOException ex) {
57
                logger.warn("Can't create help folder in '" + f.getAbsolutePath() + "'.", ex);
58
            }
59
        }
60
        ClassLoader loader = this.getClass().getClassLoader();
61
        URL resource = loader.getResource("org/gvsig/scripting/apihelp/api.hs");
62
        if (resource == null) {
63
            logger.info("Can't initialize help framework. Can't find 'api.hs'.");
64
        } else {
65
            try {
66
                helpSet = new HelpSet(loader, resource);
67
            } catch (HelpSetException e) {
68
                logger.info("Can't initialize help framework, can't create HelpSet from '" + resource.toString() + "'.", e);
69
            }
70
        }
71
        this.helpSet = helpSet;
72
        loadHelps();
73
    }
74

  
75
    public void loadHelps() {
76
//        HelpConfig helpConfig = new DefaultHelpConfig();
77
        List<File> folders = this.getHelpRoots();
78
        for (File folder : folders) {
79
            File[] helpFolders = folder.listFiles();
80
            for (File helpFolder : helpFolders) {
81
                HelpSet helpset = loadHelp(helpFolder);
82
                if (helpset != null) {
83
                    this.getHelpSet().add(helpset);
84
                }
85
            }
86
        }
87
    }
88

  
89
    public URL makeURL(File helpsetfolder, URL sourceurl) {
90
        if( sourceurl==null ) {
91
            return null;
92
        }
93
        URL url ;
94
        HelpConfig helpConfig = new DefaultHelpConfig();
95
        if (helpsetfolder == null) {
96
            List<File> folders = this.getHelpRoots();
97
            for (File folder : folders) {
98
                File[] helpFolders = folder.listFiles();
99
                for (File helpFolder : helpFolders) {
100
                    if( helpConfig.exists(helpFolder) ) {
101
                        if( helpConfig.load(helpFolder) ) {
102
                            ClassLoader loader = helpConfig.getLoader();
103
                            url = loader.getResource(sourceurl.getPath().substring(1));
104
                            if( url != null ) {
105
                                return url;
106
                            }
107
                        }
108
                    }
109
                }
110
            }
111
        } else {
112
            if( helpConfig.load(helpsetfolder) ) {
113
                ClassLoader loader = helpConfig.getLoader();
114
                url = loader.getResource(sourceurl.getPath());
115
                if( url != null ) {
116
                    return url;
117
                }
118
                if( sourceurl.getPath().startsWith(helpsetfolder.getPath()) ) {
119
                    int n = helpsetfolder.getPath().length()+1;
120
                    url = loader.getResource(sourceurl.getPath().substring(n));
121
                    if( url != null ) {
122
                        return url;
123
                    }
124
                }
125
            }
126
        }
127
        return sourceurl;
128
    }    
129
    
130
    private HelpSet loadHelp(File folder) {
131
        HelpConfig helpConfig = new DefaultHelpConfig();
132

  
133
        if (!helpConfig.exists(folder)) {
134
            return null;
135
        }
136
        if (!helpConfig.load(folder)) {
137
            logger.warn("Can't load help from folder '"+folder.getAbsolutePath()+"'.");
138
            return null;
139
        }
140

  
141
        File helpindex = helpConfig.getHelpIndex();
142
        if (helpindex != null) {
143
            this.methodsList.addMethods(helpindex);
144
        }
145
        HelpSet helpset = helpConfig.createHelpSet();
146
        return helpset;
147
    }
148

  
149
    public void reloadHelp() {
150
        this.helpSet = null;
151
        this.initializeHelpSet();
152
    }
153

  
154
    @Override
155
    public boolean existsHelp(String name) {
156
        HelpConfig helpConfig = new DefaultHelpConfig();
157
        List<File> folders = this.getHelpRoots();
158
        for (File folder : folders) {
159
            if (helpConfig.exists(FileUtils.getFile(folder,name))) {
160
                return true;
161
            }
162
        }
163
        return false;
164
    }
165

  
166
    @Override
167
    public boolean removeHelp(String name) {
168
        HelpConfig helpConfig = new DefaultHelpConfig();
169
        List<File> folders = this.getHelpRoots();
170
        for (File folder : folders) {
171
            if (helpConfig.exists(folder)) {
172
                try {
173
                    FileUtils.forceDelete(folder);
174
                    return true;
175
                } catch (IOException ex) {
176
                    return true;
177
                }
178
            }
179
        }
180
        return false;
181
    }
182

  
183
    @Override
184
    public void addMethods(URL methodsfile) {
185
        this.methodsList.addMethods(methodsfile);
186
    }
187

  
188
    @Override
189
    public List<ScriptingHelpMethod> getMethods() {
190
        return this.methodsList;
191
    }
192

  
193
    @Override
194
    public ScriptingHelpClass getHelpClass(String name) {
195
        return this.methodsList.getHelpClass(name);
196
    }
197

  
198
    @Override
199
    public List<ScriptingHelpClass> getHelpClasses() {
200
        return this.methodsList.getHelpClasses();
201
    }
202

  
203
    @Override
204
    public Map<String, ScriptingHelpMethod> findMethods(String text) {
205
        return this.methodsList.findMethods(text);
206
    }
207

  
208
    @Override
209
    public List<File> getHelpRoots() {
210
        if (this.helpRoots == null) {
211
            List<File> helpRoots = new ArrayList();
212
            helpRoots.add(new File(this.manager.getHomeFolder(), "help"));
213
            this.helpRoots = helpRoots;
214
        }
215
        return this.helpRoots;
216
    }
217

  
218
    @Override
219
    public HelpSet getHelpSet() {
220
        if (this.helpSet == null) {
221
            this.initializeHelpSet();
222
        }
223
        return this.helpSet;
224
    }
225

  
226
    private BufferedReader createFileReader(File f) {
227
        if (f == null) {
228
            logger.warn("Can't create reader file is null.");
229
            return null;
230
        }
231
        Reader fileReader;
232
        try {
233
            fileReader = new FileReader(f);
234
        } catch (FileNotFoundException ex) {
235
            logger.warn("Can't create reader from '" + f.getAbsolutePath() + "'.", ex);
236
            return null;
237
        }
238
        return new BufferedReader(fileReader);
239
    }
240

  
241
    private int countLines(File textfile) {
242
        try {
243
            BufferedReader reader = createFileReader(textfile);
244
            int nlines = 0;
245
            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
246
                nlines++;
247
            }
248
            return nlines;
249
        } catch (IOException ex) {
250
            return -1;
251
        }
252
    }
253

  
254
    @Override
255
    public boolean importJavadoc(String name, File folder, SimpleTaskStatus status) {
256
        if (existsHelp(name)) {
257
            status.message("Help '" + name + "' already exists");
258
            status.abort();
259
            return false;
260
        }
261
        status.setIndeterminate();
262
        status.message(("Preparing import of javadoc..."));
263

  
264
        HelpConfig config = new DefaultHelpConfig();
265

  
266
        File rootFolder = this.getHelpRoots().get(0);
267
        config.create(rootFolder, name, folder);
268

  
269
        Writer helpsetWriter = null;
270
        Writer tocWriter = null;
271
        Writer mappingWriter = null;
272
        Writer indexWriter = null;
273
        BufferedReader packageListReader = null;
274

  
275
        try {
276

  
277
            helpsetWriter = config.getHelpSetWriter();
278
            helpsetWriter.write(
279
                    "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
280
                    + "<!DOCTYPE helpset\n"
281
                    + "  PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN\"\n"
282
                    + " 		  \"http://java.sun.com/products/javahelp/helpset_1_0.dtd\">\n\n"
283
                    + "<?TestTarget this is data for the test target ?>\n\n"
284
                    + "<helpset version=\"1.0\">\n\n"
285
                    + "  <!-- title -->\n"
286
                    + "  <title>" + config.getName() + "</title>\n\n"
287
                    + "  <!-- maps -->\n"
288
                    + "  <maps>\n"
289
                    + "     <homeID>main</homeID>\n"
290
                    + "     <mapref location=\""+HelpConfig.FILENAME_HELPMAPPING+"\"/>\n"
291
                    + "  </maps>\n\n"
292
                    + "  <!-- views -->\n"
293
                    + "  <view>\n"
294
                    + "    <name>TOC</name>\n"
295
                    + "    <label>TOC</label>\n"
296
                    + "    <type>javax.help.TOCView</type>\n"
297
                    + "    <data>"+HelpConfig.FILENAME_HELPTOC+"</data>\n"
298
                    + "  </view>\n\n"
299
                    + "  <view>\n"
300
                    + "    <name>Index</name>\n"
301
                    + "    <label>Index</label>\n"
302
                    + "    <type>javax.help.IndexView</type>\n"
303
                    + "    <data>"+HelpConfig.FILENAME_HELPINDEX+"</data>\n"
304
                    + "  </view>\n"
305
                    + "  <view>\n"
306
                    + "    <name>Search</name>\n"
307
                    + "    <label>Search</label>\n"
308
                    + "    <type>javax.help.SearchView</type>\n"
309
                    + "    <data engine=\"com.sun.java.help.search.DefaultSearchEngine\">"+HelpConfig.FILENAME_SEARCHDB+"</data>\n"
310
                    + "  </view>\n\n"
311
                    + "  <view>\n"
312
                    + "    <name>Favorites</name>\n"
313
                    + "    <label>Favoritos</label>\n"
314
                    + "    <type>javax.help.FavoritesView</type>\n"
315
                    + "  </view>\n\n"
316
                    + "  <presentation default=\"true\" displayviewimages=\"false\">\n"
317
                    + "     <name>main window</name>\n"
318
                    + "     <size width=\"700\" height=\"400\" />\n"
319
                    + "     <location x=\"200\" y=\"200\" />\n"
320
                    + "     <title>gvSIG - Ayuda en linea</title>\n"
321
                    + "     <image>toplevelfolder</image>\n"
322
                    + "     <toolbar>\n"
323
                    + "       <helpaction image=\"action.back\">javax.help.BackAction</helpaction>\n"
324
                    + "       <helpaction image=\"action.forward\">javax.help.ForwardAction</helpaction>\n"
325
                    + "     </toolbar>\n"
326
                    + "  </presentation>\n"
327
                    + "</helpset>"
328
            );
329
            IOUtils.closeQuietly(helpsetWriter);
330

  
331
            tocWriter = config.getTOCWriter();
332
            mappingWriter = config.getHelpMappingWriter();
333
            packageListReader = createFileReader(new File(folder, "package-list"));
334

  
335
            status.message("Processing package-list");
336
            status.setRangeOfValues(0, countLines(new File(folder, "package-list")));
337

  
338
            mappingWriter.write(
339
                    "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
340
                    + "<!DOCTYPE map\n"
341
                    + "  PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN\"\n"
342
                    + "         \"http://java.sun.com/products/javahelp/map_1_0.dtd\">\n\n"
343
                    + "<map version=\"1.0\">\n"
344
            );
345
            tocWriter.write(
346
                    "<!DOCTYPE toc\n"
347
                    + "  PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 1.0//EN\"\n    "
348
                    + "         \"http://java.sun.com/products/javahelp/toc_1_0.dtd\">\n\n"
349
                    + "<toc version=\"1.0\">\n"
350
            );
351
            int count = 0;
352
            tocWriter.write("<tocitem text=\"" + name + "\">\n");
353
            String line = packageListReader.readLine();
354
            while (line != null) {
355
                tocWriter.write("\t<tocitem text=\"" + line + "\">\n");
356
                File f = new File(folder, line.replace(".", File.separator));
357
                if (f.isDirectory() && f.canRead()) {
358
                    String[] fileNames = f.list();
359
                    Arrays.sort(fileNames, String.CASE_INSENSITIVE_ORDER);
360
                    for (int i = 0; i < fileNames.length; i++) {
361
                        if (fileNames[i].toLowerCase().endsWith(".html") &&
362
                            ! fileNames[i].contains("-")    ) {
363
                            String fileName = FilenameUtils.removeExtension(fileNames[i]);
364

  
365
                            tocWriter.write("\t\t<tocitem text=\"");
366
                            tocWriter.write(fileName);
367
                            tocWriter.write("\" target=\"");
368
                            tocWriter.write(line);
369
                            tocWriter.write(".");
370
                            tocWriter.write(fileName);
371
                            tocWriter.write(".html\"/>\n");
372

  
373
                            String targetid = line + "." + fileName;
374
                            String url = "/"+targetid.replace(".", "/");
375
                            mappingWriter.write("\t\t<mapID target=\"");
376
                            mappingWriter.write(targetid);
377
                            mappingWriter.write(".html\" url=\"");
378
                            mappingWriter.write(url);
379
                            mappingWriter.write(".html\" />\n");
380
                        }
381
                    }
382
                }
383
                tocWriter.write("\t</tocitem>\n");
384
                line = packageListReader.readLine();
385
                status.setCurValue(count);
386
            }
387
            tocWriter.write("</tocitem>\n");
388
            tocWriter.write("</toc>\n");
389
            mappingWriter.write("</map>\n");
390

  
391
            IOUtils.closeQuietly(tocWriter);
392
            IOUtils.closeQuietly(mappingWriter);
393

  
394
            indexWriter = config.getHelpIndexWriter();
395
            indexWriter.write(
396
                "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" +
397
                "<!DOCTYPE index \n" +
398
                "	PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp Index Version 1.0//EN\" \n" +
399
                "		\"http://java.sun.com/javase/technologies/desktop/javahelp/index_1_0.dtd\">\n" +
400
                "\n" +
401
                "<index version=\"1.0\">\n"
402
            );
403
            MethodList methodsIndex = loadJavadocMethodsIndex(new File(folder, "index-all.html"), status);
404
            Iterator<ScriptingHelpMethod> it = methodsIndex.iterator();
405
            while (it.hasNext()) {
406
                ScriptingHelpMethod mn = it.next();
407
                indexWriter.write("\t<indexitem text=\"" + mn.getName() + "\" expand=\"false\">\n");
408
                Iterator<ScriptingHelpClass> itcn = mn.iterator();
409
                while (itcn.hasNext()) {
410
                    ScriptingHelpClass cn = itcn.next();
411
                    indexWriter.write("\t\t<indexitem text=\"" + cn.getName() + "\" target=\"" + cn.getUrl() + "\" />\n");
412
                }
413
                indexWriter.write("\t</indexitem>\n");
414
            }
415
            indexWriter.write("</index>\n");
416
            IOUtils.closeQuietly(indexWriter);
417
        
418
            File docsFolder = config.getDocsFolder();
419
            if( docsFolder!=null ) {
420
                // Si no puede obtener el fichero donde estan los docs como un File,
421
                // probablemente sea por que los documentos esten zipeados,
422
                // Y en ese caso no se pueden indexar.
423
                status.message("Indexing files");
424
                status.setIndeterminate();
425
                IndexerHelper indexer = new IndexerHelper();
426
                indexer.index(
427
                        config.getIndexerConfig(),
428
                        config.getSearchdb(),
429
                        docsFolder
430
                );
431
            }
432
        
433
            status.message("Loading help");
434
            HelpSet helpset = loadHelp(config.getFolder());
435
            if (helpset != null) {
436
                this.getHelpSet().add(helpset);
437
            }
438

  
439
        } catch (IOException ex) {
440
            logger.warn("Can't import help '" + name + "' from '" + folder.getAbsolutePath() + "'.", ex);
441
            status.abort();
442
            return false;
443

  
444
        } finally {
445
            IOUtils.closeQuietly(tocWriter);
446
            IOUtils.closeQuietly(mappingWriter);
447
            IOUtils.closeQuietly(helpsetWriter);
448
            IOUtils.closeQuietly(indexWriter);
449
            IOUtils.closeQuietly(packageListReader);
450
        }
451

  
452
        return true;
453
    }
454

  
455
    private MethodList loadJavadocMethodsIndex(File indexallFile, SimpleTaskStatus status) throws IOException {
456
        try {
457
            Map<String, Set<String>> classes = new HashMap();
458
            
459
            BufferedReader indexallReader = createFileReader(indexallFile);
460
            status.message("Loading methods information...");
461
            status.setRangeOfValues(0, countLines(indexallFile));
462
            int count = 0;
463
            for (String line = indexallReader.readLine(); line != null; line = indexallReader.readLine()) {
464
                line = line.replaceAll("\\<.*?\\>", "");
465
                String parts[] = line.split(" ");
466
                int l = parts.length;
467
                if (l > 4 && "Method".equalsIgnoreCase(parts[l - 4])) {
468
                    String classname = parts[l - 1];
469
                    String methodname = parts[0];
470
                    int n = methodname.indexOf("(");
471
                    if (n > 0) {
472
                        methodname = methodname.substring(0, n);
473
                    }
474
                    Set<String> classmethods = classes.get(classname);
475
                    if (classmethods == null) {
476
                        classmethods = new HashSet<String>();
477
                        classes.put(classname, classmethods);
478
                    }
479
                    classmethods.add(methodname);
480
                }
481
                status.setCurValue(count++);
482
            }
483

  
484
            status.message("Processing methods information...");
485
            status.setRangeOfValues(0, classes.size());
486
            count = 0;
487
            
488
            MethodList methodsIndex = new MethodList();
489
            Iterator<Map.Entry<String, Set<String>>> it = classes.entrySet().iterator();
490
            while (it.hasNext()) {
491
                Map.Entry<String, Set<String>> entry = it.next();
492
                String[] ss = entry.getKey().split("[.]");
493
                String classname = ss[ss.length - 1];
494
                methodsIndex.add(classname, entry.getKey() + ".html", new ArrayList(entry.getValue()));
495
                status.setCurValue(count++);
496
            }
497
            return methodsIndex;
498
        } catch (IOException ex) {
499
            logger.warn("Can't load methods information from '"+indexallFile.getAbsolutePath()+"'.",ex);
500
            throw ex;
501
        }
502
    }
503

  
504
//    public List<ScriptingHelpAPI> getAPI() {
505
//        String[] files = this.getFolder().list();
506
//        List<ScriptingHelpAPI> apis = new ArrayList<ScriptingHelpAPI>();
507
//
508
//        for (int i = 0; i < files.length; i++) {
509
//            apis.add(new DefaultScriptingHelpAPI(files[i]));
510
//        }
511
//        return apis;
512
//    }
513
//
514
//    private static class DefaultScriptingHelpAPI implements ScriptingHelpAPI {
515
//
516
//        private final String name;
517
//
518
//        DefaultScriptingHelpAPI(String name) {
519
//            this.name = name;
520
//        }
521
//
522
//        public String getName() {
523
//            return this.name;
524
//        }
525
//
526
//    }
527

  
528
}
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/MethodList.java
1
package org.gvsig.scripting.impl;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.net.URL;
6
import java.util.ArrayList;
7
import java.util.Collection;
8
import java.util.Collections;
9
import java.util.Comparator;
10
import java.util.HashMap;
11
import java.util.HashSet;
12
import java.util.Iterator;
13
import java.util.List;
14
import java.util.Map;
15
import java.util.Set;
16
import java.util.logging.Level;
17
import java.util.logging.Logger;
18
import java.util.regex.Matcher;
19
import java.util.regex.Pattern;
20
import org.apache.commons.io.FileUtils;
21

  
22
import org.gvsig.scripting.ScriptingHelpManager.ScriptingHelpClass;
23
import org.gvsig.scripting.ScriptingHelpManager.ScriptingHelpMethod;
24

  
25
public class MethodList extends ArrayList<ScriptingHelpMethod> {
26

  
27
    /**
28
     *
29
     */
30
    private static final long serialVersionUID = 2097121200002178537L;
31

  
32
    private Map<String, ClassNode> allClasses = new HashMap<String, ClassNode>();
33

  
34
    public MethodList() {
35
    }
36

  
37
    public void addMethods(URL indexFileUrl) {
38
        File f = new File(indexFileUrl.getFile());      
39
        this.addMethods(f);
40
    }
41
    
42
    public void addMethods(File index) {
43
        String indexFile = null;
44
        try {
45
            indexFile = FileUtils.readFileToString(index);
46
        } catch (IOException ex) {
47
            
48
        }
49
        Pattern methodPattern = Pattern.compile("<indexitem text=\"[^\"]*\" expand=\"false\">");
50
        Pattern endMethodPattern = Pattern.compile("</indexitem>");;
51
        Pattern classPattern = Pattern.compile("<indexitem text=\"[^\"]*\" target=\"[^\"]*\" />");
52

  
53
        Matcher methodMatcher = methodPattern.matcher(indexFile);
54
        while (methodMatcher.find()) {
55
            String subIndexFile = indexFile.substring(methodMatcher.start());
56
            Matcher endMethodMatcher = endMethodPattern.matcher(subIndexFile);
57
            if (endMethodMatcher.find()) {
58
                String methodExtract = subIndexFile.substring(0, endMethodMatcher.start());
59
                String[] methodnode = (indexFile.substring(methodMatcher.start(), methodMatcher.end())).split("\"");
60
                if (methodnode.length > 2) {
61
                    MethodNode mn = new MethodNode(methodnode[1], null);
62

  
63
                    Matcher classMatcher = classPattern.matcher(methodExtract);
64
                    while (classMatcher.find()) {
65
                        String[] classnode = (methodExtract.substring(classMatcher.start(), classMatcher.end())).split("\"");
66

  
67
                        if (classnode.length > 3) {
68
                            ClassNode cn = this.getOrCreateClassInfo(classnode[1], classnode[3]);
69
                            cn.addMethod(mn.getName());
70
                            mn.add(cn);
71
                        }
72

  
73
                    }
74
                    this.add(mn);
75

  
76
                }
77
            }
78

  
79
        }
80
    }
81

  
82
    private ClassNode getOrCreateClassInfo(String name, String url) {
83
        ClassNode cn = this.allClasses.get(name);
84
        if( cn == null ) {
85
            cn = new ClassNode(name,url);
86
            this.allClasses.put(name,cn);
87
        }
88
        return cn;
89
    }
90
    
91
    public ClassNode getHelpClass(String name) {
92
        return this.allClasses.get(name);
93
    }
94

  
95
    public List<ScriptingHelpClass> getHelpClasses(){
96
        List<ScriptingHelpClass> classes = new ArrayList<ScriptingHelpClass>(this.allClasses.values());
97
        Collections.sort(classes);
98
        return classes;
99
    }
100
    
101
    public ScriptingHelpClass add(String className, String target, List<String> methods) {
102
        ClassNode cn = this.getOrCreateClassInfo(className, target);
103
        for (String methodName : methods) {
104
            boolean isFound = false;
105
            for (ScriptingHelpMethod mn : this) {
106
                if (mn.getName().equals(methodName)) {
107
                    ((MethodNode) mn).add(cn);
108
                    cn.addMethod(((MethodNode) mn).getName());
109
                    isFound = true;
110
                }
111
            }
112
            if (!isFound) {
113
                this.add(new MethodNode(methodName, cn));
114
            }
115
        }
116

  
117
        Collections.sort(this, new Comparator<ScriptingHelpMethod>() {
118
            public int compare(ScriptingHelpMethod p1, ScriptingHelpMethod p2) {
119
                return p1.getName().toLowerCase().compareTo(p2.getName().toLowerCase());
120
            }
121
        });
122

  
123
        return cn;
124
    }
125

  
126
    public void printMethodList(Map<String, MethodNode> map) {
127
        Set<String> keys = map.keySet();
128
        Iterator<String> it = keys.iterator();
129
        while (it.hasNext()) {
130
            MethodNode mn = map.get(it.next());
131
            Iterator<ScriptingHelpClass> i = mn.iterator();
132
            System.out.println(mn);
133
            while (i.hasNext()) {
134
                ClassNode cn = (ClassNode) i.next();
135
                System.out.println(" ->" + cn.className);
136
            }
137
        }
138
    }
139

  
140
    public Map<String, ScriptingHelpMethod> findMethods(String text) {
141

  
142
        Map<String, ScriptingHelpMethod> matches = new HashMap<String, ScriptingHelpMethod>();
143
        List<ScriptingHelpMethod> l = this;
144
        if (text != null) {
145
            for (ScriptingHelpMethod mn : l) {
146
                if (mn.getName().toLowerCase().contains(text.toLowerCase())) {
147
                    matches.put(mn.getName(), mn);
148
                }
149
            }
150
        }
151
        return matches;
152
    }
153

  
154
    private static class MethodNode implements ScriptingHelpMethod {
155

  
156
        /**
157
         *
158
         */
159
        private static final long serialVersionUID = -7155323542211180518L;
160
        private final String methodName;
161
        private final List<ScriptingHelpClass> classes;
162

  
163
        MethodNode(String name, ScriptingHelpClass c) {
164
            this.methodName = name;
165
            this.classes = new ArrayList<ScriptingHelpClass>();
166
            if (c != null) {
167
                classes.add(c);
168
            }
169
        }
170

  
171
        MethodNode add(ClassNode c) {
172
            this.classes.add(c);
173
            return this;
174
        }
175

  
176
        public String getName() {
177
            return this.methodName;
178
        }
179

  
180
        public Iterator<ScriptingHelpClass> iterator() {
181
            return this.classes.iterator();
182
        }
183

  
184
        public String toString() {
185
            return getName();
186
        }
187
    }
188

  
189
    private static class ClassNode implements ScriptingHelpClass, Comparable {
190

  
191
        String className;
192
        String classUrl;
193
        Set<String> methods = new HashSet<String>();
194

  
195
        ClassNode(String name, String url) {
196
            this.className = name;
197
            this.classUrl = url;
198
        }
199

  
200
        public String getName() {
201
            return this.className;
202
        }
203

  
204
        public String getUrl() {
205
            return this.classUrl;
206
        }
207

  
208
        public String toString() {
209
            return getName();
210
        }
211

  
212
        public void addMethod(String name) {
213
            this.methods.add(name);
214
        }
215
        
216
        public List<String> getMethods() {
217
            List l = new ArrayList(this.methods);
218
            Collections.sort(l);
219
            return l;
220
        }
221

  
222
        @Override
223
        public int compareTo(Object o) {
224
            return this.className.compareToIgnoreCase( ((ClassNode)o).getName() );
225
        }
226
    }
227

  
228
//    public ScriptingHelpClass createHelpClass(String name, String target) {
229
//        return new ClassNode(name, target);
230
//    }
231
}
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/DefaultHelpConfig.java
1
package org.gvsig.scripting.impl;
2

  
3
import org.gvsig.scripting.HelpConfig;
4
import java.io.BufferedWriter;
5
import java.io.File;
6
import java.io.FileWriter;
7
import java.io.IOException;
8
import java.io.Writer;
9
import java.net.MalformedURLException;
10
import java.net.URL;
11
import java.net.URLClassLoader;
12
import javax.help.HelpSet;
13
import org.apache.commons.io.FileUtils;
14
import org.apache.commons.lang3.StringUtils;
15
import org.ini4j.Ini;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18

  
19
public class DefaultHelpConfig implements HelpConfig {
20

  
21
    private static final Logger logger = LoggerFactory.getLogger(DefaultHelpConfig.class);
22

  
23

  
24
    private File folder = null;
25
    private Ini ini = null;
26
    private ClassLoader loader = null;
27

  
28
    public DefaultHelpConfig() {
29

  
30
    }
31

  
32
    @Override
33
    public String getName() {
34
        return this.folder.getName();
35
    }
36

  
37
    private String getPath() {
38
        if (this.folder == null) {
39
            return "(unknown)";
40
        }
41
        return this.folder.getAbsolutePath();
42
    }
43

  
44
    @Override
45
    public File getFolder() {
46
        return this.folder;
47
    }
48

  
49
    private File getResource(String name) {
50
        File f = new File(folder, name);
51
        return f;
52
    }
53

  
54
    @Override
55
    public File getHelpConfig() {
56
        return this.getResource(FILENAME_HELP_CONFIG);
57
    }
58

  
59
    @Override
60
    public File getHelpSet() {
61
        return this.getResource(FILENAME_HELPSET);
62
    }
63

  
64
    @Override
65
    public File getHelpIndex() {
66
        return this.getResource(FILENAME_HELPINDEX);
67
    }
68

  
69
    @Override
70
    public File getTOC() {
71
        return this.getResource(FILENAME_HELPTOC);
72
    }
73

  
74
    @Override
75
    public File getHelpMapping() {
76
        return this.getResource(FILENAME_HELPMAPPING);
77
    }
78

  
79
    @Override
80
    public File getIndexerConfig() {
81
        return this.getResource(FILENAME_INDEXER_CONFIG);
82
    }
83

  
84
    @Override
85
    public File getSearchdb() {
86
        return this.getResource(FILENAME_SEARCHDB);
87
    }
88

  
89
    private Writer getResourceWriter(String name) {
90
        File f = this.getResource(name);
91
        try {
92
            if (!f.exists()) {
93
                f.createNewFile();
94
            }
95
            Writer fwriter = new FileWriter(f);
96
            Writer bufferdWriter = new BufferedWriter(fwriter);
97
            return bufferdWriter;
98
        } catch (IOException ex) {
99
            logger.info("Can't create resource '" + name + "' in '" + f.getAbsolutePath() + "'.", ex);
100
            return null;
101
        }
102
    }
103

  
104
    @Override
105
    public Writer getHelpSetWriter() {
106
        return this.getResourceWriter(FILENAME_HELPSET);
107
    }
108

  
109
    @Override
110
    public Writer getHelpIndexWriter() {
111
        return this.getResourceWriter(FILENAME_HELPINDEX);
112
    }
113

  
114
    @Override
115
    public Writer getTOCWriter() {
116
        return this.getResourceWriter(FILENAME_HELPTOC);
117
    }
118

  
119
    @Override
120
    public Writer getHelpMappingWriter() {
121
        return this.getResourceWriter(FILENAME_HELPMAPPING);
122
    }
123

  
124
    @Override
125
    public boolean exists(File folder) {
126
        if( folder == null ) {
127
            return false;
128
        }
129
        File f = new File(folder, FILENAME_HELP_CONFIG);
130
        return f.exists();
131
    }
132

  
133
    @Override
134
    public boolean load(File folder) {
135
        if( folder == null ) {
136
            logger.info("Can't load help, folder is null.");
137
            return false;
138
        }
139
        if( !this.exists(folder) ) {
140
            logger.info("Can't load help from '" + folder.getAbsolutePath() + "'.");
141
            return false;
142
        }
143
        Ini ini;
144
        this.folder = folder;
145
        try {
146
            ini = new Ini(this.getHelpConfig());
147
        } catch (Exception ex) {
148
            this.folder = null;
149
            logger.info("Can't load config help file from '" + this.getPath() + ".", ex);
150
            return false;
151
        }
152
        this.ini = ini;
153
        if( !this.getSearchdb().exists() ) {
154
            if( this.getDocsFolder().isDirectory() ) {
155
                IndexerHelper indexer = new IndexerHelper();
156
                indexer.index(
157
                        this.getIndexerConfig(),
158
                        this.getSearchdb(),
159
                        this.getDocsFolder()
160
                );
161
            }
162
        }
163
        return true;
164
    }
165

  
166
    @Override
167
    public boolean create(File folder, String name) {
168
        return this.create(FileUtils.getFile(folder, name), (File)null);
169
    }
170

  
171
    @Override
172
    public boolean create(File folder, String name, File docsFolder) {
173
        return this.create(FileUtils.getFile(folder, name), docsFolder);
174
    }
175

  
176
    @Override
177
    public boolean create(File folder, File docsFolder) {
178
        if (folder == null) {
179
            logger.info("Can't create help folder, paramter is null.");
180
            return false;
181
        }
182
        try {
183
            if (!folder.exists()) {
184
                FileUtils.forceMkdir(folder);
185
            }
186
            File f = new File(folder, FILENAME_DOCS);
187
            if (!f.exists()) {
188
                FileUtils.forceMkdir(f);
189
            }
190
            f = new File(folder, FILENAME_SEARCHDB);
191
            if (!f.exists()) {
192
                FileUtils.forceMkdir(f);
193
            }
194
            f = new File(folder, FILENAME_HELP_CONFIG);
195
            if (!f.exists()) {
196
                Ini ini = new Ini();
197
                if( docsFolder == null ) {
198
                    ini.put("main", "docs", "file:${config.path}/docs");
199
                } else {
200
                    ini.put("main", "docs", docsFolder.toURI().toString());
201
                }
202
                ini.store(f);
203
            } 
204
            if( !this.load(folder) ) {
205
                return false;
206
            }
207
            f = new File(folder, FILENAME_INDEXER_CONFIG);
208
            if (!f.exists()) {
209
                FileUtils.write(f,
210
                        "IndexRemove " + this.getDocsFolder() + "\n"
211
                );
212
            }
213
            return true;
214
        } catch (Exception ex) {
215
            this.ini = null;
216
            this.folder = null;
217
            logger.info("Can't create help folder '" + folder.getAbsolutePath() + "'.", ex);
218
            return false;
219
        }
220
    }
221

  
222
    @Override
223
    public File getDocsFolder() {
224
        File docsFolder = null;
225
        String s = this.ini.get("main", "docs");
226
        if (s == null) {
227
            docsFolder = this.getResource(FILENAME_DOCS);
228
        } else {            
229
            s = StringUtils.replace(s, "${config.path}", this.folder.getAbsolutePath());
230
            URL url;
231
            try {
232
                url = new URL(s);
233
                if( "file".equalsIgnoreCase(url.getProtocol())) {
234
                    docsFolder = new File(url.getFile());
235
                }
236
            } catch (MalformedURLException ex) {
237
                // Si no puede obtener el File retorna null.
238
                logger.info("Can't get docs folder from option main/docs of file '"+this.getHelpConfig().getAbsolutePath()+"'.",ex);
239
            }
240
        }
241
        return docsFolder;        
242
    }
243
    
244
    @Override
245
    public URL getDocsUrl() {
246
        URL docsFolder = null;
247
        try {
248
            // Lo inicializo con el valor por defecto.
249
            docsFolder = this.getResource(FILENAME_DOCS).toURI().toURL();
250
        } catch (MalformedURLException ex) {
251
            // Por aqui no deberia pasar, no se me ocurre por que no se
252
            // podria convertir un file a una url.
253
        }
254
        String s = this.ini.get("main", "docs");
255
        if (s != null) {
256
            s = StringUtils.replace(s, "${config.path}", this.folder.getAbsolutePath());
257
            try {
258
                docsFolder = new URL(s);
259
            } catch (MalformedURLException ex) {
260
                // Si falla cogemos el valor por defecto.
261
                logger.info("Can't get docs folder from option main/docs of file '"+this.getHelpConfig().getAbsolutePath()+"'.",ex);
262
            }
263
        }
264
        return docsFolder;        
265
    }
266

  
267
    @Override
268
    public ClassLoader getLoader() {
269
        if (this.loader == null) {
270
            try {
271
                URL[] urls = new URL[]{
272
                    this.getDocsUrl(),
273
                    this.getFolder().toURI().toURL()
274
                };
275
                ClassLoader loader = new URLClassLoader(urls);
276
                this.loader = loader;
277
            } catch (MalformedURLException ex) {
278
                logger.info("Can't create class loader from config help file '" + this.getPath() + ".", ex);
279
                return null;
280
            }
281
        }
282
        return this.loader;
283
    }
284

  
285
    @Override
286
    public HelpSet createHelpSet() {
287
        HelpSet hst;
288
        try {
289
            hst = new HelpSet(this.getLoader(), this.getHelpSet().toURI().toURL());
290
        } catch (Exception ex) {
291
            logger.info("Can't create HelpSet from  config help file '" + this.getPath() + ".", ex);
292
            return null;
293
        }
294
        return hst;
295
    }
296

  
297
}
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/ScriptingHelpInstallerProviderFactory.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
package org.gvsig.scripting.impl;
24

  
25
import org.gvsig.scripting.ScriptingManager;
26
import org.gvsig.tools.ToolsLocator;
27
import org.gvsig.tools.dynobject.DynClass;
28
import org.gvsig.tools.dynobject.DynObject;
29
import org.gvsig.tools.dynobject.DynObjectManager;
30
import org.gvsig.tools.service.spi.AbstractProviderFactory;
31
import org.gvsig.tools.service.spi.Provider;
32
import org.gvsig.tools.service.spi.ProviderServices;
33

  
34
public class ScriptingHelpInstallerProviderFactory extends
35
    AbstractProviderFactory {
36

  
37
    private DynClass parametersDefinition = null;
38

  
39
    @Override
40
    protected DynClass createParametersDynClass() {
41
        if (parametersDefinition == null) {
42
            initialize();
43
        }
44
        return parametersDefinition;
45
    }
46

  
47
    @Override
48
    protected Provider doCreate(DynObject parameters, ProviderServices services) {
49
        return new ScriptingInstallerProvider(services);
50
    }
51

  
52
    @Override
53
    public void initialize() {
54
        if (parametersDefinition == null) {
55
            DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager();
56
            if( dynObjectManager.has(ScriptingManager.HELP_INSTALLER_PROVIDER_NAME) ) {
57
                parametersDefinition =  dynObjectManager.get(ScriptingManager.HELP_INSTALLER_PROVIDER_NAME);
58
            } else {
59
                parametersDefinition =  dynObjectManager.createDynClass(
60
                        ScriptingManager.HELP_INSTALLER_PROVIDER_NAME,
61
                	ScriptingManager.HELP_INSTALLER_PROVIDER_DESCRIPTION
62
                );
63
                dynObjectManager.add(parametersDefinition);
64
            }
65
        }
66
    }
67

  
68
}
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/IndexerHelper.java
1
package org.gvsig.scripting.impl;
2

  
3
import com.sun.java.help.search.Indexer;
4
import java.io.File;
5
import java.io.IOException;
6
import java.lang.reflect.Field;
7
import java.util.Hashtable;
8
import java.util.logging.Level;
9
import org.apache.commons.io.FileUtils;
10
import org.apache.commons.lang3.StringUtils;
11
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13

  
14
public class IndexerHelper {
15

  
16
    protected static final Logger logger = LoggerFactory.getLogger(IndexerHelper.class);
17

  
18
    protected static Indexer indexer;
19

  
20
    public IndexerHelper() {
21

  
22
    }
23

  
24
    /**
25
     * Repeated invokation of the javahelp indexer (possibly via multiple
26
     * classloaders) is causing trouble, residue from previous invokations seems
27
     * to cause errors this is a nasty workaround for the problem. alternatively
28
     * we could try invoking the indexer from a separate jvm i guess, ut that's
29
     * more work.
30
     *
31
     */
32
    public void ClearStaticFieldsInJavaHelpIndexer() {
33
        if (indexer == null) {
34
            return;
35
        }
36
        try {
37
            Class<?> clazz = Class.forName("com.sun.java.help.search.Indexer");
38
            Field fld = clazz.getDeclaredField("kitRegistry");
39
            fld.setAccessible(true);
40
            Hashtable<?, ?> hash = (Hashtable<?, ?>) fld.get(null);
41
            hash.clear();
42

  
43
            clazz = Class.forName("com.sun.java.help.search.HTMLIndexerKit");
44
            fld = clazz.getDeclaredField("defaultParser");
45
            fld.setAccessible(true);
46
            fld.set(null, null);
47

  
48
            fld = clazz.getDeclaredField("defaultCallback");
49
            fld.setAccessible(true);
50
            fld.set(null, null);
51

  
52
        } catch (Exception ex) {
53
            logger.warn("Can't clear indexer", ex);
54
        }
55
    }
56

  
57
    private Indexer getIndexer() {
58
        if (indexer == null) {
59
            indexer = new Indexer();
60
        }
61
        return indexer;
62
    }
63

  
64
    public void index(File config, File searchdb, File docs) {
65
            /*
66
            https://docs.oracle.com/cd/E19253-01/819-0913/author/jhindexer.html
67
            
68
            
69
            Usage:   java JavaHelp.Index options file ...
70
            
71
            Options: -c file   config file
72
            -db file  generated database file name
73
            -verbose  verbose documentation
74
            -nostopwords ignore stop words
75
            -locale language_country_variant
76
            -logfile log file name
77
            Note: config file composition:
78
            IndexRemove /public_html/JavaHelp/demo
79
            IndexPrepend ..
80
            StopWords word1 ... wordN
81
            StopWordsFile stopWordFileName
82
            File /public_html/JavaHelp/demo/first.html
83
            File=/public_html/JavaHelp/demo/second.html
84
            ...
85
            */
86
            
87
        try {
88
            FileUtils.write(config,
89
                    "IndexRemove " + docs.getAbsolutePath() + "\n"
90
            );
91
        } catch (IOException ex) {
92
            logger.warn("Can't create indexer config file in '"+config.getAbsolutePath()+"'.",ex);
93
        }
94
        String[] args = new String[]{
95
            //"-verbose",
96
            "-c",
97
            config.getAbsolutePath(),
98
            "-db",
99
            searchdb.getAbsolutePath() + "/",
100
            docs.getAbsolutePath() + "/"
101
        };
102
        ClearStaticFieldsInJavaHelpIndexer();
103
        try {
104
            logger.info("Start indexing help, args: '"+StringUtils.join(args, ", ")+"'.");
105
            this.getIndexer().compile(args);
106
            logger.info("End indexing help, args: '"+StringUtils.join(args, ", ")+"'.");
107
        } catch (Exception e) {
108
            logger.info("Can't index help ('" + args + "').", e);
109
        }
110
    }
111
}
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/ScriptingHelpInstallerProvider.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
package org.gvsig.scripting.impl;
24

  
25
import java.io.File;
26
import java.io.IOException;
27
import java.io.InputStream;
28
import org.apache.commons.io.FileUtils;
29

  
30
import org.gvsig.installer.lib.api.PackageInfo;
31
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
32
import org.gvsig.installer.lib.spi.InstallPackageProviderServices;
33
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
34
import org.gvsig.installer.lib.spi.InstallerProviderManager;
35
import org.gvsig.installer.lib.spi.execution.InstallPackageProvider;
36
import org.gvsig.scripting.ScriptingLocator;
37
import org.gvsig.scripting.ScriptingManager;
38
import org.gvsig.tools.service.spi.AbstractProvider;
39
import org.gvsig.tools.service.spi.ProviderServices;
40

  
41
public class ScriptingHelpInstallerProvider extends AbstractProvider
42
    implements InstallPackageProvider {
43

  
44
    public ScriptingHelpInstallerProvider(ProviderServices providerServices) {
45
        super(providerServices);
46
    }
47

  
48
    public void install(File applicationDirectory, InputStream inputStream,
49
        PackageInfo packageInfo) throws InstallPackageServiceException {
50

  
51
    	ScriptingManager scriptingManager = ScriptingLocator.getManager();
52
    	
53
    	File target = scriptingManager.getHelpManager().getHelpRoots().get(0);
54
    	
55
        try {
56
            if( ! target.exists() ) {
57
                FileUtils.forceMkdir(target);
58
            }
59
            InstallerProviderManager installerProviderManager =
60
                InstallerProviderLocator.getProviderManager();
61
            InstallPackageProviderServices installerProviderServices =
62
                installerProviderManager.createInstallerProviderServices();
63

  
64
            installerProviderServices.decompress(inputStream, target);
65

  
66
        } catch (Exception e) {
67
            throw new InstallPackageServiceException(e);
68
        }
69
    }
70

  
71
    public void installLater(File applicationDirectory,
72
        InputStream inputStream, PackageInfo packageInfo)
73
        throws InstallPackageServiceException, IOException {
74
        // TODO Auto-generated method stub
75

  
76
    }
77
}
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/DefaultScriptingManager.java
23 23
import org.gvsig.scripting.ScriptingDialog;
24 24
import org.gvsig.scripting.ScriptingExternalFile;
25 25
import org.gvsig.scripting.ScriptingFolder;
26
import org.gvsig.scripting.ScriptingHelpManager;
27 26
import org.gvsig.scripting.ScriptingManager;
28 27
import org.gvsig.scripting.ScriptingScript;
29 28
import org.gvsig.scripting.ScriptingUnit;
......
54 53
    protected List<RegisterSystemFolder> systemFolders = new ArrayList<>();
55 54
    protected ScriptEngineManager engineManager = null;
56 55
    private final SimpleBindings bindings = new SimpleBindings();
57
    private ScriptingHelpManager helpManager = null;
58 56
    private List<String> unitTypes = null;
59 57
    private ClassLoader classLoader = null;
60 58
    private final List<File> libFolders = new ArrayList<>();
......
105 103

  
106 104
    private void createDefaultFolders(File home) {
107 105
        createFolder(new File(home, "scripts"));
108
        createFolder(new File(home, "help"));
109 106
        createFolder(new File(home, "lib"));
110 107
        createFolder(new File(home, "data"));
111 108
    }
......
131 128
        this.addLibFolder(new File(this.home, "lib"));
132 129
    }
133 130
    
131
    @Override
134 132
    public File getDataFolder(String id) {
135 133
        File f = FileUtils.getFile(getHomeFolder(), "data",id);
136 134
        createFolder(f);
......
410 408
        return (ScriptingBaseScript) findScript(null, name);
411 409
    }
412 410

  
411
    @Override
413 412
    public Script locateScript(String name) {
414 413
        ScriptingUnit script = findScript(null, name);
415 414
        if( script instanceof Script ) {
......
565 564
    }
566 565

  
567 566
    @Override
568
    public ScriptingHelpManager getHelpManager() {
569
        if (this.helpManager == null) {
570
            this.helpManager = new DefaultScriptingHelpManager(this);
571
        }
572
        return this.helpManager;
573
    }
574

  
575
    @Override
576 567
    public ScriptingUnit createUnit(String unitType, ScriptingFolder folder, String id) {
577 568
        return createUnit(unitType, folder, id, null);
578 569
    }
......
660 651
    }
661 652

  
662 653
    @Override
663
    public ProviderFactory getHelpInstallerFactory() {
664
        return new ScriptingHelpInstallerProviderFactory();
665
    }
666

  
667
    @Override
668 654
    public File getPackagesFolder() {
669 655
        return this.packagesFolder;
670 656
    }
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingHelpManager.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4
import java.net.URL;
5
import java.util.Iterator;
6
import java.util.List;
7
import java.util.Map;
8

  
9
import javax.help.HelpSet;
10
import org.gvsig.tools.task.SimpleTaskStatus;
11

  
12
/**
13
 * This class is responsable of the management of the Help services provided to
14
 * the application.
15
 * It shows all the methods applied to the JavaDocs imported on the
16
 * ScriptingFramework
17
 * 
18
 * @see ScriptingManager
19
 */
20
public interface ScriptingHelpManager {
21

  
22
    public URL makeURL(File helpsetfolder, URL sourceurl);
23

  
24
//    /**
25
//     * Interface that represents each JavaDoc imported to the application
26
//     * 
27
//     */
28
//    public interface ScriptingHelpAPI {
29
//
30
//        /**
31
//         * Gets the JavaDoc's identificator
32
//         * 
33
//         * @return a String with the name of the JavaDoc imported identificator
34
//         */
35
//        public String getName();
36
//    }
37

  
38
    /**
39
     * Interface that represents a class contained on the JavaDocs
40
     * 
41
     */
42
    public interface ScriptingHelpClass extends Comparable {
43

  
44
        /**
45
         * Gets the name of the class
46
         * 
47
         * @return a String with the Class' name
48
         */
49
        public String getName();
50

  
51
        /**
52
         * Gets the URL of the resource that contains the JavaDoc of this class
53
         * 
54
         * @return a String with the URL.
55
         */
56
        public String getUrl();
57

  
58
        public void addMethod(String name);
59
        
60
        public List<String> getMethods();
61
        
62
    }
63

  
64
    /**
65
     * Interface that represents a method implemented by a class of the JavaDoc
66
     * 
67
     */
68
    public interface ScriptingHelpMethod extends Iterable<ScriptingHelpClass> {
69

  
70
        /**
71
         * Gets the method's name
72
         * 
73
         * @return a String with the method's name
74
         */
75
        public String getName();
76

  
77
        /**
78
         * Gets an Iterator of the {@link ScriptingHelpClass}es which implements
79
         * that method
80
         * 
81
         */
82
        @Override
83
        public Iterator<ScriptingHelpClass> iterator();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff