Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c364232d2bb56c90c3d11b4ff699cc80ef298488 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
package org.eclipse.ui.externaltools.internal.ant.editor;

/**********************************************************************
This file is made available under the terms of the Common Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/cpl-v10.html
**********************************************************************/
//
// Copyright:
// GEBIT Gesellschaft fuer EDV-Beratung
// und Informatik-Technologien mbH, 
// Berlin, Duesseldorf, Frankfurt (Germany) 2002
// All rights reserved.
//

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeSet;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Available;
import org.apache.tools.ant.taskdefs.Parallel;
import org.apache.tools.ant.taskdefs.PathConvert;
import org.apache.tools.ant.taskdefs.Property;
import org.apache.tools.ant.taskdefs.Sequential;
import org.apache.tools.ant.taskdefs.UpToDate;
import org.apache.tools.ant.taskdefs.condition.Condition;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.externaltools.internal.ant.dtd.IAttribute;
import org.eclipse.ui.externaltools.internal.ant.dtd.IDfm;
import org.eclipse.ui.externaltools.internal.ant.dtd.IElement;
import org.eclipse.ui.externaltools.internal.ant.dtd.ISchema;
import org.eclipse.ui.externaltools.internal.ant.dtd.ParseError;
import org.eclipse.ui.externaltools.internal.ant.dtd.Parser;
import org.eclipse.ui.externaltools.internal.ant.editor.utils.ProjectHelper;
import org.eclipse.ui.externaltools.internal.model.ExternalToolsImages;
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
import org.eclipse.ui.externaltools.internal.ui.IExternalToolsUIConstants;
import org.eclipse.ui.part.FileEditorInput;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

/**
 * The text completion processor for Planty.
 * 
 * @author Alf Schiefelbein
 */
public class PlantyCompletionProcessor implements IContentAssistProcessor {

    /**
     * Comparator that is used for sorting 
     * <code>ICompletionProposal</code> instances by their display string.
     */
    public class CompletionComparator implements Comparator {
        public int compare(Object o1, Object o2) {
            String tempString1 = ((ICompletionProposal)o1).getDisplayString();
            String tempString2 = ((ICompletionProposal)o2).getDisplayString();
            return tempString1.compareTo(tempString2);
        }
    }        
 
    /**
     * Helper Set that may only be used to collect 
     * <code>ICompletionProposal</code> instances.
     * <P>
     * This implementation tests the proposal objects by their display string
     * for equality.
     */
    protected class CompletionSet extends TreeSet {
        
        
        private Map displayStringToProposal = new HashMap();


        /**
         * Creates an instance that compares using the 
         * <code>CompletionComparator</code>.
         */
        public CompletionSet() {
           super(new Comparator() {
                public int compare(Object o1, Object o2) {
                    String tempString1 = ((ICompletionProposal)o1).getDisplayString();
                    String tempString2 = ((ICompletionProposal)o2).getDisplayString();
                    return tempString1.compareTo(tempString2);
                }
           });           
        }


        /**
         * Adds the specified <code>ICompletionProposal</code> only if another
         * proposal with the same display string is not contained already.
         * 
         * @param o must be instanceof <code>ICompletionProposal</code>
         */
        public boolean add(Object o) {
            ICompletionProposal tempProposal = (ICompletionProposal)o;
            if(!displayStringToProposal.containsKey(tempProposal.getDisplayString())) {
                boolean tempResult = super.add(o);
                if(tempResult) {
                    displayStringToProposal.put(tempProposal.getDisplayString(), tempProposal);
                }
                return tempResult;
            }
            return false;
        }
            
        
        /**
         * Returns true if no another proposal with the same display string is 
         * contained allready.
         * 
         * @param o must be instanceof <code>ICompletionProposal</code>
         */
        public boolean contains(Object o) {
            ICompletionProposal tempProposal = (ICompletionProposal)o;
            if(!displayStringToProposal.containsKey(tempProposal.getDisplayString())) {
                return true;
            }
            return false;
        }


        /**
         * Removes the specified proposal.
         * 
         * @param o must be instanceof <code>ICompletionProposal</code>
         */
        public boolean remove(Object o) {
            ICompletionProposal tempProposal = (ICompletionProposal)o;
            boolean tempResult = super.remove(o);
            if(tempResult) {
                Object tempObject = displayStringToProposal.remove(tempProposal.getDisplayString());
                if(tempObject == null) {
                    throw new NoSuchElementException(AntEditorMessages.getString("PlantyCompletionProcessor.Serious_Error")); //$NON-NLS-1$
                }
            }
            return tempResult;
        }

    }


    protected final static int PROPOSAL_MODE_NONE = 0;
    protected final static int PROPOSAL_MODE_TASK_PROPOSAL = 1;
    protected final static int PROPOSAL_MODE_ATTRIBUTE_PROPOSAL = 2;
    protected final static int PROPOSAL_MODE_TASK_PROPOSAL_CLOSING = 3;
    protected final static int PROPOSAL_MODE_ATTRIBUTE_VALUE_PROPOSAL = 4;
    protected final static int PROPOSAL_MODE_PROPERTY_PROPOSAL = 5;

    protected final static String REQUIRED = "#REQUIRED"; //$NON-NLS-1$
    
    /**
     * The line where the cursor sits now.
     * <P>
     * The first line has index '1'.
     */
    protected int lineNumber = -1;

