|
From: <de...@us...> - 2016-02-15 21:57:58
|
Revision: 9273
http://sourceforge.net/p/fudaa/svn/9273
Author: deniger
Date: 2016-02-15 21:57:56 +0000 (Mon, 15 Feb 2016)
Log Message:
-----------
CRUE-689
Modified Paths:
--------------
trunk/soft/fudaa-crue/ui-sysdoc/src/main/java/org/fudaa/fudaa/crue/sysdoc/services/SysdocService.java
Modified: trunk/soft/fudaa-crue/ui-sysdoc/src/main/java/org/fudaa/fudaa/crue/sysdoc/services/SysdocService.java
===================================================================
--- trunk/soft/fudaa-crue/ui-sysdoc/src/main/java/org/fudaa/fudaa/crue/sysdoc/services/SysdocService.java 2016-02-15 21:57:42 UTC (rev 9272)
+++ trunk/soft/fudaa-crue/ui-sysdoc/src/main/java/org/fudaa/fudaa/crue/sysdoc/services/SysdocService.java 2016-02-15 21:57:56 UTC (rev 9273)
@@ -37,203 +37,215 @@
* @author Frederic Deniger
*/
@ServiceProviders(value = {
- @ServiceProvider(service = Help.class, supersedes = {"org.netbeans.modules.javahelp.JavaHelp"}),
- @ServiceProvider(service = SysdocService.class),
- @ServiceProvider(service = SysdocContrat.class)})
-public class SysdocService extends Help implements SysdocContrat {
+ @ServiceProvider(service = Help.class, supersedes = {"org.netbeans.modules.javahelp.JavaHelp"}),
+ @ServiceProvider(service = HelpCtx.Displayer.class),
+ @ServiceProvider(service = SysdocService.class),
+ @ServiceProvider(service = SysdocContrat.class)})
+public class SysdocService extends Help implements SysdocContrat, HelpCtx.Displayer {
- private InstallationService installationService = Lookup.getDefault().lookup(InstallationService.class);
- private ConfigurationManagerService configurationManagerService = Lookup.getDefault().lookup(ConfigurationManagerService.class);
+ private InstallationService installationService = Lookup.getDefault().lookup(InstallationService.class);
+ private ConfigurationManagerService configurationManagerService = Lookup.getDefault().lookup(ConfigurationManagerService.class);
- private static HashMap<String, String> helpIdLink = null;
- private static final String DEFAULT_LINK = "DEFAUT";
- private static final String HTMLCode = "<!DOCTYPE HTML>\n"
- + "<html>\n"
- + " <head>\n"
- + " <meta charset=\"UTF-8\">\n"
- + " <meta http-equiv=\"refresh\" content=\"1;url=@@URL@@\">\n"
- + " <title>Fudaa Crue</title>\n"
- + " </head>\n"
- + " <body>\n"
- + " Suivez ce lien pour afficher la documentation <a href='@@URL@@'>Aide FudaaCrue</a>\n"
- + " </body>\n"
- + "</html>";
+ private static HashMap<String, String> helpIdLink = null;
+ private static final String DEFAULT_LINK = "DEFAUT";
+ private static final String HTML_CODE = "<!DOCTYPE HTML>\n" + "<html>\n"
+ + " <head>\n"
+ + " <meta charset=\"UTF-8\">\n"
+ + " <meta http-equiv=\"refresh\" content=\"1;url=@@URL@@\">\n"
+ + " <title>Fudaa Crue</title>\n"
+ + " </head>\n"
+ + " <body>\n"
+ + " Suivez ce lien pour afficher la documentation <a href='@@URL@@'>Aide FudaaCrue</a>\n"
+ + " </body>\n"
+ + "</html>";
- /**
- * Construit l'URL pour accéder à l'aide en ligne
- *
- * @param HelpId
- * @return
- */
- public String getHelpURL(String HelpId) {
- String locale = configurationManagerService.getCurrentLocale();
- String path = String.format(configurationManagerService.getOptionsManager().getAideOption().getCheminBase(), locale);
+ /**
+ * Construit l'URL pour accéder à l'aide en ligne
+ *
+ * @param HelpId
+ * @return
+ */
+ public String getHelpURL(String HelpId) {
+ String locale = configurationManagerService.getCurrentLocale();
+ String path = String.format(configurationManagerService.getOptionsManager().getAideOption().getCheminBase(), locale);
- if (configurationManagerService.getOptionsManager().getAideOption().getType().equals(AideEnum.RELATIVE.toString())) {
- try {
+ if (configurationManagerService.getOptionsManager().getAideOption().getType().equals(AideEnum.RELATIVE.toString())) {
+ try {
- File pathSiteDir = installationService.getSiteDir();
- //Recherche du lecteur
- String drive = "";
- if (pathSiteDir.getCanonicalPath().length() > 1 && pathSiteDir.getCanonicalPath().charAt(1) == ':') {
- drive = pathSiteDir.getCanonicalPath().substring(0, 1);
- }
- //drive = "P";
- //Commande Net Use pour recuperer le nom du serveur pour generer le chemin UNC
- String[] command = new String[3];
- command[0] = "net";
- command[1] = "use";
- command[2] = drive + ":";
- Process p = Runtime.getRuntime().exec(command);
+ File pathSiteDir = installationService.getSiteDir();
+ //Recherche du lecteur
+ String drive = "";
+ if (pathSiteDir.getCanonicalPath().length() > 1 && pathSiteDir.getCanonicalPath().charAt(1) == ':') {
+ drive = pathSiteDir.getCanonicalPath().substring(0, 1);
+ }
+ //drive = "P";
+ //Commande Net Use pour recuperer le nom du serveur pour generer le chemin UNC
+ String[] command = new String[3];
+ command[0] = "net";
+ command[1] = "use";
+ command[2] = drive + ":";
+ Process p = Runtime.getRuntime().exec(command);
- BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
- String lineErr = "";
- while ((lineErr = err.readLine()) != null) {
- System.out.println(lineErr);
- }
+ BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+ String lineErr = "";
+ while ((lineErr = err.readLine()) != null) {
+ System.out.println(lineErr);
+ }
- BufferedReader read = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ BufferedReader read = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String netPath = "";
- try {
- String line = read.readLine();
+ String netPath = "";
+ try {
+ String line = read.readLine();
- while (line != null) {
- if (line.contains("\\\\")) {
- netPath = line.substring(line.indexOf("\\\\")).substring(2);
- break;
- }
- line = read.readLine();
- }
- } finally {
- read.close();
- }
- path = "/" + path;
- if (netPath.length() > 0) {
- String pathConv = installationService.getSiteDir().getCanonicalPath().replace(drive + ":", netPath);
- if ((System.getenv("USERDNSDOMAIN") != null && System.getenv("USERDOMAIN") != null) && pathConv.toLowerCase().contains(System.getenv("USERDNSDOMAIN").toLowerCase())) {
- pathConv = pathConv.toLowerCase().replace(System.getenv("USERDNSDOMAIN").toLowerCase(), System.getenv("USERDOMAIN"));
- }
- path = "file://" + pathConv + path + getLink(HelpId);
- } else {
- path = "file://" + installationService.getSiteDir().getCanonicalPath() + path + getLink(HelpId);
- }
- path = path.replace("\\", "/");
- } catch (IOException ex) {
- Exceptions.printStackTrace(ex);
+ while (line != null) {
+ if (line.contains("\\\\")) {
+ netPath = line.substring(line.indexOf("\\\\")).substring(2);
+ break;
}
+ line = read.readLine();
+ }
+ } finally {
+ read.close();
+ }
+ path = "/" + path;
+ if (netPath.length() > 0) {
+ String pathConv = installationService.getSiteDir().getCanonicalPath().replace(drive + ":", netPath);
+ if ((System.getenv("USERDNSDOMAIN") != null && System.getenv("USERDOMAIN") != null) && pathConv.toLowerCase().contains(System.getenv(
+ "USERDNSDOMAIN").toLowerCase())) {
+ pathConv = pathConv.toLowerCase().replace(System.getenv("USERDNSDOMAIN").toLowerCase(), System.getenv("USERDOMAIN"));
+ }
+ path = "file://" + pathConv + path + getLink(HelpId);
} else {
- path = path + getLink(HelpId);
+ path = "file://" + installationService.getSiteDir().getCanonicalPath() + path + getLink(HelpId);
}
-
- return path;
+ path = path.replace("\\", "/");
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ } else {
+ path = path + getLink(HelpId);
}
- /**
- * Fournit le lien correspondant à l'ID interne FudaaCrue
- *
- * @param HelpId
- * @return
- */
- private String getLink(String HelpId) {
- String link = "";
- if (helpIdLink == null) {
- helpIdLink = configurationManagerService.readAide();
- }
+ return path;
+ }
- if (helpIdLink != null && helpIdLink.containsKey(HelpId)) {
- link = helpIdLink.get(HelpId);
- } else if (helpIdLink != null && helpIdLink.containsKey(DEFAULT_LINK)) {
- link = helpIdLink.get(DEFAULT_LINK);
- }
- return link;
+ /**
+ * Fournit le lien correspondant à l'ID interne FudaaCrue
+ *
+ * @param HelpId
+ * @return
+ */
+ private String getLink(String HelpId) {
+ String link = "";
+ if (helpIdLink == null) {
+ helpIdLink = configurationManagerService.readAide();
}
- @Override
- public Boolean isValidID(String string, boolean bln) {
- return Boolean.TRUE;
+ if (helpIdLink != null && helpIdLink.containsKey(HelpId)) {
+ link = helpIdLink.get(HelpId);
+ } else if (helpIdLink != null && helpIdLink.containsKey(DEFAULT_LINK)) {
+ link = helpIdLink.get(DEFAULT_LINK);
}
+ return link;
+ }
- @Override
- public void showHelp(HelpCtx hc, boolean bln) {
- display(hc.getHelpID());
+ @Override
+ public Boolean isValidID(String string, boolean bln) {
+ return Boolean.TRUE;
+ }
- }
+ @Override
+ public void showHelp(HelpCtx hc, boolean bln) {
+ display(hc.getHelpID());
+ }
- @Override
- public void addChangeListener(ChangeListener cl) {
- }
+ @Override
+ public boolean display(HelpCtx help) {
+ display(help.getHelpID());
+ return true;
+ }
- @Override
- public void removeChangeListener(ChangeListener cl) {
- }
+ @Override
+ public void showHelp(HelpCtx ctx) {
+ super.showHelp(ctx);
+ }
- @Override
- public void display(String path) {
+ @Override
+ public void addChangeListener(ChangeListener cl) {
+ }
- if (configurationManagerService.getOptionsManager().getAideOption().getSyDocActivation()) {
- String lienHelp = getLink(path);
- SysdocTopComponent findTopComponent = (SysdocTopComponent) WindowManager.getDefault().findTopComponent(SysdocTopComponent.TOPCOMPONENT_ID);
- if (lienHelp != null) {
- findTopComponent.display(lienHelp);
- }
- if (!findTopComponent.isOpened()) {
- findTopComponent.open();
- }
- findTopComponent.requestActive();
- } else {
- try {
- String pageRedirection = HTMLCode.replaceAll("@@URL@@", this.getHelpURL(path));
- if (installationService.getUserDir() != null) {
- File userDirectory = Places.getUserDirectory();
- FileUtils.writeStringToFile(new File(userDirectory.getCanonicalPath() + "/var/temp/aide.htm"), pageRedirection);
- URL HelpUrl = new URL("file:///" + userDirectory.getCanonicalPath() + "/var/temp/aide.htm");
- Desktop.getDesktop().browse(HelpUrl.toURI());
- } else {
- Logger.getLogger(SysdocService.class.getName()).log(Level.WARNING, "Repertoire utilisateur non défini.");
- }
- } catch (Exception ex) {
- Exceptions.printStackTrace(ex);
- }
- }
- }
+ @Override
+ public void removeChangeListener(ChangeListener cl) {
+ }
- @Override
- @Messages("Sysdoc.DisplayMediaNotFound=Le m\u00e9dia n''est pas trouv\u00e9. Chemin: {0}")
- public void displayMedia(String helpUrl) {
- if (helpUrl.startsWith("http")) {
- try {
- Desktop.getDesktop().browse(new URI(helpUrl));
- } catch (Exception ex) {
- Exceptions.printStackTrace(ex);
- }
- return;
- }
- File sysdocLocaleDir = getSysdocLocalizedDir();
- File target = new File(sysdocLocaleDir, helpUrl);
- if (!target.exists()) {
- DialogHelper.showError(Sysdoc_DisplayMediaNotFound(target.getAbsolutePath()));
+ @Override
+ public void display(String path) {
+
+ if (configurationManagerService.getOptionsManager().getAideOption().getSyDocActivation()) {
+ String lienHelp = getLink(path);
+ SysdocTopComponent findTopComponent = (SysdocTopComponent) WindowManager.getDefault().findTopComponent(SysdocTopComponent.TOPCOMPONENT_ID);
+ if (lienHelp != null) {
+ findTopComponent.display(lienHelp);
+ }
+ if (!findTopComponent.isOpened()) {
+ findTopComponent.open();
+ }
+ findTopComponent.requestActive();
+ } else {
+ try {
+ String pageRedirection = HTML_CODE.replaceAll("@@URL@@", this.getHelpURL(path));
+ if (installationService.getUserDir() != null) {
+ File userDirectory = Places.getUserDirectory();
+ FileUtils.writeStringToFile(new File(userDirectory.getCanonicalPath() + "/var/temp/aide.htm"), pageRedirection);
+ URL HelpUrl = new URL("file:///" + userDirectory.getCanonicalPath() + "/var/temp/aide.htm");
+ Desktop.getDesktop().browse(HelpUrl.toURI());
} else {
- try {
- Desktop.getDesktop().open(target);
- } catch (IOException ex) {
- Logger.getLogger(SysdocService.class.getName()).log(Level.WARNING, "message {0}", ex);
- }
+ Logger.getLogger(SysdocService.class.getName()).log(Level.WARNING, "Repertoire utilisateur non défini.");
}
+ } catch (Exception ex) {
+ Exceptions.printStackTrace(ex);
+ }
}
+ }
- public File getSysdocLocalizedDir() {
- File sysdocBaseDir = new File(configurationManagerService.getCoeurManager().getSiteDir(), "sydoc");
- String local = configurationManagerService.getCurrentLocale();
- File sysdocLocaleDir = new File(sysdocBaseDir, local);
- return sysdocLocaleDir;
+ @Override
+ @Messages("Sysdoc.DisplayMediaNotFound=Le m\u00e9dia n''est pas trouv\u00e9. Chemin: {0}")
+ public void displayMedia(String helpUrl) {
+ if (helpUrl.startsWith("http")) {
+ try {
+ Desktop.getDesktop().browse(new URI(helpUrl));
+ } catch (Exception ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return;
}
+ File sysdocLocaleDir = getSysdocLocalizedDir();
+ File target = new File(sysdocLocaleDir, helpUrl);
+ if (!target.exists()) {
+ DialogHelper.showError(Sysdoc_DisplayMediaNotFound(target.getAbsolutePath()));
+ } else {
+ try {
+ Desktop.getDesktop().open(target);
+ } catch (IOException ex) {
+ Logger.getLogger(SysdocService.class.getName()).log(Level.WARNING, "message {0}", ex);
+ }
+ }
+ }
- @Override
- /*
+ public File getSysdocLocalizedDir() {
+ File sysdocBaseDir = new File(configurationManagerService.getCoeurManager().getSiteDir(), "sydoc");
+ String local = configurationManagerService.getCurrentLocale();
+ File sysdocLocaleDir = new File(sysdocBaseDir, local);
+ return sysdocLocaleDir;
+ }
+
+ @Override
+ /*
* Flag permettant de connaitre l'activation ou non de SyDoc
- */
- public boolean isSyDocActivated() {
- return configurationManagerService.getOptionsManager().getAideOption().getSyDocActivation();
- }
+ */
+ public boolean isSyDocActivated() {
+ return configurationManagerService.getOptionsManager().getAideOption().getSyDocActivation();
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|