Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 301598
Collapse All | Expand All

(-)src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java (-92 / +141 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
2
 * Copyright (c) 2004, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 116-121 Link Here
116
116
117
	public static final String ENDL = "\n"; //$NON-NLS-1$
117
	public static final String ENDL = "\n"; //$NON-NLS-1$
118
118
119
	private static final String JSP_PREFIX = "jsp:"; //$NON-NLS-1$
120
119
	String fClassHeader = null;
121
	String fClassHeader = null;
120
	String fClassname = null;
122
	String fClassname = null;
121
123
Lines 820-948 Link Here
820
	}
822
	}
821
823
822
	protected void addTaglibVariables(String tagToAdd, ITextRegionCollection customTag) {
824
	protected void addTaglibVariables(String tagToAdd, ITextRegionCollection customTag) {
823
		IFile f = getFile();
824
825
		if (f == null || !f.exists())
826
			return;
827
828
		TaglibHelper helper = TaglibHelperManager.getInstance().getTaglibHelper(f);
829
		/*
825
		/*
830
		 * Variables can declare as available when NESTED, AT_BEGIN, or
826
		 * Variables can declare as available when NESTED, AT_BEGIN, or
831
		 * AT_END. For AT_END variables, store the entire list of variables in
827
		 * AT_END. For AT_END variables, store the entire list of variables in
832
		 * the map field so it can be used on the end tag.
828
		 * the map field so it can be used on the end tag.
833
		 */
829
		 */
834
		String decl = ""; //$NON-NLS-1$
835
		if (customTag.getFirstRegion().getType().equals(DOMRegionContext.XML_TAG_OPEN)) {
830
		if (customTag.getFirstRegion().getType().equals(DOMRegionContext.XML_TAG_OPEN)) {
836
			/*
831
			/*
837
			 * Start tag
832
			 * Start tag
838
			 */
833
			 */
839
			List problems = new ArrayList();
834
			addStartTagVariable(tagToAdd, customTag);
840
			CustomTag tag = helper.getCustomTag(tagToAdd, getStructuredDocument(), customTag, problems);
835
		}
841
			TaglibVariable[] taglibVars = tag.getTagVariables();
836
		/**
842
			fTranslationProblems.addAll(problems);
837
		 * Pop from stack, add ending curly brace and AT_END variables
843
			// Bug 199047
838
		 */
844
			/*
839
		else if (customTag.getFirstRegion().getType().equals(DOMRegionContext.XML_END_TAG_OPEN)) {
845
			 * Add AT_BEGIN variables
840
			addEndTagVariable(tagToAdd, customTag);
846
			 */
841
		}
847
			for (int i = 0; i < taglibVars.length; i++) {
842
	}
848
				if (taglibVars[i].getScope() == VariableInfo.AT_BEGIN) {
849
					decl = taglibVars[i].getDeclarationString();
850
					appendToBuffer(decl, fUserCode, false, customTag);
851
				}
852
			}
853
854
			boolean isEmptyTag = customTag.getLastRegion().getType().equals(DOMRegionContext.XML_EMPTY_TAG_CLOSE);
855
843
856
			/**
844
	private void addEndTagVariable(String tagToAdd, ITextRegionCollection customTag){
857
			 * Add opening curly brace
845
		IFile f = getFile();
858
			 */
846
		if (f == null || !f.exists())
847
			return;
848
		String decl = ""; //$NON-NLS-1$
849
		RegionTag regionTag = (RegionTag) fTagToVariableMap.pop(tagToAdd);
850
		if (regionTag != null) {
851
			TaglibVariable[] taglibVars = regionTag.tag.getTagVariables();
852
			// even an empty array will indicate a need for a closing
853
			// brace
859
			StringBuffer text = new StringBuffer();
854
			StringBuffer text = new StringBuffer();
860
			if (!isEmptyTag && tag.isIterationTag() && tag.getTagClassName() != null)
855
			if (regionTag.tag.isIterationTag())
861
				text.append("\nwhile (true) "); //$NON-NLS-1$
856
				doAfterBody(text, regionTag);
862
			text.append("{ // <"); //$NON-NLS-1$
857
			text.append("} // </"); //$NON-NLS-1$
863
			text.append(tagToAdd);
858
			text.append(tagToAdd);
864
			if (isEmptyTag)
859
			text.append(">\n"); //$NON-NLS-1$
865
				text.append("/>\n"); //$NON-NLS-1$
866
			else
867
				text.append(">\n"); //$NON-NLS-1$
868
869
			appendToBuffer(text.toString(), fUserCode, false, customTag); //$NON-NLS-1$
860
			appendToBuffer(text.toString(), fUserCode, false, customTag); //$NON-NLS-1$
870
861
871
			/**
862
			/*
872
			 * Add NESTED variables
863
			 * Add AT_END variables
873
			 */
864
			 */
874
			for (int i = 0; i < taglibVars.length; i++) {
865
			for (int i = 0; i < taglibVars.length; i++) {
875
				if (taglibVars[i].getScope() == VariableInfo.NESTED) {
866
				if (taglibVars[i].getScope() == VariableInfo.AT_END) {
876
					decl = taglibVars[i].getDeclarationString();
867
					decl = taglibVars[i].getDeclarationString();
877
					appendToBuffer(decl, fUserCode, false, customTag);
868
					appendToBuffer(decl, fUserCode, false, customTag);
878
				}
869
				}
879
			}
870
			}
871
		}
872
		else {
873
			// report an unmatched end tag in fTranslationProblems ?
874
		}
875
	}
