bindeditor.java

来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 1,701 行 · 第 1/5 页

JAVA
1,701
字号
		tagcontent = clearContentHeadTail(tagcontent);
		tagcontent = replaceSeparator(tagcontent);
//		String temptag = "";
//		temptag = tagcontent;
//		for(int t = 0;t<temptag.length()-1;t++){
//			String temp = temptag;
//			if(temptag.substring(t,t+1).compareTo("\n") == 0){
//				if(t==0){
//					temptag = temptag.substring(0,t) + separator + temptag.substring(t+1,temptag.length());
//				}else{
//					temptag = temptag.substring(0,t) + "\"" + separator
//							+ "                                + \""
//							+ temptag.substring(t+1,temptag.length());
//
//				}
//				t+=3;							
//			}
//		}
		String strForReplace = "\"" + separator+ "                                + \"";
		String temptag="";
		if(tagcontent!=null && tagcontent.length()>0){
			boolean blnBeginWithEnter = false;
			if(tagcontent.substring(0,1).equals("\n")){
				temptag=tagcontent.substring(1);
				blnBeginWithEnter=true;
			}else{
				temptag=tagcontent;
			}
			
			if(blnBeginWithEnter){
				temptag=separator+temptag.replaceAll("\n",strForReplace);
			}else{
				temptag=temptag.replaceAll("\n",strForReplace);
			}
			
		}
		
		retnstr.append(temptag);
		retnstr.append("\" ;");
		retnstr.append(separator);
		retnstr.append("%>");
		retnstr.append(separator);
		retnstr.append("<%=PageBean.printLoopInfo(str");
		retnstr.append(tagname);
		retnstr.append("Template)%>");
		retnstr.append(separator);
		return retnstr.toString();
    }
    
	/**
	 * 拼出Customer绑定在JSP文??中的内容
	 * 
	 * @param tagcontent   一个Customer绑定的内容 
	 * 
	 */
    public String getCustomerComponent(String tagcontent,String tagname,int flag){
		String separator = System.getProperty("line.separator");
		StringBuffer retnstr = new StringBuffer();
		retnstr.append("<%");
		retnstr.append(separator);
		retnstr.append("    /** draw ");
		retnstr.append(tagname);
		retnstr.append(" component */");
		retnstr.append(separator);
		retnstr.append("    String str");
		retnstr.append(tagname);
		retnstr.append("Template = \"");
		tagcontent = clearContentHeadTail(tagcontent);
		tagcontent = replaceSeparator(tagcontent);
//		String temptag = "";
//		temptag = tagcontent;
//		for(int t = 0;t<temptag.length()-1;t++){
//			String temp = temptag;
//			if(temptag.substring(t,t+1).compareTo("\n") == 0){
//				if(t==0){
//					temptag = temptag.substring(0,t) + temptag.substring(t+1,temptag.length());
//				}else{
//					temptag = temptag.substring(0,t) + "\"" + separator
//							+ "                                + \"" 
//							+ temptag.substring(t+1,temptag.length());
//				}
//				t+=3;
//			}
//		}
		String strForReplace = "\"" + separator+ "                                + \"";
		String temptag="";
		if(tagcontent!=null && tagcontent.length()>0){
			boolean blnBeginWithEnter = false;
			if(tagcontent.substring(0,1).equals("\n")){
				temptag=tagcontent.substring(1);
				blnBeginWithEnter=true;
			}else{
				temptag=tagcontent;
			}
			
			if(blnBeginWithEnter){
				temptag=separator+temptag.replaceAll("\n",strForReplace);
			}else{
				temptag=temptag.replaceAll("\n",strForReplace);
			}
			
		}
		retnstr.append(temptag);
		retnstr.append("\" ;");
		retnstr.append(separator);
		retnstr.append("%>");
		retnstr.append(separator);
		retnstr.append("<%=draw");
		retnstr.append(tagname);
		retnstr.append("(PageBean, str");
		retnstr.append(tagname);
		retnstr.append("Template)%>");
		retnstr.append(separator);
		retnstr.append(separator);
		createCustomBindMethod(tagname,flag);
		return retnstr.toString();
    }
    
    /**
     * Sorts the words in parameter originalContent which is geted in the jsp file, 
     * and then update the String between the specifical targets.
     * In this way,the method update the jsp files.
     * 
     * @param  originalcontent     the content of the jsp file
     */    
    public void setjspcontent(String originalcontent){
		
        /** the new jsp content we create */
        String newcontent = "";
		String Body = "";
        /** The next two variable is used for signing up the begin offset
         *  and the end offset of the whole bind content **/
        int targetstart = 0;
        int targetend = 0;

		String separator = System.getProperty("line.separator");

		int headoffset = -1;
		int tailoffset = -1;
		int len = 0;
		try {
			headoffset = editor.getDocumentProvider().getDocument(editor.getEditorInput()).search(0,"<body",true,false,true);
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
		String editorText = editor.getDocumentProvider().getDocument(editor.getEditorInput()).get();
		if(headoffset!=-1){
			for(int i=headoffset;i<editorText.length();i++){
				if(editorText.substring(i,i+1).equals(">")){
					len = i - headoffset + 1;
					break;
				}
			}
			Body = editorText.substring(headoffset,headoffset+len);
		}
		//System.out.println(originalcontent.length());
		if(!Body.equals("")){
			int body = originalcontent.toUpperCase().indexOf("<BODY");
			for(int i=body;i<originalcontent.length();i++){
				if(originalcontent.substring(i,i+1).equals(">")){
					len = i - body + 1;
					break;
				}
			}
			originalcontent = originalcontent.substring(0,body)+ Body + originalcontent.substring(body+len,originalcontent.length());
			
		}
		boolean replace = false;
		
		
		String FileName = editor.getTitle();
//		取得当前??在编辑的html文??对应的??据对??
		int index = FileName.indexOf('.');
		String PageName = FileName.substring(0,index);
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss G E D F w W a E F");
		String mDateTime=formatter.format(cal.getTime());
		String filehead = "<%" + separator + "/**" + separator + " * @(#)" + PageName + ".jsp 1.2.0 " + mDateTime + separator + " */" + separator + "%>";
		targetstart = originalcontent.indexOf("<%-- {{ WebPumpTool( FileHeader) --%>") + 37;
		targetend = originalcontent.indexOf("<%-- }} End of WebPumpTool( FileHeader) --%>");
		if(targetstart-37 >= 0 && targetend >= 0){
			newcontent = originalcontent.substring(0,targetstart);
			newcontent += separator + filehead + separator;
			newcontent += originalcontent.substring(targetend,originalcontent.length());
		}
		if(newcontent.equals("")){
			newcontent = originalcontent;
		}
		
		//拼接生成好的Html Head 的JSP内容
		targetstart = newcontent.indexOf("<%-- {{ WebPumpTool( outBodyHeader) --%>") + 40;
		targetend = newcontent.indexOf("<%-- }} End of WebPumpTool( outBodyHeader) --%>");
		if(targetstart-40 >= 0 && targetend >= 0){
			String temp = newcontent;
			newcontent = temp.substring(0,targetstart);
			newcontent += replaceAll(m_strJSP_htmlheader);
			if(m_strJSP_htmlheader.equals("")){
				newcontent += separator;
			}
			newcontent += temp.substring(targetend,temp.length());
		}
		
        //拼接生成好的Html Script 的JSP内容
		targetstart = newcontent.indexOf("<%-- {{ WebPumpTool( outputScript) --%>") + 39;
		targetend = newcontent.indexOf("<%-- }} End of WebPumpTool( outputScript) --%>");
		if(targetstart-39 >= 0 && targetend >= 0){
			String temp = newcontent;
			newcontent = temp.substring(0,targetstart);
			newcontent += replaceAll(m_strJSP_htmlscript);
			if(m_strJSP_htmlscript.equals("")){
				newcontent += separator;
			}
			newcontent += temp.substring(targetend,temp.length());
		}
        //拼接生成好的Html Style 的JSP内容
		targetstart = newcontent.indexOf("<%-- {{ WebPumpTool( outputStyle) --%>") + 38;
		targetend = newcontent.indexOf("<%-- }} End of WebPumpTool( outputStyle) --%>");
		if(targetstart-38 >= 0 && targetend >= 0){
			String temp = newcontent;
			newcontent = temp.substring(0,targetstart);
			newcontent += replaceAll(m_strJSP_htmlstyle);
			if(m_strJSP_htmlstyle.equals("")){
				newcontent += separator;
			}
			newcontent += temp.substring(targetend,temp.length());
		}
		//拼接生成好的Html Body 的JSP内容
		StringBuffer tempbuf = new StringBuffer();
		targetstart = newcontent.indexOf("<%-- {{ WebPumpTool( drawScene) --%>") + 36;
		targetend = newcontent.indexOf("<%-- }} End of WebPumpTool( drawScene) --%>");
		if(targetstart-36 >= 0 && targetend >= 0){
//			String temp = newcontent;
			tempbuf.append(newcontent.substring(0,targetstart));
			tempbuf.append(replaceAll(m_strJSP_htmlbody));
			if(m_strJSP_htmlbody.equals("")){
				tempbuf.append(separator);
			}
			tempbuf.append(newcontent.substring(targetend,newcontent.length()));
			newcontent = tempbuf.toString(); 
		}
		//拼接生成好的Html Tail Script 的JSP内容
		targetstart = newcontent.indexOf("<%-- {{ WebPumpTool( outputScriptAtTail) --%>") + 45;
		targetend = newcontent.indexOf("<%-- }} End of WebPumpTool( outputScriptAtTail) --%>");
		if(targetstart-45 >= 0 && targetend >= 0){
			String temp = newcontent;
			newcontent = temp.substring(0,targetstart);
			newcontent += replaceAll(m_strJSP_htmltail);
			if(m_strJSP_htmltail.equals("")){
				newcontent += separator;
			}
			newcontent += temp.substring(targetend,temp.length());
		}
		
		//拼接生成好的Customer Bind的java script Function
		targetstart = newcontent.indexOf("<%-- {{ WebPumpTool( outputCustomAtTail) --%>") + 45;
		targetend = newcontent.indexOf("<%-- }} End of WebPumpTool( outputCustomAtTail) --%>");
		if(targetstart-45 >= 0 && targetend >= 0){
			String temp = newcontent;
			newcontent = temp.substring(0,targetstart);
			boolean hasCustomBind = false;
			if(!m_strCustomBindMethod.equals("")){
				newcontent += separator + m_strCustomBindMethod + separator;
				hasCustomBind = true;
			}
			if(!m_strCustomBindMethod_2.equals("")){
				newcontent += separator + m_strCustomBindMethod_2 + separator;
				hasCustomBind = true;
			}
			if(!m_strCustomBindMethod_3.equals("")){
				newcontent += separator + m_strCustomBindMethod_3 + separator;
				hasCustomBind = true;
			}
			if(!m_strCustomBindMethod_4.equals("")){
				newcontent += separator + m_strCustomBindMethod_4 + separator;
				hasCustomBind = true;
			}
			if(!m_strCustomBindMethod_5.equals("")){
				newcontent += separator + m_strCustomBindMethod_5 + separator;
				hasCustomBind = true;
			}
			if(!hasCustomBind){
				newcontent += separator;
			}
			newcontent += temp.substring(targetend,temp.length());
			m_strCustomBindMethod = "";
			m_strCustomBindMethod_2 = "";
			m_strCustomBindMethod_3 = "";
			m_strCustomBindMethod_4 = "";
			m_strCustomBindMethod_5 = "";
		}

        /** set the m_strJSPFileContent with the newcontent */
        m_strJSPFileContent = newcontent;
    }
    
	/**
	 * get the content of the file show with the parameter Path
	 * 
	 * @param  Path     the path of the file which content we want to get
	 */ 
	public String getcontent(IPath Path,String tag){
		String content = "";
		try
		{
			FileInputStream filestream;
			byte byteBuffer[];
			int segcount = Path.segmentCount();
			int seg = 0;
			for(int i =0;i<segcount;i++){
				if(Path.segment(i).equals(tag)){
					seg = i+2;
					break;
				}
			}
			String modulename = "/" + Path.segment(seg-1);
			String packagename = "/" + Path.segment(seg+1);
			String filename = "/" + Path.lastSegment();
			IPath ProjectPath = Path.removeLastSegments(segcount-seg+2);
			ProjectModel projectModel = WebpumpIDEPlugin.getProjectModel(m_objhtmlfile,false);
			ProjectInfo projectInfo = (ProjectInfo)projectModel.getDataObject();
			m_Charset = projectInfo.getProjectInfo()[5];
			
			/** to get the file content as a FileInputSteam with the Path */
			filestream = new FileInputStream(Path.toString());
			byteBuffer = new byte[filestream.available()];
			filestream.read(byteBuffer, 0,filestream.available());
			filestream.close();
			/** to get content in the style of string */
            content = new String(byteBuffer, m_Charset);
		}catch (Exception e){
			e.printStackTrace();
		}
		return content;
	}
    
    /**
     * Get BindParasXMLFile
     * 
     * @return
     */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?