    /**
     * The startingColumn where the cursor sits now.
     * <P>
     * The first startingColumn has index '1'.
     */
    protected int columnNumber = -1;
    
    public static final String ANT_1_5_DTD_FILENAME = "/ant1.5b.dtd"; //$NON-NLS-1$

    /**
     * The dtd.
     */
    protected static ISchema dtd;


    /**
     * Cursor position, counted from the beginning of the document.
     * <P>
     * The first position has index '0'.
     */
	protected int cursorPosition = -1;
	
    /**
     * The text viewer.
     */
	protected ITextViewer viewer;
	
	private char[] autoActivationChars= new char[]{'<', '$', '{' };
	
    
    /**
     * The provider for all task and attribute descriptions.
     */
    protected TaskDescriptionProvider descriptionProvider = new TaskDescriptionProvider();
	private PlantySaxDefaultHandler lastDefaultHandler;
	
    
	/**
	 * Constructor for PlantyCompletionProcessor.
	 */
	public PlantyCompletionProcessor() {
		super();
		if(dtd == null) {
	        try {
	     	  	dtd = parseDtd();
	        } catch (IOException e) {
	        	ExternalToolsPlugin.getDefault().log(e);
	        } catch (ParseError e) {
				ExternalToolsPlugin.getDefault().log(e);
			}
		}
	}

    /**
     * Parses the dtd.
     */
    private ISchema parseDtd() throws ParseError, IOException {
        InputStream tempStream = getClass().getResourceAsStream(ANT_1_5_DTD_FILENAME);
        InputStreamReader tempReader = new InputStreamReader(tempStream, "UTF-8"); //$NON-NLS-1$
        Parser parser = new Parser();
        return parser.parseDTD(tempReader, "project"); //$NON-NLS-1$
    }
    
