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 293503 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java (-1 / +67 lines)
Lines 244-249 Link Here
244
	 * EL Translator ID
244
	 * EL Translator ID
245
	 */
245
	 */
246
	private String fELTranslatorID;
246
	private String fELTranslatorID;
247
	
248
	/**
249
	 * A buffer to store non translated code such as plain XML
250
	 */
251
	private StringBuffer fCollectedNonTranslatedCode;
252
	
253
	/**
254
	 * <code>true</code> if code has been appended to a buffer for the current region,
255
	 * <code>false</code> otherwise
256
	 */
257
	private boolean fCodeAppended;
247
258
248
	/**
259
	/**
249
	 * A structure for holding a region collection marker and list of variable
260
	 * A structure for holding a region collection marker and list of variable
Lines 488-493 Link Here
488
499
489
		fELProblems = new ArrayList();
500
		fELProblems = new ArrayList();
490
501
502
		fCollectedNonTranslatedCode = new StringBuffer();
503
		fCodeAppended = false;
491
	}
504
	}
492
505
493
	/**
506
	/**
Lines 916-922 Link Here
916
		setCurrentNode(fStructuredDocument.getFirstStructuredDocumentRegion());
929
		setCurrentNode(fStructuredDocument.getFirstStructuredDocumentRegion());
917
930
918
		while (getCurrentNode() != null && !isCanceled()) {
931
		while (getCurrentNode() != null && !isCanceled()) {
919
932
			//no code has been append for this region yet
933
			fCodeAppended = false;
934
			
920
			// intercept HTML comment flat node
935
			// intercept HTML comment flat node
921
			// also handles UNDEFINED (which is what CDATA comes in as)
936
			// also handles UNDEFINED (which is what CDATA comes in as)
922
			// basically this part will handle any "embedded" JSP containers
937
			// basically this part will handle any "embedded" JSP containers
Lines 927-936 Link Here
927
				// iterate through each region in the flat node
942
				// iterate through each region in the flat node
928
				translateRegionContainer(getCurrentNode(), STANDARD_JSP);
943
				translateRegionContainer(getCurrentNode(), STANDARD_JSP);
929
			}
944
			}
945
			
946
			//if no code was appended for this region collect it as not translated
947
			if(!fCodeAppended) {
948
				collectNonTranslatedCode(getCurrentNode());
949
			}
950
			
930
			if (getCurrentNode() != null)
951
			if (getCurrentNode() != null)
931
				advanceNextNode();
952
				advanceNextNode();
932
		}
953
		}
933
		
954
		
955
		writeCollectedNonTranslatedCode();
956
		
934
		/*
957
		/*
935
		 * Any contents left in the map indicate start tags that never had end
958
		 * Any contents left in the map indicate start tags that never had end
936
		 * tags. While the '{' that is present without the matching '}' would
959
		 * tags. While the '{' that is present without the matching '}' would
Lines 2113-2118 Link Here
2113
		if (!nonl && !newText.endsWith(ENDL))
2136
		if (!nonl && !newText.endsWith(ENDL))
2114
			newText += ENDL;
2137
			newText += ENDL;
2115
2138
2139
		//dump any non translated code before writing translated code
2140
		writeCollectedNonTranslatedCode();
2141
		fCodeAppended = true;
2142
		
2143
		
2116
		if (buffer == fUserCode) {
2144
		if (buffer == fUserCode) {
2117
			buffer.append(newText);
2145
			buffer.append(newText);
2118
			if (addToMap) {
2146
			if (addToMap) {
Lines 2370-2375 Link Here
2370
	}
2398
	}
2371
2399
2372
	/**
2400
	/**
2401
	 * Adds the given {@link ITextRegion} to the collection of non translated code.
2402
	 *
2403
	 * @param region
2404
	 */
2405
	private void collectNonTranslatedCode(ITextRegion region) {
2406
		String s = ""; //$NON-NLS-1$
2407
		if (region instanceof ITextRegionContainer) {
2408
			Iterator it = ((ITextRegionContainer) region).getRegions().iterator();
2409
			ITextRegion temp = null;
2410
			while (it.hasNext()) {
2411
				temp = (ITextRegion) it.next();
2412
				fCollectedNonTranslatedCode.append(getCurrentNode().getFullText(temp));
2413
			}
2414
		}
2415
		else {
2416
			s = EscapedTextUtil.getUnescapedText(getCurrentNode(), region);
2417
			fCollectedNonTranslatedCode.append(s.trim());
2418
		}
2419
	}
2420
	
2421
	/**
2422
	 * Writes the non translated code to the {@link #fUserCode} buffer.
2423
	 * This should be done before appending any new translated code.
2424
	 */
2425
	private void writeCollectedNonTranslatedCode() {
2426
		if(fCollectedNonTranslatedCode.length() > 0) {
2427
			String dump = fCollectedNonTranslatedCode.toString();
2428
			dump = dump.replaceAll("[\n\t\r\" ]*", "");
2429
			
2430
			dump = EXPRESSION_PREFIX + "\"" + dump + "\"" + EXPRESSION_SUFFIX + ENDL;
2431
			fUserCode.append(dump);
2432
			fOffsetInUserCode += dump.length();
2433
			
2434
			fCollectedNonTranslatedCode = new StringBuffer();
2435
		}
2436
	}
2437
	
2438
	/**
2373
	 * Set the buffer to the current JSPType: STANDARD_JSP, EMBEDDED_JSP,
2439
	 * Set the buffer to the current JSPType: STANDARD_JSP, EMBEDDED_JSP,
2374
	 * DECLARATION, EXPRESSION, SCRIPTLET (for keepting track of cursor
2440
	 * DECLARATION, EXPRESSION, SCRIPTLET (for keepting track of cursor
2375
	 * position when the final document is built)
2441
	 * position when the final document is built)

Return to bug 293503