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

Collapse All | Expand All

(-)metadata/checkmodeop_dti.xml (+60 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<md:metadatamodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" 
4
    xmlns:md="http://org.eclipse.jst.jsf.common.metadata/metadata.ecore"
5
    xmlns:dti="http://org.eclipse.jsf.pagedesigner/dtinfo.ecore"
6
    id="org.eclipse.jst.pagedesigner.tests.testCheckModeOperation"
7
    type="tagFile">
8
9
    <entity id="testTagOne" type="tag">
10
        <trait id="dt-info">
11
            <value xsi:type="dti:DTInfo">
12
                <tag-convert-info>
13
                    <operation id="org.eclipse.jst.pagedesigner.CheckModeOperation">
14
                        <parameter value="design"/>
15
                        <operation id="org.eclipse.jst.pagedesigner.CreateElementOperation">
16
                            <parameter value="div"/>
17
                        </operation>
18
                        <operation id="org.eclipse.jst.pagedesigner.CopyChildrenOperation"/>
19
                    </operation>
20
                </tag-convert-info>
21
                <tag-decorate-info id="vpd-decorate-preview"
22
                        nonVisual="true"
23
                />
24
            </value>
25
        </trait>
26
    </entity>
27
    
28
    <entity id="testTagTwo" type="tag">
29
        <trait id="dt-info">
30
            <value xsi:type="dti:DTInfo">
31
                <tag-convert-info>
32
                    <operation id="org.eclipse.jst.pagedesigner.CreateElementOperation">
33
                        <parameter value="div"/>
34
                    </operation>
35
                    <operation id="org.eclipse.jst.pagedesigner.CheckModeOperation">
36
                        <parameter value="design"/>
37
                        <operation id="org.eclipse.jst.pagedesigner.CopyAttributeOperation">
38
                            <parameter value="requiredAttr1"/>
39
                        </operation>
40
                        <operation id="org.eclipse.jst.pagedesigner.RenameAttributeOperation">
41
                            <parameter value="requiredAttr1"/>
42
                            <parameter value="id"/>
43
                        </operation>
44
                    </operation>
45
                    <operation id="org.eclipse.jst.pagedesigner.CheckModeOperation">
46
                        <parameter value="preview"/>
47
                        <operation id="org.eclipse.jst.pagedesigner.CopyAttributeOperation">
48
                            <parameter value="requiredAttr2"/>
49
                        </operation>
50
                        <operation id="org.eclipse.jst.pagedesigner.RenameAttributeOperation">
51
                            <parameter value="requiredAttr2"/>
52
                            <parameter value="id"/>
53
                        </operation>
54
                    </operation>
55
                </tag-convert-info>
56
            </value>
57
        </trait>
58
    </entity>
59
60
</md:metadatamodel>
(-)plugin.xml (+4 lines)
Lines 4-9 Link Here
4
   <extension
4
   <extension
5
         point="org.eclipse.jst.jsf.common.standardMetaDataFiles">
5
         point="org.eclipse.jst.jsf.common.standardMetaDataFiles">
6
      <standardMetaDataFile
6
      <standardMetaDataFile
7
            location="/metadata/checkmodeop_dti.xml"
8
            uri="org.eclipse.jst.pagedesigner.tests.testCheckModeOperation">
9
      </standardMetaDataFile>
10
      <standardMetaDataFile
7
            location="/metadata/test-metadata.xml"
11
            location="/metadata/test-metadata.xml"
8
            uri="org.eclipse.jst.pagedesigner.tests.tagCreatorFactory1">
12
            uri="org.eclipse.jst.pagedesigner.tests.tagCreatorFactory1">
9
      </standardMetaDataFile>
13
      </standardMetaDataFile>
(-)src/org/eclipse/jst/pagedesigner/tests/Test_TransformOperations.java (-36 / +160 lines)
Lines 180-185 Link Here
180
	}
180
	}
181
181
182
	/**
182
	/**
183
	 * Test "CheckModeOperation".
184
	 */