	/**
	 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
	 */
	public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
		this.viewer = viewer;
		return determineProposals();
	
	}
	
	
	/**
	 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(ITextViewer, int)
	 */
	public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
		return new IContextInformation[0];
	}

	/**
	 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
	 */
	public char[] getCompletionProposalAutoActivationCharacters() {
        return autoActivationChars;
	}

	/**
	 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
	 */
	public char[] getContextInformationAutoActivationCharacters() {
        return null;
	}

	/**
	 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
	 */
	public IContextInformationValidator getContextInformationValidator() {
		return null;
	}

	/**
	 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
	 */
	public String getErrorMessage() {
		return AntEditorMessages.getString("PlantyCompletionProcessor.No_Text_Completions_2"); //$NON-NLS-1$
	}
	

    /**
     * Returns the new determined proposals.
     */ 
	private ICompletionProposal[] determineProposals() {
		
		String prefix = getCurrentPrefix();
		cursorPosition = ((ITextSelection)viewer.getSelectionProvider().getSelection()).getOffset();
        
        IDocument tempDocument = viewer.getDocument();
        try {
            lineNumber = tempDocument.getLineOfOffset(cursorPosition);
            columnNumber = cursorPosition - tempDocument.getLineOffset(lineNumber);
        } catch (BadLocationException e) {
            ExternalToolsPlugin.getDefault().log(e);
        }
		
		if (prefix == null || cursorPosition == -1) {
			if (ExternalToolsPlugin.getDefault().isDebugging()) {
				ExternalToolsPlugin.getDefault().log(AntEditorMessages.getString("PlantyCompletionProcessor.Could_not_do_completion_3"), null); //$NON-NLS-1$
			}
			IWorkbenchWindow window= ExternalToolsPlugin.getActiveWorkbenchWindow();
			if (window != null) {
				window.getShell().getDisplay().beep();
			}
			return null;
		}
	
		ICompletionProposal[] proposals = getProposalsFromDocument(tempDocument.get(), prefix);
		return proposals;
		
	}


    /**
     * Returns the proposals for the specified document.
     * 
     * @param aDocmuentString the text of the currently edited file as one string.
     * @param the prefix
     */
    protected ICompletionProposal[] getProposalsFromDocument(String aDocumentString, String aPrefix) {
        String tempTaskString = null;

        /*
         * Completions will be determined depending on the proposal mode.
         */
        switch (determineProposalMode(aDocumentString, cursorPosition, aPrefix)) {

            case PROPOSAL_MODE_NONE :
                break;

            case PROPOSAL_MODE_ATTRIBUTE_PROPOSAL:
                tempTaskString = getTaskStringFromDocumentStringToPrefix(aDocumentString.substring(0, cursorPosition-aPrefix.length()));
                return getAttributeProposals(tempTaskString, aPrefix);

            case PROPOSAL_MODE_TASK_PROPOSAL:
                return getTaskProposals(aDocumentString, findParentElement(aDocumentString, lineNumber, columnNumber), aPrefix);

            case PROPOSAL_MODE_TASK_PROPOSAL_CLOSING:
                return getClosingTaskProposals(findNotClosedParentElement(aDocumentString, lineNumber, columnNumber), aPrefix);

            case PROPOSAL_MODE_ATTRIBUTE_VALUE_PROPOSAL:
                tempTaskString = getTaskStringFromDocumentStringToPrefix(aDocumentString.substring(0, cursorPosition-aPrefix.length()));
                String tempAttributeString = getAttributeStringFromDocumentStringToPrefix(aDocumentString.substring(0, cursorPosition-aPrefix.length()));
                return getAttributeValueProposals(tempTaskString, tempAttributeString, aPrefix);

            case PROPOSAL_MODE_PROPERTY_PROPOSAL:
                return getPropertyProposals(aDocumentString, aPrefix, cursorPosition);

            default :
                break;
        } 
        
         return new ICompletionProposal[0];

    }
    
    /**
     * Returns all possible attributes for the specified task.
     * 
     * @param aTaskName the name of the task for that the attribute shall be 
     * completed
     * @param aPrefix prefix, that all proposals should start with. The prefix
     * may be an empty string.
     */
    protected ICompletionProposal[] getAttributeProposals(String aTaskName, String aPrefix) {
        ArrayList tempProposals = new ArrayList();
        IElement tempElement = dtd.getElement(aTaskName);
        if (tempElement != null) {
        	Iterator tempKeys = tempElement.getAttributes().keySet().iterator();
        	while (tempKeys.hasNext()) {
        		String tempAttrName = (String) tempKeys.next();
        		if (tempAttrName.startsWith(aPrefix)) {
        			IAttribute tempDTDAttribute = (IAttribute) tempElement.getAttributes().get(tempAttrName);
					String tempReplacementString = tempAttrName+"=\"\""; //$NON-NLS-1$
					String tempDisplayString = tempAttrName;
					String[] tempItems = tempDTDAttribute.getEnum();
					if (tempItems != null) {					        			
                        if(tempItems.length > 1) {
                            tempDisplayString += " - ("; //$NON-NLS-1$
                        }
                        for (int i = 0; i < tempItems.length; i++) {
                            tempDisplayString += tempItems[i];
                            if(i+1 < tempItems.length) {
                                tempDisplayString += " | "; //$NON-NLS-1$
                            }
                            else {
                                tempDisplayString += ")"; //$NON-NLS-1$
                            }
                        }
                    }
                    
                    String tempProposalInfo = null;
                    String tempRequired = descriptionProvider.getRequiredAttributeForTaskAttribute(aTaskName, tempAttrName);
                    if(tempRequired != null && tempRequired.length() > 0) {
                        tempProposalInfo = AntEditorMessages.getString("PlantyCompletionProcessor.Required___4") + tempRequired; //$NON-NLS-1$
                        tempProposalInfo += "<BR><BR>"; //$NON-NLS-1$
                    }
                    String tempDescription = descriptionProvider.getDescriptionForTaskAttribute(aTaskName, tempAttrName);
                    if(tempDescription != null) {
                        tempProposalInfo = (tempProposalInfo == null ? "" : tempProposalInfo); //$NON-NLS-1$
                        tempProposalInfo += tempDescription;
                    }
                    
                    
                    ICompletionProposal tempProposal = new CompletionProposal(tempReplacementString, cursorPosition - aPrefix.length(), aPrefix.length(), tempAttrName.length()+2, null, tempDisplayString, null, tempProposalInfo);
                    /*
                     * This is how we do it, once we have the documentation.
                     *
                     * IContextInformation tempContextInfo = new ContextInformation("contextDisplayString", "informationDisplayString");
                     * ICompletionProposal tempProposal = new CompletionProposal(tempAttrName+"=\"\"", cursorPosition - aPrefix.length(), aPrefix.length(), tempAttrName.length()+2, null, tempAttrName, tempContextInfo, "Pustekuchen ;-) !!!");
                     */
                    tempProposals.add(tempProposal);
                }       
            }
        }
        return (ICompletionProposal[])tempProposals.toArray(new ICompletionProposal[tempProposals.size()]);
    }


    /**
     * Returns all possible values for the specified attribute of the specified 
     * task.
     * 
     * @param aTaskName the name of the task that the specified attribute 
     * belongs to.
     * 
     * @param anAttributeName the name of the attribute for that the value
     * shall be completed
     * 
     * @param aPrefix prefix, that all proposals should start with. The prefix
     * may be an empty string.
     */
    protected ICompletionProposal[] getAttributeValueProposals(String aTaskName, String anAttributeName, String aPrefix) {
        ArrayList tempProposals = new ArrayList();
        IElement tempElement = dtd.getElement(aTaskName);
        if (tempElement != null) {
        	IAttribute tempAttribute = (IAttribute) tempElement.getAttributes().get(anAttributeName);
        	if (tempAttribute != null) {
        		String[] tempItems = tempAttribute.getEnum();
        		if (tempItems != null) {
                    for (int i = 0; i < tempItems.length; i++) {
                        String tempItem = tempItems[i];
                        if(tempItem.startsWith(aPrefix)) {
                            ICompletionProposal tempProposal = new CompletionProposal(tempItem, cursorPosition - aPrefix.length(), aPrefix.length(), tempItem.length(), null, tempItem, null, null);
                            tempProposals.add(tempProposal);
                        }
                    }
        		}
            }
        }
        return (ICompletionProposal[])tempProposals.toArray(new ICompletionProposal[tempProposals.size()]);
    }

    
    /**
     * Returns all possible properties for the specified prefix.
     * <P>
     * Note that the completion mode must be property mode, otherwise it is not
     * safe to call this method.
     */
    protected ICompletionProposal[] getPropertyProposals(String aDocumentText, String aPrefix, int aCursorPosition) {
        Set tempProposals = new CompletionSet();
        Map tempProperties = findPropertiesFromDocument(aDocumentText);
        for(Iterator i=tempProperties.keySet().iterator(); i.hasNext(); ) {
            String tempPropertyName = (String)i.next();
            if(tempPropertyName.startsWith(aPrefix)) {
                String tempPropertyValue = (String)tempProperties.get(tempPropertyName);
                String tempAdditPropInfo = tempPropertyValue;

                // Determine replacement length and offset
                // String from beginning to the beginning of the prefix
                int tempReplacementLength = aPrefix.length();
                int tempReplacementOffset = 0;
                String tempStringToPrefix = aDocumentText.substring(0, aCursorPosition - aPrefix.length());
                // Property proposal
                String tempLastTwoCharacters = tempStringToPrefix.substring(tempStringToPrefix.length()-2, tempStringToPrefix.length());
                if(tempLastTwoCharacters.equals("${")) { //$NON-NLS-1$
                    tempReplacementLength += 2;
                    tempReplacementOffset = aCursorPosition - aPrefix.length() - 2;
                }
                else if(tempLastTwoCharacters.endsWith("$")) { //$NON-NLS-1$
                    tempReplacementLength += 1;
                    tempReplacementOffset = aCursorPosition - aPrefix.length() - 1;                }
                else {
                    throw new PlantyException(AntEditorMessages.getString("PlantyCompletionProcessor.Error")); //$NON-NLS-1$
                }
                if(aDocumentText.length() > aCursorPosition && aDocumentText.charAt(aCursorPosition) == '}') {
                    tempReplacementLength += 1;
                }
                 
                String tempReplacementString = new StringBuffer("${").append(tempPropertyName).append('}').toString();  //$NON-NLS-1$
                Image tempImage = ExternalToolsImages.getImage(IExternalToolsUIConstants.IMAGE_ID_PROPERTY);
                
                ICompletionProposal tempProposal = 
                    new CompletionProposal(
                        tempReplacementString, 
                        tempReplacementOffset, 
                        tempReplacementLength, 
                        tempReplacementString.length(), 
						tempImage,
                        tempPropertyName, null, 
                        tempAdditPropInfo);
                tempProposals.add(tempProposal);
            }
        }                
        return (ICompletionProposal[])tempProposals.toArray(new ICompletionProposal[tempProposals.size()]);
    }


    /**
     * Returns all possible attributes for the specified parent task element.
     * <P>
     * No completions will be returned if <code>aParentTaskElement</code> is 
     * not known.
     * 
     * @param aParentTaskName name of the parent(surrounding) task or 
     * <code>null</code> if completion should be done for the root element.
     * 
     * @param aPrefix prefix, that all proposals should start with. The prefix
     * may be an empty string.
     */
    protected ICompletionProposal[] getTaskProposals(String aWholeDocumentString, Element aParentTaskElement, String aPrefix) {
		// The code this replaced assumed that child elements
		// are unordered; there was no provision for walking
		// through a child sequence. This works for the Ant
		// 1.5 DTD but not in general. I kept the assumption. bf
        LinkedList tempProposals = new LinkedList();
        Image tempImage = ExternalToolsImages.getImage(IExternalToolsUIConstants.IMAGE_ID_TASK);
        
        if (aParentTaskElement == null) {
        	// DTDs do not designate a root element.
        	// The previous code must have looked for an element that
        	// was not in the content model of any other element.
        	// This test doesn't work with a DTD used to validate
        	// document partitions, a DTD with multiple candidate
        	// roots, etc. The right answer is to get
        	// the root element from the document. If there isn't
        	// one, we assume "project". bf
            String tempRootElementName = null;
	       	if(lastDefaultHandler != null) {
                tempRootElementName = lastDefaultHandler.rootElementName;
        	}
			if (tempRootElementName == null) {
				tempRootElementName = aPrefix + "project"; //$NON-NLS-1$
			}
			IElement tempRootElement = dtd.getElement(tempRootElementName);
			if(tempRootElement != null && tempRootElementName.startsWith(aPrefix)) {
				String tempProposalInfo = null;
				String tempDescription = descriptionProvider.getDescriptionForTask(tempRootElementName);
				if(tempDescription != null) {
					tempProposalInfo = tempDescription;
				}
	                                
				String tempReplacementString = getTaskProposalReplacementString(tempRootElementName);
				int tempReplacementOffset = cursorPosition-aPrefix.length();
				int tempReplacementLength = aPrefix.length();
				if(tempReplacementOffset > 0 && tempReplacementOffset-1 < aWholeDocumentString.length() && aWholeDocumentString.charAt(tempReplacementOffset-1) == '<') {
					tempReplacementOffset--;
					tempReplacementLength++;
				}

				ICompletionProposal tempProposal = new CompletionProposal(
					tempReplacementString, 
					tempReplacementOffset, 
					tempReplacementLength, 
					tempRootElementName.length()+2, 
					tempImage, 
					tempRootElementName, 
					null, 
					tempProposalInfo);
				tempProposals.add(tempProposal);
				//commented this out because it doesn't quite replace the above
				//ICompletionProposal tempProposal = makeProposal(tempRootElementName, aPrefix, aWholeDocumentString);
				//tempProposals.add(tempProposal);
			}
        }
        else {
			IElement parent = dtd.getElement(aParentTaskElement.getTagName());
			if (parent != null) {
				IDfm dfm = parent.getDfm();
				String[] accepts = dfm.getAccepts();
				for (int i = 0; i < accepts.length; i++) {
					String tempElementName = accepts[i];

					if(tempElementName.startsWith(aPrefix)) {
                                        
						String tempProposalInfo = null;
						String tempDescription = descriptionProvider.getDescriptionForTask(tempElementName);
						if(tempDescription != null) {
							tempProposalInfo = tempDescription;
						}
                                                            
						String tempReplacementString = getTaskProposalReplacementString(tempElementName);
						int tempReplacementOffset = cursorPosition-aPrefix.length();
						int tempReplacementLength = aPrefix.length();
						if(tempReplacementOffset > 0 && aWholeDocumentString.charAt(tempReplacementOffset-1) == '<') {
							tempReplacementOffset--;
							tempReplacementLength++;
						}
						ICompletionProposal tempProposal = new CompletionProposal(
							tempReplacementString, 
							tempReplacementOffset, 
							tempReplacementLength, 
							tempElementName.length()+2, 
							tempImage, 
							tempElementName, 
							null, 
							tempProposalInfo);
						tempProposals.add(tempProposal);
					}
					//commented this out because it doesn't quite replace the above
					//ICompletionProposal tempProposal = makeProposal(tempElementName, aPrefix, aWholeDocumentString);
					//tempProposals.add(tempProposal);
				}
			}
        }
        
       return (ICompletionProposal[])tempProposals.toArray(new ICompletionProposal[tempProposals.size()]);
   }

    /**
     * Returns the one possible completion for the specified unclosed task 
     * element.
     * 
     * @param aUnclosedTaskElement the task element that hasn't been closed 
     * last
     * 
     * @param aPrefix prefix, that the one possible proposals should start 
     * with. The prefix may be an empty string.
     * 
     * @return array which may contain either one or none proposals
     */
    private ICompletionProposal[] getClosingTaskProposals(Element aUnclosedTaskElement, String aPrefix) {
        Set tempProposals = new CompletionSet();
        if(aUnclosedTaskElement != null) {
            if(aUnclosedTaskElement.getTagName().startsWith(aPrefix)) {
                String tempReplaceString = aUnclosedTaskElement.getTagName();
                tempProposals.add(new CompletionProposal(tempReplaceString + '>', cursorPosition - aPrefix.length(), aPrefix.length(), tempReplaceString.length()+1, null, tempReplaceString, null, null));
            }
        }
        return (ICompletionProposal[])tempProposals.toArray(new ICompletionProposal[tempProposals.size()]);
    }

    /**
     * Returns the replacement string for the specified task name.
     */
    private String getTaskProposalReplacementString(String aTaskName) {
        StringBuffer tempReplacement = new StringBuffer("<"); //$NON-NLS-1$
        tempReplacement.append(aTaskName); 
        if(isEmpty(aTaskName)) {
            tempReplacement.append(" />"); //$NON-NLS-1$
        }
        else {
            tempReplacement.append(" ></"); //$NON-NLS-1$
            tempReplacement.append(aTaskName);
            tempReplacement.append('>');
        }
        return tempReplacement.toString();               
    }


    /**
     * Returns whether the named element is empty, thus may not have any child
     * elements.
     */
    private boolean isEmpty(String aDTDElementName) {
        IElement element = dtd.getElement(aDTDElementName);
        return element.isEmpty();
    }
    
    
    /**
     * Finds a direct child element with <code>aChildElementName</code> of 
     * <code>anElement</code>.
     * <P>
     * The child will not be searched for in the whole hierarchy but only in
     * the hierarchy step below.
     * 
     * @return the found child or <code>null</code> if not found.
     */
    protected Element findChildElementNamedOf(Element anElement, String aChildElementName) {
        NodeList tempNodeList = anElement.getChildNodes();
        for (int i = 0; i < tempNodeList.getLength(); i++) {
            Node tempChildNode = (Node)tempNodeList.item(i);
            if(tempChildNode.getNodeType() == Node.ELEMENT_NODE) {
                if(tempChildNode.getNodeName().equals(aChildElementName)) {
                    return (Element)tempChildNode;
                }
            }
            
        }
        return null;
    }

	/**
     * Determines the current prefix, that should be used for completion.
     */
	private String getCurrentPrefix() {

		ITextSelection selection = (ITextSelection)viewer.getSelectionProvider().getSelection();
		
		if (selection.getLength() > 0) {
			return null;
		}
		
		IDocument doc = viewer.getDocument();

        return getPrefixFromDocument(doc.get(), selection.getOffset()).toLowerCase();
	}


    /**
     * Returns the prefix in the specified document text with respect to the 
     * specified offset.
     * 
     * @param aDocumentString the whole content of the edited file as String
     * @param anOffset the cursor position
     */
    protected String getPrefixFromDocument(String aDocumentText, int anOffset) {
        
        int startOfWordToken = anOffset;
        
        while (startOfWordToken > 0 
                && (Character.isJavaIdentifierPart(aDocumentText.charAt(startOfWordToken - 1)) 
                    || '.' == aDocumentText.charAt(startOfWordToken - 1)
                    )
                && !('$' == aDocumentText.charAt(startOfWordToken - 1))) {
            startOfWordToken--;
        }
        
        if (startOfWordToken != anOffset) {
            return aDocumentText.substring(startOfWordToken, anOffset);
        } else {
            return ""; //$NON-NLS-1$
        }
    }
 
 
    /**
     * Returns the current proposal mode.
     */
    protected int determineProposalMode(String aWholeDocumentString, int aCursorPosition, String aPrefix) {

        // String from beginning of document to the beginning of the prefix
        String tempStringToPrefix = aWholeDocumentString.substring(0, aCursorPosition - aPrefix.length());

        // Is trimmable from behind
        String tempTrimmedString = tempStringToPrefix.trim();
        char tempLastChar = 0;
        if(tempTrimmedString.length() > 0) {
	        tempLastChar = tempTrimmedString.charAt(tempTrimmedString.length()-1);
        }
        else {
        	return PROPOSAL_MODE_TASK_PROPOSAL;
        }
        if(tempStringToPrefix.charAt(tempStringToPrefix.length()-1) != tempLastChar && tempLastChar != '>') {
            /*
             * Substring must be trimmable from behind in case of attribute 
             * proposal because a space or a new line must be used as delimiter 
             * between task name and attribute or attribute and attribute.
             * Example: '<property id="bla" name="hups"'
             */
             
            // Attribute proposal
            if(tempLastChar != '>' && tempLastChar != '<') {
                String tempTaskString =
                    getTaskStringFromDocumentStringToPrefix(
                        tempTrimmedString);
                if(tempTaskString != null && isNamedTaskKnown(tempTaskString)) {
                    return PROPOSAL_MODE_ATTRIBUTE_PROPOSAL;
                }
            }                
        }

        // Attribute value proposal
        else if(tempStringToPrefix.charAt(tempStringToPrefix.length()-1) == '"') {
            String tempTaskString =
                getTaskStringFromDocumentStringToPrefix(
                    tempTrimmedString);
            if(tempTaskString != null && isNamedTaskKnown(tempTaskString)) {
                return PROPOSAL_MODE_ATTRIBUTE_VALUE_PROPOSAL;
            }
        }
        
        // Task proposal
        else {
            int tempSpaceIndex = tempStringToPrefix.lastIndexOf(' ');
            int tempLessThanIndex = tempStringToPrefix.lastIndexOf('<');
            int tempGreaterThanIndex = tempStringToPrefix.lastIndexOf('>');
            
            // Task proposal
            if(tempLessThanIndex > tempSpaceIndex && tempGreaterThanIndex < tempLessThanIndex) {
                int tempSlashIndex = tempStringToPrefix.lastIndexOf('/');
                if(tempSlashIndex == tempLessThanIndex +1) {
                    return PROPOSAL_MODE_TASK_PROPOSAL_CLOSING; // ... </
                }
                return PROPOSAL_MODE_TASK_PROPOSAL;
            }
            if(tempLessThanIndex < tempGreaterThanIndex && "".equals(aPrefix)) { //$NON-NLS-1$
                
                // no other regular character may be between '>' and cursor position
                int tempActIndex = aCursorPosition;
                do {
                    char tempChar = tempStringToPrefix.charAt(--tempActIndex);
                    if(tempChar != ' ' && tempChar != '\t' && tempChar != '\n' && tempChar != '\r') {
                        break; // found a character -> no task proposal mode
                    }
                } while(tempActIndex > tempGreaterThanIndex);  

                // no character found in between                  
                if(tempActIndex == tempGreaterThanIndex) {           
                    return PROPOSAL_MODE_TASK_PROPOSAL;
                }
            }
        }

        // Property proposal
        if(tempStringToPrefix.length() >= 2) {
	        String tempLastTwoCharacters = tempStringToPrefix.substring(tempStringToPrefix.length()-2, tempStringToPrefix.length());
	        if(tempLastTwoCharacters.equals("${") || //$NON-NLS-1$
	            tempStringToPrefix.charAt(tempStringToPrefix.length()-1) == '$') {
	                return PROPOSAL_MODE_PROPERTY_PROPOSAL;
	        }
        }
        	            
        return PROPOSAL_MODE_NONE;
    }


    /**
     * Returns the last occuring task string in the specified string.
     * <P>
     * The returned string must not necessarily be a valid Ant task string.
     * This can be tested with the method <code>inNamedTaskKnown(String)</code>
     * after invoking this method.
     * 
     * @param aDocumentStringToPrefix the String that contains the whole string
     * of the currently edited file from the beginning up to the prefix for code
     * completion. Example: '<project default="name"><property '.
     * 
     * @return the extracted task string or <code>null</code> if no string could
     * be extracted.
     */
    private String getTaskStringFromDocumentStringToPrefix(
            String aDocumentStringToPrefix) {
            
        int tempLessThanIndex = aDocumentStringToPrefix.lastIndexOf('<');

        if(tempLessThanIndex > -1) {
            String tempTaskString = aDocumentStringToPrefix.trim();
            tempTaskString = tempTaskString.substring(tempLessThanIndex+1, tempTaskString.length());
            int tempIndex = tempTaskString.indexOf(' ');
            if(tempIndex > 0) {
                tempTaskString = tempTaskString.substring(0, tempIndex);
            }
            tempIndex = tempTaskString.indexOf('\n');
            if(tempIndex > 0) {
                tempTaskString = tempTaskString.substring(0, tempIndex);
            }
            tempIndex = tempTaskString.indexOf('\r');
            if(tempIndex > 0) {
                tempTaskString = tempTaskString.substring(0, tempIndex);
            }
            return tempTaskString;
        }
        
        return null;
    }
    

    /**
     * Returns the last occuring attribute string in the specified string.
     * <P>
     * Calling this method is only safe if the current proposal mode is really
     * <code>PROPOSAL_MODE_ATTRIBUTE_VALUE_PROPOSAL</code>.
     */
    private String getAttributeStringFromDocumentStringToPrefix(String aDocumentStringToPrefix) {
        int tempIndex = aDocumentStringToPrefix.lastIndexOf('=');
        String tempSubString = aDocumentStringToPrefix.substring(0, tempIndex);
        tempSubString = tempSubString.trim();
        
        tempIndex = tempSubString.lastIndexOf(' ');
        if(tempIndex > 0) {
            tempSubString = tempSubString.substring(tempIndex+1, tempSubString.length());
        }
        tempIndex = tempSubString.lastIndexOf('\n');
        if(tempIndex > 0) {
            tempSubString = tempSubString.substring(tempIndex+1, tempSubString.length());
        }
        tempIndex = tempSubString.lastIndexOf('\r');
        if(tempIndex > 0) {
            tempSubString = tempSubString.substring(tempIndex+1, tempSubString.length());
        }
        return tempSubString;
    }


    /**
     * Returns whether the specified task name is known according to the DTD.
     */
    private boolean isNamedTaskKnown(String aTaskName) {
        return dtd.getElement(aTaskName) != null;
    }


    /**
     * Finds the parent task element in respect to the cursor position.
     * 
     * @return the parent task element or <code>null</code> if not found.
     */
    protected Element findParentElement(String aWholeDocumentString, int aLineNumber, int aColumnNumber) {

        // Return the parent
        return parseEditedFileSearchingForParent(aWholeDocumentString, aLineNumber, aColumnNumber).getParentElement(true);      
    }
    

    /**
     * Parses the actually edited file as far as possible.
     * <P>
     * The returned handler can be asked about what happend while parsing
     * the document.
     * 
     * @return the handler that has been used for parsing or <code>null</code>
     * if parsing couldn't be done because of some error.
     */
    protected PlantySaxDefaultHandler parseEditedFileSearchingForParent(String aWholeDocumentString, int aLineNumber, int aColumnNumber) {
        // Get a new SAX Parser
        SAXParser tempParser = null;
        try {
            tempParser = SAXParserFactory.newInstance().newSAXParser();
        } catch (ParserConfigurationException e) {
            ExternalToolsPlugin.getDefault().log(e);
            return null;
        } catch (SAXException e) {
			ExternalToolsPlugin.getDefault().log(e);
            return null;
        }
        
        // Set the handler
        PlantySaxDefaultHandler tempHandler = null;
        File editedFile= getEditedFile();
        try {
			File parent = null;
			if(editedFile != null) {
				parent = editedFile.getParentFile();
			}
        	tempHandler = new PlantySaxDefaultHandler(parent, aLineNumber, aColumnNumber);
        } catch (ParserConfigurationException e) {
			ExternalToolsPlugin.getDefault().log(e);
        }
        
        // Parse!
        InputSource tempInputSource = new InputSource(new StringReader(aWholeDocumentString));
		if (editedFile != null) {
			//needed for resolving relative external entities
			tempInputSource.setSystemId(editedFile.getAbsolutePath());
		}
        try {
            tempParser.parse(tempInputSource, tempHandler);
        } catch(SAXParseException e) {
            // Ignore since that happens always if the edited file is not valid. We try to handle that.
        } catch (SAXException e) {
            ExternalToolsPlugin.getDefault().log(e);
        } catch (IOException e) {
            ExternalToolsPlugin.getDefault().log(e);
        }
        
        lastDefaultHandler = tempHandler; // bf
        return tempHandler;
    }


    /**
     * Parses the actually edited file as far as possible.
     * <P>
     * We use the parsing facilities of the ant plug-in here.
     * 
     * @return a map with all the found properties
     */
    protected Map findPropertiesFromDocument(String aWholeDocumentString) {
		/*
		 * What is implemented here:
		 * - We first use the ant plug-in to create a Project instance.
		 * - We determine the enclosing parent task element
		 * - We determine the dependency Vector for the parent task element
		 * - We work our way through the dependency Vector and execute the
		 *   Property relevant tasks.
		 */

        // Create an initialized project
        Project tempProject = new Project();
        tempProject.init();

        /* 
         * Ant's parsing facilities always works on a file, therefore we need
         * to determine the actual location of the file. Though the file 
         * contents will not be parsed. We parse the passed document string 
         * that is passed.
         */
        File tempFile = getEditedFile();
        String filePath= ""; //$NON-NLS-1$
        if (tempFile != null) {
			filePath= tempFile.getAbsolutePath();
        }
        tempProject.setUserProperty("ant.file", filePath); //$NON-NLS-1$

        try {
            ProjectHelper.configureProject(tempProject, tempFile, aWholeDocumentString);  // File will be parsed here
        }
        catch(BuildException e) {
            // ignore a build exception on purpose, since we also parse invalid
            // build files.
        }    
        Map properties = tempProject.getProperties();
        
        // Determine the parent
        Element tempElement = findEnclosingTargetElement(aWholeDocumentString, lineNumber, columnNumber);
        String tempTargetName = null;
        if(tempElement == null 
        		|| (tempTargetName = tempElement.getAttribute("name")) == null //$NON-NLS-1$
        		|| tempTargetName.length() == 0) {
        	return properties;
        }
        List tempSortedTargets = null;
        try {
        	tempSortedTargets= tempProject.topoSort(tempTargetName, tempProject.getTargets());
        } catch (BuildException be) {
			return tempProject.getProperties();
        }

        int curidx = 0;
        Target curtarget;

        do {
            curtarget = (Target) tempSortedTargets.get(curidx++);
			Task[] tempTasks = curtarget.getTasks();
			
			for (int i = 0; i < tempTasks.length; i++) {
				Task tempTask = tempTasks[i];                

				// sequential
				if(tempTask instanceof Sequential) {
					// (T)
				}
				
				// parallel
				if(tempTask instanceof Parallel) {
					// (T)
				}
				
				// waitfor (@since Ant 1.5)
	//			if(tempTask instanceof WaitFor) { 
	//				// (T)
	//			}
				
				if(tempTask instanceof Property 
					|| tempTask instanceof PathConvert
					|| tempTask instanceof Available
					|| tempTask instanceof UpToDate
					|| tempTask instanceof Condition) {
					((Task)tempTask).perform();					
				}
			
			
				// Ant 1.5
//				if(tempTask instanceof LoadFile) {
//				
//				}
			
				// Ant 1.5
//				if(tempTask instanceof XmlProperty) {
//				
//				}
			
				// Ant 1.5
//				if(tempTask instanceof Basename) {
//				
//				}
			
				
				// Ant 1.5
//				if(tempTask instanceof Dirname) {
//				
//				}
			
				// Ant 1.5
//				if(tempTask instanceof LoadProperties) {
//				
//				}
            }
        } while (!curtarget.getName().equals(tempTargetName));

        
        // Need to reget it since tempTable hasn't been updated with Ant 1.5
        return tempProject.getProperties();
    }

    protected File getEditedFile() {
    	IWorkbenchPage page= ExternalToolsPlugin.getActivePage();
    	if (page == null) {
    		return null;
    	}
		IEditorPart editor= page.getActiveEditor();
		if (editor == null) {
			return null;
		}
        FileEditorInput tempInput = (FileEditorInput) editor.getEditorInput();
        String tempProjectPath = tempInput.getFile().getProject().getLocation().toFile().getAbsolutePath();
        String tempProjectRelativeFilePath = tempInput.getFile().getFullPath().removeFirstSegments(1).makeRelative().toString();
        File tempFile = new File(tempProjectPath + File.separator +tempProjectRelativeFilePath);
        return tempFile;
    }

    /**
     * Finds the parent task element in respect to the cursor position which
     * that has not been closed yet.
     * 
     * @return the not closed parent task element or <code>null</code> if not 
     * found.
     */
    protected Element findNotClosedParentElement(String aWholeDocumentString, int aLineNumber, int aColumnNumber) {
        PlantySaxDefaultHandler tempHandler = parseEditedFileSearchingForParent(aWholeDocumentString, aLineNumber, aColumnNumber);
        if(tempHandler != null) {
            
            // A not closed parent element can only be found by guessing.
            if(tempHandler.getParentElement(false) == null) {
                return tempHandler.getParentElement(true);
            }

        }
        return null;
    }
 

    /**
     * Finds the enclosing target element in respect to the cursor position. 
     * 
     * @return the enclosing target element or <code>null</code> if not found.
     */
 	protected Element findEnclosingTargetElement(String aWholeDocumentString, int aLineNumber, int aColumnNumber) {

        // Get a new SAX Parser
        SAXParser tempParser = null;
        try {
            tempParser = SAXParserFactory.newInstance().newSAXParser();
        } catch (ParserConfigurationException e) {
            ExternalToolsPlugin.getDefault().log(e);
            return null;
        } catch (SAXException e) {
            ExternalToolsPlugin.getDefault().log(e);
            return null;
        }
        
        // Set the handler
        EnclosingTargetSearchingHandler tempHandler = null;
		File editedFile= getEditedFile();
        try {
		   File parent = null;
		   if(editedFile != null) {
			   parent = editedFile.getParentFile();
		   }
            tempHandler = new EnclosingTargetSearchingHandler(parent, aLineNumber, aColumnNumber);
        } catch (ParserConfigurationException e) {
            ExternalToolsPlugin.getDefault().log(e);
        }
        
        // Parse!
        InputSource tempInputSource = new InputSource(new StringReader(aWholeDocumentString));
		if (editedFile != null) {
			//needed for resolving relative external entities
			tempInputSource.setSystemId(editedFile.getAbsolutePath());
		}
        try {
            tempParser.parse(tempInputSource, tempHandler);
        } catch(SAXParseException e) {
            // Ignore since that happens always if the edited file is not valid. We try to handle that.
        } catch (SAXException e) {
            ExternalToolsPlugin.getDefault().log(e);
        } catch (IOException e) {
            ExternalToolsPlugin.getDefault().log(e);
        }

		return tempHandler.getParentElement(true);
 	}
}

Back to the top