eclipse RCP 根据输入内容,将内容显示在编辑区中

来源:互联网 发布:软件需求分析工具 编辑:程序博客网 时间:2024/05/22 12:15
将输入流内容显示在 eclipse rcp编辑区内,输入流的内容从wsdlurl中获取String wsdlUrl = "http://fy.webxml.com.cn/webservices/EnglishChinese.asmx?wsdl";InputStream inputStream = null;IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();if (page != null) {try {inputStream = getUrlInputStream(wsdlUrl);IStorage storage = new WsdlStorage(inputStream,serviceName);IStorageEditorInput input = new WsdlEditorInput(storage);page.openEditor(input, TextEditor.ID); } catch (Exception e) {// TODO: handle exceptione.printStackTrace();}}getUrlInputStream 方法/** * 根据wsdlurl,返回网页内容 * @param wsdlUrl * @return */public static InputStream getUrlInputStream(String wsdlUrl) {InputStream inputStream = null;ByteArrayOutputStream bos = new ByteArrayOutputStream();//定义字符数组输出流对象Definition definition = null;WSDLFactory wsdlFactory = null;try {wsdlFactory = WSDLFactory.newInstance();WSDLReader reader = wsdlFactory.newWSDLReader();definition = reader.readWSDL(wsdlUrl);WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();Writer wr = new OutputStreamWriter(bos, "gbk");wsdlWriter.writeWSDL(definition, wr);inputStream = new ByteArrayInputStream(bos.toString().getBytes());} catch (WSDLException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}return inputStream;}WsdlStorage 类import java.io.InputStream;import org.eclipse.core.resources.IStorage;import org.eclipse.core.runtime.CoreException;import org.eclipse.core.runtime.IPath;import org.eclipse.core.runtime.PlatformObject;public class WsdlStorage extends PlatformObject  implements IStorage  {private InputStream inputStream;//wsdl文档对应的输入流private String  wsdlName;//wsdl对应的名字public WsdlStorage(InputStream inputStream, String wsdlName) { super();   this.inputStream = inputStream; this.wsdlName = wsdlName; }@Overridepublic Object getAdapter(Class adapter) {// TODO Auto-generated method stubreturn null;}@Overridepublic InputStream getContents() throws CoreException {// TODO Auto-generated method stubreturn inputStream;}@Overridepublic IPath getFullPath() {// TODO Auto-generated method stubreturn null;}/** * 返回在编辑中显示的名字 */@Overridepublic String getName() {// TODO Auto-generated method stubreturn wsdlName;}/** * 设置是否只读 */@Overridepublic boolean isReadOnly() {// TODO Auto-generated method stubreturn false;}}WsdlEditorInput  类import org.eclipse.core.resources.IStorage;import org.eclipse.core.runtime.CoreException;import org.eclipse.core.runtime.PlatformObject;import org.eclipse.jface.resource.ImageDescriptor;import org.eclipse.ui.IPersistableElement;import org.eclipse.ui.IStorageEditorInput;/** * 编辑区内容输入为wsdl的内容 * @author lww * */public class WsdlEditorInput extends PlatformObject  implements IStorageEditorInput {private IStorage storage;       public WsdlEditorInput(IStorage storage) {   super();       this.storage=storage;   }   @Overridepublic boolean exists() {// TODO Auto-generated method stubreturn false;}@Overridepublic ImageDescriptor getImageDescriptor() {// TODO Auto-generated method stubreturn null;}@Overridepublic String getName() {// TODO Auto-generated method stubreturn storage.getName();}@Overridepublic IPersistableElement getPersistable() {// TODO Auto-generated method stubreturn null;}@Overridepublic String getToolTipText() {// TODO Auto-generated method stubreturn "toolTip:" + storage.getName();}@Overridepublic Object getAdapter(Class adapter) {// TODO Auto-generated method stubreturn null;}@Overridepublic IStorage getStorage() throws CoreException {// TODO Auto-generated method stubreturn storage;   }}