185
	public void testCheckModeOperation() {
186
		try {
187
	        webProjectTestEnv.loadResourceInWebRoot
188
	        (PageDesignerTestsPlugin.getDefault().getBundle()
189
	            , "/testdata/checkmodeop/checkModeOp.tld.data"
190
	            , "/META-INF/checkModeOp.tld");
191
192
	        webProjectTestEnv.loadResourceInWebRoot(
193
	            PageDesignerTestsPlugin.getDefault().getBundle()
194
	            ,"/testdata/checkmodeop/testCheckModeOperation.jsp.data"
195
	            ,"/testCheckModeOperation.jsp");
196
197
	        ContextWrapper wrapper = null;
198
199
	        // First converter is simple use of CheckModeOperation
200
	        // containing child operations.
201
	        // Exercises both design and preview mode, but there should
202
	        // only be conversion for design view based on the design
203
	        // time info traits in the meta-data for this test.
204
	        try {
205
		        wrapper = 
206
		        	getDocumentContext("/WebContent/testCheckModeOperation.jsp", 365);
207
208
		        String prefix = "cmo";
209
		        String localName = "testTagOne";
210
				ITagConverter tagConverter = 
211
					getTagConverter(wrapper, prefix, localName, IConverterFactory.MODE_DESIGNER);
212
	            assertNotNull(tagConverter);
213
214
	            // invoke ITagConverter instance
215
	            tagConverter.convertRefresh(null);
216
217
	            // get and test result element
218
				Element resultElement = tagConverter.getResultElement();
219
				assertNotNull(resultElement);
220
				assertEquals("div", resultElement.getLocalName());
221
222
	            // Ensure correct child element was copied to child node list.
223
				// First child is text node, look at second child.
224
	            List<?> childNodes = tagConverter.getChildModeList();
225
	            assertTrue(childNodes.size() > 1);
226
	            Node secondChildNode = (Node)childNodes.get(1);
227
	            assertTrue(secondChildNode instanceof Element);
228
	            Element secondChildElement = (Element)secondChildNode;
229
	            assertEquals("span", secondChildElement.getLocalName());
230
	            assertEquals("t1ChildSpan", secondChildElement.getAttribute("id"));
231
232
				// now try in preview mode
233
				tagConverter = 
234
					getTagConverter(wrapper, prefix, localName, IConverterFactory.MODE_PREVIEW);
235
	            assertNotNull(tagConverter);
236
237
	            // invoke ITagConverter instance
238
	            tagConverter.convertRefresh(null);
239
240
	            // get and test result element
241
				resultElement = tagConverter.getResultElement();
242
				assertNull(resultElement);
243
	        } finally {
244
				if (wrapper != null) {
245
					wrapper.dispose();
246
				}
247
	        }
248
249
	        // Second tag converter has the CheckModeOperation
250
	        // as a sibling operation for additional transforms.
251
	        // Exercises both design and preview mode.
252
	        try {
253
		        wrapper = 
254
		        	getDocumentContext("/WebContent/testCheckModeOperation.jsp", 531);
255
256
		        String prefix = "cmo";
257
		        String localName = "testTagTwo";
258
259
		        // test conversion for design mode
260
				ITagConverter tagConverter = 
261
					getTagConverter(wrapper, prefix, localName, IConverterFactory.MODE_DESIGNER);
262
	            assertNotNull(tagConverter);
263
264
	            // invoke ITagConverter instance
265
	            tagConverter.convertRefresh(null);
266
267
	            // get and test result element
268
				Element resultElement = tagConverter.getResultElement();
269
				assertNotNull(resultElement);
270
				assertEquals("div", resultElement.getLocalName());
271
				assertEquals("designId", resultElement.getAttribute("id"));
272
273
				// now try in preview mode
274
				tagConverter = 
275
					getTagConverter(wrapper, prefix, localName, IConverterFactory.MODE_PREVIEW);
276
	            assertNotNull(tagConverter);
277
278
	            // invoke ITagConverter instance
279
	            tagConverter.convertRefresh(null);
280
281
	            // get and test result element
282
				resultElement = tagConverter.getResultElement();
283
				assertNotNull(resultElement);
284
				assertEquals("div", resultElement.getLocalName());
285
				assertEquals("previewId", resultElement.getAttribute("id"));
286
	        } finally {
287
				if (wrapper != null) {
288
					wrapper.dispose();
289
				}
290
	        }
291
		} catch(Exception ex) {
292
			ex.printStackTrace();
293
			fail(ex.getLocalizedMessage());
294
		}
295
	}