876
	
877
	private void addStartTagVariable(String tagToAdd,ITextRegionCollection customTag){
878
		IFile f = getFile();
880
879
881
			/**
880
		if (f == null || !f.exists())
882
			 * If empty, pop from stack, add ending curly brace and AT_END
881
			return;
883
			 * variables
882
		TaglibHelper helper = TaglibHelperManager.getInstance().getTaglibHelper(f);
884
			 */
883
		/*
885
			if (isEmptyTag) {
884
		 * Variables can declare as available when NESTED, AT_BEGIN, or
886
				text = new StringBuffer();
885
		 * AT_END. For AT_END variables, store the entire list of variables in
887
				text.append("} // <"); //$NON-NLS-1$
886
		 * the map field so it can be used on the end tag.
888
				text.append(tagToAdd);
887
		 */
889
				text.append("/>\n"); //$NON-NLS-1$
888
		String decl = ""; //$NON-NLS-1$
890
				appendToBuffer(text.toString(), fUserCode, false, customTag); //$NON-NLS-1$
889
		List problems = new ArrayList();
891
				for (int i = 0; i < taglibVars.length; i++) {
890
		CustomTag tag = helper.getCustomTag(tagToAdd, getStructuredDocument(), customTag, problems);
892
					if (taglibVars[i].getScope() == VariableInfo.AT_END) {
891
		TaglibVariable[] taglibVars = tag.getTagVariables();
893
						decl = taglibVars[i].getDeclarationString();
892
		fTranslationProblems.addAll(problems);
894
						appendToBuffer(decl, fUserCode, false, customTag);
893
		// Bug 199047
895
					}
894
		/*
896
				}
895
		 * Add AT_BEGIN variables
896
		 */
897
		for (int i = 0; i < taglibVars.length; i++) {
898
			if (taglibVars[i].getScope() == VariableInfo.AT_BEGIN) {
899
				decl = taglibVars[i].getDeclarationString();
900
				appendToBuffer(decl, fUserCode, false, customTag);
897
			}
901
			}
898
			else {
902
		}
899
				/*
903
900
				 * Store for use at end tag and for accurate pairing even with
904
		boolean isEmptyTag = customTag.getLastRegion().getType().equals(DOMRegionContext.XML_EMPTY_TAG_CLOSE);
901
				 * extra end tags (with empty non-null array)
905
		if (!isEmptyTag){
902
				 */
906
			if (customTag.getLastRegion().getType().equals(DOMRegionContext.WHITE_SPACE)){
903
				fTagToVariableMap.push(tagToAdd, new RegionTag(customTag, tag));
907
				int len = customTag.getRegions().size();
908
				if (len >2){
909
					isEmptyTag = customTag.getRegions().get(len-2).getType().equals(DOMRegionContext.XML_EMPTY_TAG_CLOSE);
910
				}
911
				
904
			}
912
			}
905
		}
913
		}
914
906
		/**
915
		/**
907
		 * Pop from stack, add ending curly brace and AT_END variables
916
		 * Add opening curly brace
908
		 */
917
		 */
909
		else if (customTag.getFirstRegion().getType().equals(DOMRegionContext.XML_END_TAG_OPEN)) {
918
		StringBuffer text = new StringBuffer();
910
			// pop the variables
919
		if (!isEmptyTag && tag.isIterationTag() && tag.getTagClassName() != null)
911
			RegionTag regionTag = (RegionTag) fTagToVariableMap.pop(tagToAdd);
920
			text.append("\nwhile (true) "); //$NON-NLS-1$
912
			if (regionTag != null) {
921
		text.append("{ // <"); //$NON-NLS-1$
913
				TaglibVariable[] taglibVars = regionTag.tag.getTagVariables();
922
		text.append(tagToAdd);
914
				// even an empty array will indicate a need for a closing
923
		if (isEmptyTag)
915
				// brace
924
			text.append("/>\n"); //$NON-NLS-1$
916
				StringBuffer text = new StringBuffer();
925
		else
917
				if (regionTag.tag.isIterationTag())
926
			text.append(">\n"); //$NON-NLS-1$
918
					doAfterBody(text, regionTag);
919
				text.append("} "); //$NON-NLS-1$
920
				text.append("// </"); //$NON-NLS-1$
921
				text.append(tagToAdd);
922
				if (customTag.getLastRegion().getType().equals(DOMRegionContext.XML_EMPTY_TAG_CLOSE)) {
923
					text.append("/>\n"); //$NON-NLS-1$
924
				}
925
				else {
926
					text.append(">\n"); //$NON-NLS-1$
927
				}
928
				appendToBuffer(text.toString(), fUserCode, false, customTag); //$NON-NLS-1$
929
927
930
				/*
928
		appendToBuffer(text.toString(), fUserCode, false, customTag); //$NON-NLS-1$
931
				 * Add AT_END variables
929
932
				 */
930
		/**
933
				for (int i = 0; i < taglibVars.length; i++) {
931
		 * Add NESTED variables
934
					if (taglibVars[i].getScope() == VariableInfo.AT_END) {
932
		 */
935
						decl = taglibVars[i].getDeclarationString();
933
		for (int i = 0; i < taglibVars.length; i++) {
936
						appendToBuffer(decl, fUserCode, false, customTag);
934
			if (taglibVars[i].getScope() == VariableInfo.NESTED) {
937
					}
935
				decl = taglibVars[i].getDeclarationString();
938
				}
936
				appendToBuffer(decl, fUserCode, false, customTag);
939
			}
937
			}
