bindeditor.java

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

JAVA
1,701
字号
    }
    
    /**
     * Sorts the words in the parameter sorttag, 
     * and replace the bind tag "##" with the String of get/set method which
     * is declared in the file of formbean.java.
     * 
     * @param  sorttag   the string need to be sorted
     */
    
	String dosortJSPWords(String sorttag){
		String paramName = "";
		String bindParamName = "";
		
		/** marker which sign that weather the parameter need filter*/
		String FileName = editor.getTitle();
//		取得当前??在编辑的html文??对应的??据对??
		int index = FileName.indexOf('.');
		m_strPageName = FileName.substring(0,index);		
		Model objModel = WebpumpIDEPlugin.getModelFromHtml(m_objhtmlfile,false);
		Modules objModules = (Modules)objModel.getDataObject();
		Vector vPages = objModules.getPages().getPage();
		boolean formtype = false;
		for(int i=0;i<vPages.size();i++){
			String PageName = m_strPageName;
			Page objCurrentPage = (Page)vPages.get(i);
			if(PageName.equals(objCurrentPage.getPageName())){
				if(objCurrentPage.getFormType().equals("Static")){
					formtype = true;
				}
				break;
			}
		}		
				
		int filter = 0;
		boolean isBind = true; 
		boolean isCombobox = false;
		          
        /** to get parameters information of this page in BindParameters.xml */
        Vector vParameterInfo = m_objHtmlPage.getvParameterInfo();
        /** to search the BindParameters.xml for this parameter and get the filter information of it */
        ParameterInfo objParameterInfo = null;
        for (int k = 0;k < vParameterInfo.size();k++ ){
            objParameterInfo = (ParameterInfo) vParameterInfo.get(k);
            String parameterName = objParameterInfo.getParamsInfo()[1];
            String parameterType = objParameterInfo.getParamsInfo()[5];
            if(parameterType.equals("Combobox")){
                isCombobox = true;
            }else{
                isCombobox = false;
            }            

            if(objParameterInfo.getParamsInfo()[8].compareTo("true") == 0){
                filter = 1;
            }else{
                filter = 0;
            }
            
            String strParameterValue = "##"+parameterName+"##";
              
            String strFunction = jspParamBind(isBind,filter,isCombobox,formtype,parameterName);
            sorttag = sorttag.replaceAll(strParameterValue,strFunction);
        }            


        return sorttag;
	}
   
	/**
	 * 拼接JSP文??中的绑定变量的get方法
	 * 
	 * @param isBind 是否绑定
	 * @param filter 是???滤
	 * @param isCombobox 是否Combobox对??
	 * @param formtype form的类型
	 * @param bindParamName 绑定变量的名字
	 * 
	 */   
	public String jspParamBind(boolean isBind,int filter,boolean isCombobox,boolean formtype,String bindParamName){
		StringBuffer tempbuf = new StringBuffer();
		if(isBind == true){
			String tempbindParamName = bindParamName.substring(0,1).toUpperCase()+bindParamName.substring(1,bindParamName.length());
			/** with the filter information to create the string of get function for the param*/
			if(filter == 1&&!isCombobox){
				tempbuf.append("<%=PageBean.filter(PageBean.get");
				if(!formtype){
					tempbuf.append("(\"" + bindParamName + "\"))%>");//替换偶??##
				}else{
					tempbuf.append(tempbindParamName);//获得偶??##前的字符串?即绑定内容
					tempbuf.append("())%>");//替换偶??##
				}
			}
			if(filter == 0||isCombobox){
				tempbuf.append("<%=PageBean.get");//替换单??##
				if(!formtype){
					tempbuf.append("(\"" + bindParamName + "\")%>");//替换偶??##
				}else{
					tempbuf.append(tempbindParamName);//获得偶??##前的字符串?即绑定内容
					tempbuf.append("()%>");//替换偶??##
				}              
			} 
		}
		if(isBind == false){
			tempbuf.append("##");
			tempbuf.append(bindParamName);//获得偶??##前的字符串?即绑定内容
			tempbuf.append("##");//替换偶??##
		}
		return tempbuf.toString();
	}

    /**
     * Sorts the words in parameter originalContent 
     * which is the HTMLBODY binding content get in the "HTML绑定编辑" page(page 0 of the BindEditor), 
     * and then create a newcontent which can be used in the jsp files.
     * 
     * @param originalContent   the string we used for content create 
     */
	public String createBodyContent(String originalContent,int flag){
		StringBuffer tempbuf = new StringBuffer();
		String separator = System.getProperty("line.separator");
		int separatorlength = separator.length();
		int nNameIndex=0;
//		int nTypeIndex=0;
		String strTemp="";
		
		/** the name of the inner bind */
		String tagname = "";
		/** the type of the inner bind */
		String tagtype = "";
		/** the content of the inner bind target */
		String tagcontent = "";
        
        String []temp = originalContent.split("\" -->");
        if(temp.length == 1){
			tempbuf.append(dosortJSPWords(originalContent));
        }else{
			for(int i = 0;i < temp.length;i++){
				if(i == 0){
					tempbuf.append(dosortJSPWords(temp[i].substring(0,temp[i].indexOf("<!--WEBPUMPCOMPONET"))));
					nNameIndex=temp[i].indexOf("NAME=\""+m_strPageName)+6;
					strTemp=temp[i].substring(nNameIndex);
					tagname = strTemp.substring(0,strTemp.indexOf("\" TYPE=\""));
					strTemp=strTemp.substring(tagname.length()+8);
					tagtype = strTemp.substring(0,strTemp.length());
				}
				/** another detect of the inner bind */
				else{
					tagcontent = temp[i].substring(0,temp[i].indexOf("<!--/"));
					tagcontent = modifyTagContent(tagcontent);
					/** to treat the inner bind content with it's type */
					if(tagtype.compareTo("FirstErrorComponent") == 0){
							tempbuf.append("<%=ErrorBean.getFirstErrorMessage(request)%>");
							tempbuf.append(separator);
					}else if(tagtype.compareTo("AllErrorComponent") == 0){
							tempbuf.append("<%=ErrorBean.getAllErrorMessages(request)%>");
							tempbuf.append(separator);
					}else if(tagtype.compareTo("SingleErrorComponent") == 0&&tagcontent.length()>3){
							tempbuf.append(getSingleErrorComponent(tagcontent));               
					}else if(tagtype.compareTo("LoopComponent") == 0&&tagcontent.length()>3){
							tempbuf.append(getLoopComponent(tagcontent,tagname));
					}else if(tagtype.compareTo("CustomerComponent") == 0&&tagcontent.length()>3){
							tempbuf.append(getCustomerComponent(tagcontent,tagname,flag));
					}
					
					if(i == temp.length-1){
						tempbuf.append(dosortJSPWords(temp[i].substring(temp[i].indexOf("]-->")+4,temp[i].length())));
					}else{
//						tempbuf.append(dosortJSPWords(temp[i].substring(temp[i].indexOf("]-->")+4,temp[i].indexOf("<!--WEBPUMPCOMPONET"))));
//						tagname = temp[i].substring(temp[i].indexOf("NAME=\""+m_strPageName)+6,temp[i].indexOf("\" TYPE=\""));
//						tagtype = temp[i].substring(temp[i].indexOf("\" TYPE=\"")+8,temp[i].length());	
						tempbuf.append(dosortJSPWords(temp[i].substring(temp[i].indexOf("]-->")+4,temp[i].indexOf("<!--WEBPUMPCOMPONET"))));
						nNameIndex=temp[i].indexOf("NAME=\""+m_strPageName)+6;
						strTemp=temp[i].substring(nNameIndex);
						tagname = strTemp.substring(0,strTemp.indexOf("\" TYPE=\""));
						strTemp=strTemp.substring(tagname.length()+8);
						tagtype = strTemp.substring(0,strTemp.length());		
					}
				}
			}
		}
		return tempbuf.toString();
	}
    
	/**
	 * 将一个内部绑定??记内容中的"\"" 替换成 "\\\""
	 * 
	 * @param tagcontent   一个内部绑定??记中的内容 
	 */
    public String modifyTagContent(String tagcontent){
    	String retnstr = "";
		StringBuffer tempbuf = new StringBuffer();
		/** to keep the offset of the "\"" in the bind content */
		int temptagcontentnum = 0;
		/** replay the "\"" in the bind content with "\\\"" */
		for(int a = 0;a < tagcontent.length();a++){
			int entertag = 0;
			if(a+1 < tagcontent.length() && tagcontent.substring(a,a+1).compareTo("\"") == 0){
				if(temptagcontentnum == 0){
					tempbuf.append(tagcontent.substring(0,a));
					tempbuf.append("\\\"");
					temptagcontentnum = a+1;
				}else{
					tempbuf.append(tagcontent.substring(temptagcontentnum,a));
					tempbuf.append("\\\"");
					temptagcontentnum = a+1;
				}
			}
		}
		if(temptagcontentnum < tagcontent.length()){
			tempbuf.append(tagcontent.substring(temptagcontentnum,tagcontent.length()));
		}
		/** update the tagcontent with temptagcontent */
		if(tempbuf.toString().compareTo("") != 0){
			retnstr = tempbuf.toString();
		}else{
			retnstr = tagcontent;
		}
		return retnstr;
    }
    
	/**
	 * 提取一个内部绑定??记的属性值 name或是type
	 * 
	 * @param originalContent   一个绑定??记中的内容 
	 * @param index   当前??索到的位置 
	 * @param originalContent   属性?? 
	 * 
	 */
    public String getPropertiesName(String originalContent,int index,String properName){
    	int propertiesstart = 0;
    	int propertiesend = 0;
		int m = 0;
		String retnstr = "";
		while(index+m+6<originalContent.length() && 
		      originalContent.substring(index+m,index+m+6).compareTo(properName) != 0){
			m++;
		}
		propertiesstart = index+m+6;
		int n = 0;
		while(propertiesstart+n+1 < originalContent.length() && 
		      originalContent.substring(propertiesstart+n,propertiesstart+n+1).compareTo("\"") != 0){
			n++; 
		}
		propertiesend = propertiesstart+n;
		retnstr = originalContent.substring(propertiesstart,propertiesend);//some such as "Page10003"
		return retnstr;
    }
    
	/**
	 * 将一个内部绑定??记内容头尾的"\n"、"\r"、" "??滤??
	 * 
	 * @param tagcontent   一个内部绑定??记中的内容 
	 * 
	 */
    public String clearContentHeadTail(String tagcontent){
		if(tagcontent.length() != 0){
			if(tagcontent.compareTo("\n") == 0||
			   tagcontent.compareTo("\r") == 0||
			   tagcontent.compareTo(" ") == 0){
				tagcontent = "";
			}else{
				int tag = 0;
				for(int t = 0;t < tagcontent.length();t++){
					if(tagcontent.substring(t,t+1).compareTo("\n") == 0||
					   tagcontent.substring(t,t+1).compareTo("\r") == 0||
					   tagcontent.substring(t,t+1).compareTo(" ") == 0){
						tag = t+1;
					}else{
						break;
					}
				}
				tagcontent = tagcontent.substring(tag,tagcontent.length());
				tag = tagcontent.length();
				for(int t = tagcontent.length();t > 0;t--){
					if(tagcontent.substring(t-1,t).compareTo("\n") == 0||
					   tagcontent.substring(t-1,t).compareTo("\r") == 0||
					   tagcontent.substring(t-1,t).compareTo(" ") == 0){
						tag = t-1;
					}else{
						break;
					}
				}
				tagcontent = tagcontent.substring(0,tag);
			}
		}
		return tagcontent;
    }
    
	/**
	 * 拼出SingleError绑定在JSP文??中的内容
	 * 
	 * @param tagcontent   一个SingleError绑定的内容 
	 * 
	 */
    public String getSingleErrorComponent(String tagcontent){
		String separator = System.getProperty("line.separator");
    	StringBuffer retnstr = new StringBuffer();
    	
		tagcontent = clearContentHeadTail(tagcontent);				
		String []splitArray = tagcontent.split("##");
		boolean paramMinus = false;
		boolean bindComplete = false;	
		if(splitArray.length>1){
			bindComplete = true;	
		}
		if(splitArray.length==2 && splitArray[0].equals("")){
			bindComplete = true;
		}
		if(bindComplete){
			retnstr.append("<%=ErrorBean.getMessageByField(\"");
			retnstr.append(splitArray[1]);
			retnstr.append("\",");
			if(paramMinus){
				retnstr.append("\"");
				retnstr.append(tagcontent);
				retnstr.append("\",");
			}
			retnstr.append("request)%>");
			retnstr.append(separator);
		}
		return retnstr.toString();
    }
    
	/**
	 * 拼出Loop绑定在JSP文??中的内容
	 * 
	 * @param tagcontent   一个Loop绑定的内容 
	 * 
	 */
    public String getLoopComponent(String tagcontent,String tagname){
		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 = \"");

⌨️ 快捷键说明

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