296
297
298
	/**
183
	 * Test "ConvertAttributeToTextOperation".
299
	 * Test "ConvertAttributeToTextOperation".
184
	 */
300
	 */
185
	public void testConvertAttributeToTextOperation() {
301
	public void testConvertAttributeToTextOperation() {
Lines 519-559 Link Here
519
		ContextWrapper wrapper = null;
635
		ContextWrapper wrapper = null;
520
		try {
636
		try {
521
			wrapper = getDocumentContext("/WebContent/Test_TransformOperations.jsp", docOffset);
637
			wrapper = getDocumentContext("/WebContent/Test_TransformOperations.jsp", docOffset);
522
			IStructuredDocumentContext context = wrapper.getContext();
638
			ITagConverter tagConverter =
523
            IDOMContextResolver resolver =
639
				getTagConverter(wrapper, prefix, localName, IConverterFactory.MODE_DESIGNER);
524
                IStructuredDocumentContextResolverFactory.INSTANCE.
640
            if (tagConverter != null) {
525
                    getDOMContextResolver(context);
641
    			
526
642
	            //invoke ITagConverter instance
527
            //get Element
643
	            tagConverter.convertRefresh(null);
528
            Node node = resolver.getNode();
644
	
529
            if (
645
	            //get result element
530
            		node instanceof Element &&
646
	            resultElement = tagConverter.getResultElement();
531
            		node.getPrefix().equals(prefix) &&
532
            		node.getLocalName().equals(localName)) {
533
534
            	Element element = (Element)node;
535
536
	            //get IDOMDocument
537
	            IStructuredModel model = wrapper.getModel();
538
	            if (model instanceof IDOMModel) {
539
		            IDOMDocument document = ((IDOMModel)model).getDocument();
540
		            if (document != null) {
541
		
542
			            //get ITagConverter instance
543
			            ITagConverter tagConverter = DTManager.getInstance().getTagConverter(
544
			            		element,
545
			            		IConverterFactory.MODE_DESIGNER,
546
			            		document);
547
			            if (tagConverter != null) {
548
			
549
				            //invoke ITagConverter instance
550
				            tagConverter.convertRefresh(null);
551
				
552
				            //get result element
553
				            resultElement = tagConverter.getResultElement();
554
			            }
555
		            }
556
	            }
557
            }
647
            }
558
		} finally {
648
		} finally {
559
			if (wrapper != null) {
649
			if (wrapper != null) {
Lines 563-568 Link Here
563
		return resultElement;
653
		return resultElement;
564
	}
654
	}
565
655
656
	private ITagConverter getTagConverter(ContextWrapper wrapper, String prefix,
657
			String localName, int mode) throws Exception {
658
    	ITagConverter tagConverter = null;
659
		IStructuredDocumentContext context = wrapper.getContext();
660
        IDOMContextResolver resolver =
661
            IStructuredDocumentContextResolverFactory.INSTANCE.
662
                getDOMContextResolver(context);
663
664
        //get Element
665
        Node node = resolver.getNode();
666
        if (
667
        		node instanceof Element &&
668
        		node.getPrefix().equals(prefix) &&
669
        		node.getLocalName().equals(localName)) {
670
671
        	Element element = (Element)node;
672
673
            //get IDOMDocument
674
            IStructuredModel model = wrapper.getModel();
675
            if (model instanceof IDOMModel) {
676
	            IDOMDocument document = ((IDOMModel)model).getDocument();
677
	            if (document != null) {
678
	
679
		            //get ITagConverter instance
680
		            tagConverter = DTManager.getInstance().getTagConverter(
681
		            		element,
682
		            		mode,
683
		            		document);
684
	            }
685
            }
686
        }
687
688
        return tagConverter;
689
    }
690
566
    private ContextWrapper getDocumentContext(String path, int offset) throws Exception {
691
    private ContextWrapper getDocumentContext(String path, int offset) throws Exception {
567
        IProject project = webProjectTestEnv.getTestProject();
692
        IProject project = webProjectTestEnv.getTestProject();
568
        IFile jspFile = project.getFile(new Path(path));
693
        IFile jspFile = project.getFile(new Path(path));
Lines 597-601 Link Here
597
            model.releaseFromRead();
722
            model.releaseFromRead();
598
        }
723
        }
599
    }
724
    }
600
601
}
725
}
(-)testdata/checkmodeop/checkModeOp.tld.data (+72 lines)
Added Link Here
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
3
<!DOCTYPE taglib
4
  PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