940
			else {
938
		}
941
				// report an unmatched end tag in fTranslationProblems ?
939
940
		/**
941
		 * If empty, pop from stack, add ending curly brace and AT_END
942
		 * variables
943
		 */
944
		if (isEmptyTag) {
945
			text = new StringBuffer();
946
			text.append("} // <"); //$NON-NLS-1$
947
			text.append(tagToAdd);
948
			text.append("/>\n"); //$NON-NLS-1$
949
			appendToBuffer(text.toString(), fUserCode, false, customTag); //$NON-NLS-1$
950
			/* Treat this as the end for empty tags */
951
			for (int i = 0; i < taglibVars.length; i++) {
952
				if (taglibVars[i].getScope() == VariableInfo.AT_END) {
953
					decl = taglibVars[i].getDeclarationString();
954
					appendToBuffer(decl, fUserCode, false, customTag);
955
				}
942
			}
956
			}
943
		}
957
		}
958
		else {
959
			/*
960
			 * Store for use at end tag and for accurate pairing even with
961
			 * extra end tags (with empty non-null array)
962
			 */
963
			fTagToVariableMap.push(tagToAdd, new RegionTag(customTag, tag));
964
		}
965
		
944
	}
966
	}
967
	
968
	private void addCustomTaglibVariables(String tagToAdd, ITextRegionCollection customTag, ITextRegion prevRegion) {
969
		//Can't judge by first region as start and end tag are part of same ContextRegionContainer		
970
		if (prevRegion != null && prevRegion.getType().equals(DOMRegionContext.XML_END_TAG_OPEN)) {
971
			/*
972
			 * End tag
973
			 */
974
			addEndTagVariable(tagToAdd, customTag);
975
		}
976
		else if (customTag.getFirstRegion().getType().equals(DOMRegionContext.XML_TAG_OPEN)) {
977
			/*
978
			 * Start tag
979
			 */
980
			addStartTagVariable(tagToAdd,customTag);
981
		}
945
982
983
	}
984
	
946
	private void doAfterBody(StringBuffer buffer, RegionTag regionTag) {
985
	private void doAfterBody(StringBuffer buffer, RegionTag regionTag) {
947
		buffer.append("\tif ( (new "); //$NON-NLS-1$
986
		buffer.append("\tif ( (new "); //$NON-NLS-1$
948
		buffer.append(regionTag.tag.getTagClassName());
987
		buffer.append(regionTag.tag.getTagClassName());
Lines 1711-1716 Link Here
1711
			// possible delimiter, check later
1750
			// possible delimiter, check later
1712
			delim = embeddedRegions.get(i);
1751
			delim = embeddedRegions.get(i);
1713
			type = delim.getType();
1752
			type = delim.getType();
1753
			if (type == DOMRegionContext.XML_TAG_NAME )
1754
			{
1755
				String fullTagName = embeddedContainer.getText(delim);
1756
				if (fullTagName.indexOf(':') > -1 && !fullTagName.startsWith(JSP_PREFIX)) {
1757
					ITextRegion prevRegion =null;
1758
					if (i>0)
1759
						prevRegion = embeddedRegions.get(i-1);
1760
					addCustomTaglibVariables(fullTagName, embeddedContainer,prevRegion); // it may be a custom tag
1761
				}
1762
			}
1714
			if(type == DOMJSPRegionContexts.XML_TAG_ATTRIBUTE_VALUE_DQUOTE || type == DOMJSPRegionContexts.XML_TAG_ATTRIBUTE_VALUE_SQUOTE
1763
			if(type == DOMJSPRegionContexts.XML_TAG_ATTRIBUTE_VALUE_DQUOTE || type == DOMJSPRegionContexts.XML_TAG_ATTRIBUTE_VALUE_SQUOTE
1715
				|| type == DOMJSPRegionContexts.JSP_TAG_ATTRIBUTE_VALUE_DQUOTE || type == DOMJSPRegionContexts.JSP_TAG_ATTRIBUTE_VALUE_SQUOTE)
1764
				|| type == DOMJSPRegionContexts.JSP_TAG_ATTRIBUTE_VALUE_DQUOTE || type == DOMJSPRegionContexts.JSP_TAG_ATTRIBUTE_VALUE_SQUOTE)
1716
				quotetype = type;
1765
				quotetype = type;

Return to bug 301598