1) Fixed issue #347: Syntax highlight doesn't like apostrophe in heredoc.
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpeclipse / externaltools / PHPConsole.java
1 package net.sourceforge.phpeclipse.externaltools;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5
6 //import org.eclipse.swt.graphics.Color;
7 import org.eclipse.ui.console.ConsolePlugin;
8 import org.eclipse.ui.console.IConsole;
9 import org.eclipse.ui.console.MessageConsole;
10 import org.eclipse.ui.console.MessageConsoleStream;
11
12 public class PHPConsole {
13         private MessageConsole myConsole;
14
15         private MessageConsoleStream stream;
16
17         //private boolean hasMessages;
18
19         public PHPConsole() {
20                 //hasMessages = false;
21                 myConsole = new MessageConsole("PHPeclipse Console", null);
22                 ConsolePlugin.getDefault().getConsoleManager().addConsoles(
23                                 new IConsole[] { myConsole });
24                 ConsolePlugin.getDefault().getConsoleManager().showConsoleView(
25                                 myConsole);
26                 // layout.addView(IConsoleConstants.ID_CONSOLE_VIEW, IPageLayout.BOTTOM,
27                 // .5f,IPageLayout.ID_EDITOR_AREA);
28                 stream = myConsole.newMessageStream();
29         }
30
31         /**
32          * @return
33          */
34 //      public Color getColor() {
35 //              return stream.getColor();
36 //      }
37
38         /**
39          * @return
40          */
41         public MessageConsole getConsole() {
42                 return stream.getConsole();
43         }
44
45         /*
46          * (non-Javadoc)
47          * 
48          * @see java.lang.Object#hashCode()
49          */
50         public int hashCode() {
51                 return stream.hashCode();
52         }
53
54         /**
55          * @param message
56          */
57         public void print(String message) {
58                 //hasMessages = true;
59                 stream.print(message);
60         }
61
62         /**
63          * 
64          */
65 //      public void println() {
66 //              //hasMessages = true;
67 //              stream.println();
68 //      }
69
70         /**
71          * @param message
72          */
73         public void println(String message) {
74                 //hasMessages = true;
75                 stream.println(message);
76         }
77
78         /**
79          * @param color
80          */
81 //      public void setColor(Color color) {
82 //              stream.setColor(color);
83 //      }
84
85         // public void reportError(String title, String message) {
86         // if (hasMessages) {
87         // WikiEditorPlugin.getDefault().reportError(title, message);
88         // }
89         // }
90
91         // public void reportError() {
92         // reportError("Problems listed", "Open console view for problems log!");
93         // }
94         /**
95          * Creates a string buffer from the given input stream
96          */
97         public static String getStringFromStream(InputStream stream)
98                         throws IOException {
99                 StringBuffer buffer = new StringBuffer();
100                 byte[] b = new byte[100];
101                 int finished = 0;
102                 while (finished != -1) {
103                         finished = stream.read(b);
104                         if (finished != -1) {
105                                 String current = new String(b, 0, finished);
106                                 buffer.append(current);
107                         }
108                 }
109                 return buffer.toString();
110         }
111 }