5
  "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
6
7
8
<taglib>
9
10
11
  <!-- ========== Tag Library Description Elements ========================= -->
12
13
14
  <tlib-version>1.0</tlib-version>
15
  <jsp-version>1.2</jsp-version>
16
  <short-name>testCheckModeOperation</short-name>
17
  <uri>org.eclipse.jst.pagedesigner.tests.testCheckModeOperation</uri>
18
  <description>
19
   A test tld used for verifying the CheckModeOperation.
20
  </description>
21
22
  <!-- ========== Tag Descriptions ========================================= -->
23
24
25
  <tag>
26
    <name>testTagOne</name>
27
    <tag-class>com.foo.SomeClassOne</tag-class>
28
    <body-content>JSP</body-content>
29
    <description>
30
       A simple test tag. This test includes design time metadata mapped to
31
       this tag to exercise the CheckModeOperation.
32
    </description>
33
34
    <attribute>
35
      <name>notRequiredAttr1</name>
36
      <required>false</required>
37
      <rtexprvalue>false</rtexprvalue>
38
      <description>
39
          This attribute is optional.
40
      </description>
41
    </attribute>
42
  </tag>
43
44
  <tag>
45
    <name>testTagTwo</name>
46
    <tag-class>com.foo.SomeClassTwo</tag-class>
47
    <body-content>JSP</body-content>
48
    <description>
49
       A simple test tag. This test includes design time metadata mapped to
50
       this tag to exercise the CheckModeOperation.
51
    </description>
52
53
    <attribute>
54
      <name>requiredAttr1</name>
55
      <required>true</required>
56
      <rtexprvalue>false</rtexprvalue>
57
      <description>
58
          This attribute is required.
59
      </description>
60
    </attribute>
61
62
    <attribute>
63
      <name>requiredAttr2</name>
64
      <required>true</required>
65
      <rtexprvalue>false</rtexprvalue>
66
      <description>
67
          This attribute is required.
68
      </description>
69
    </attribute>
70
  </tag>
71
72
</taglib>
(-)testdata/checkmodeop/testCheckModeOperation.jsp.data (+27 lines)
Added Link Here
1
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
2
<%@taglib uri="org.eclipse.jst.pagedesigner.tests.testCheckModeOperation" prefix="cmo"%>
3
4
<html>
5
<head>
6
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7
    <title>Test CheckModeOperation</title>
8
</head>
9
<body>
10
    <div id="t1Div">
11
        <cmo:testTagOne>
12
            <span id="t1ChildSpan">
13
                some text
14
            </span>
15
        </cmo:testTagOne>
16
    </div>
17
18
    <div id="t2Div">
19
        <cmo:testTagTwo requiredAttr1="designId"
20
                        requiredAttr2="previewId">
21
            <span id="t2ChildSpan">
22
                some text
23
            </span>
24
        </cmo:testTagTwo>
25
    </div>
26
</body>
27
</html>

Return to bug 252861