Modidy a package name of nemo
[nemo.git] / nemo-tools / eclipse-plugin / nemo-rest / org.opendaylight.nemo.tool.eclipse.plugin.rest / src / org / opendaylight / nemo / tool / eclipse / plugin / rest / collectinfo / GetContent.java
1 package org.opendaylight.nemo.tool.eclipse.plugin.rest.collectinfo;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7
8 import org.eclipse.core.resources.IFile;
9 import org.eclipse.core.runtime.CoreException;
10 import org.eclipse.core.runtime.Platform;
11 import org.eclipse.ui.IEditorInput;
12 import org.eclipse.ui.IEditorPart;
13 import org.eclipse.ui.PlatformUI;
14 import org.eclipse.ui.part.FileEditorInput;
15
16 public class GetContent {
17
18         public static String activeContent() {
19                 IEditorPart aditorPart = PlatformUI.getWorkbench()
20                                 .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
21                 if (aditorPart == null) {
22                         return null;
23                 }
24                 String result = null;
25                 IEditorInput input = aditorPart.getEditorInput();
26                 if (input instanceof FileEditorInput) {
27                         IFile file = ((FileEditorInput) input).getFile();
28                         String name = file.getName();
29                         if (!name.endsWith(".nemo")) {
30                                 return null;
31                         }
32                         try {
33                                 InputStream is = file.getContents();
34                                 result = getContent(is);
35                         } catch (CoreException e) {
36                                 // TODO Auto-generated catch block
37                                 e.printStackTrace();
38                         }
39                 }
40                 return result;
41         }
42
43         private static String getContent(InputStream input) {
44                 BufferedReader br = null;
45                 StringBuilder builder = new StringBuilder();
46
47                 String line;
48                 try {
49                         br = new BufferedReader(new InputStreamReader(input));
50                         while ((line = br.readLine()) != null) {
51                                 if(line.indexOf("//")>=0)
52                                         line = line.substring(0,line.indexOf("//"));
53                                 line = line.replaceAll("\"", " ");
54                                 String ss[] = line.split(" ");
55                                 line = "";
56                                 for(String s:ss){
57                                         if(!s.trim().equals("")){
58                                                 line += (" "+s.trim());
59                                         }
60                                 }
61                                 if (!line.trim().equals(""))
62                                         builder.append(line);
63                         }
64                 } catch (IOException e) {
65                         e.printStackTrace();
66                 } finally {
67                         if (br != null) {
68                                 try {
69                                         br.close();
70                                 } catch (IOException e) {
71                                         e.printStackTrace();
72                                 }
73                         }
74                 }
75
76                 return builder.toString();
77         }
78 }