1 package org.opendaylight.nemo.tool.eclipse.plugin.rest.collectinfo;
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
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;
16 public class GetContent {
18 public static String activeContent() {
19 IEditorPart aditorPart = PlatformUI.getWorkbench()
20 .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
21 if (aditorPart == 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")) {
33 InputStream is = file.getContents();
34 result = getContent(is);
35 } catch (CoreException e) {
36 // TODO Auto-generated catch block
43 private static String getContent(InputStream input) {
44 BufferedReader br = null;
45 StringBuilder builder = new StringBuilder();
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(" ");
57 if(!s.trim().equals("")){
58 line += (" "+s.trim());
61 if (!line.trim().equals(""))
64 } catch (IOException e) {
70 } catch (IOException e) {
76 return builder.toString();