IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Eclipse Platform Discussion :

lire un fichier qui est dans un plugin


Sujet :

Eclipse Platform

  1. #1
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Points : 2 336
    Points
    2 336
    Par défaut lire un fichier qui est dans un plugin
    Hello,

    Je cherche à lire un fichier qui est stocké dans un de mes plugin, malheureusement celui-ci n'est pas trouvé lors de l'execution

    voici le code utilisé

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     
    	/** The platform-relative path to the resources. */
    	private static final String RESOURCES_PATH = "platform:/plugin/com.odcgroup.page.common/src/main/resources";
     
    	/** The page footer filer. */
    	private static final String FOOTER_FILE = RESOURCES_PATH + "/" + "tableFooter.xml";
     
    	/**  
             * Builds the xsp:logic section and it's children.
             * 
             * @param context
             *                      The WidgetTransformerContext
             * @param widget
             *                      The widget
             * @param parent
             *                      The parent element 
             */
    	private void buildXspLogic(WidgetTransformerContext context, Widget widget, Element parent) {
    		Element xspLogic = appendElement(context,parent, XSPConstants.XSP_NAMESPACE_URI, XSPConstants.XSP_LOGIC);
    		StringBuffer condition = new StringBuffer();
    		IPath path = new Path(FOOTER_FILE);
    		IFile file =ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
    		try {
    			InputStream inputStream = file.getContents();
    			char c;
    			while((c = (char) inputStream.read()) != -1) {
    	            condition.append(c);
    			}
    			inputStream.close();
    			xspLogic.setTextContent(inputStream.toString());
    		}catch (Exception ex) {
    			Logger.error("Exception while reading the page footer file ",ex);
    		}
     
    	}

  2. #2
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Points : 2 336
    Points
    2 336
    Par défaut
    finalement la solution :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
     
    	/** The platform-relative path to the resources. */
    	private static final String RESOURCES_PATH = "src/main/resources";
     
    	/** The page footer filer. */
    	private static final String FOOTER_FILE = RESOURCES_PATH + "/" + "tableFooter.xml";
     
    	/**
             * Loads the text related to paging. This includes the buttons and actions.
             * 
             * @return String
             */
     
    	private String loadPageSizeText() {
    		LineInputStream stream  = null;
    		try {
    			StringBuffer condition = new StringBuffer();
    			IPath path = new Path(FOOTER_FILE);
    			stream = new LineInputStream(FileLocator.openStream(Activator.getDefault().getBundle(), path, false));
     
    			String s;
    			while ((s = stream.readLine()) != null) {
    				condition.append(s);
    				condition.append("\n");
    			}
    			return condition.toString();
    		}catch (Exception ex) {
    			Logger.error("Exception while reading the page footer file ", ex);
    			return "";
    		} finally {
    			try {
    				stream.close();
    			} catch(IOException e) {
    				// ignored
    			}
    		}
    	}

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 7
    Dernier message: 17/04/2013, 22h26
  2. Réponses: 2
    Dernier message: 06/03/2008, 21h20
  3. Réponses: 2
    Dernier message: 03/10/2007, 16h45
  4. Lire un fichier qui ne se trouve pas dans la webapps
    Par sorilazer dans le forum Servlets/JSP
    Réponses: 5
    Dernier message: 31/08/2007, 13h48
  5. [JAVA] Appeller fonction qui est dans un autre fichier
    Par Aspic dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 15/05/2007, 21h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo