Search in sources :

Example 1 with DOMModelForJSP

use of org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP in project webtools.sourceediting by eclipse.

the class JSPTranslationTest method testXMLJSPTranslationText.

/**
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=86382
 */
public void testXMLJSPTranslationText() {
    IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/xml-jsp/most-tags-xml-jsp.jsp"));
    DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
    try {
        setupAdapterFactory(sModel);
        JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
        JSPTranslation translation = adapter.getJSPTranslation();
        String javaText = translation.getJavaText();
        // named as .bin so no line conversion occurs (\n is in use)
        InputStream in = getClass().getResourceAsStream("translated_xml_jsp.bin");
        String knownTranslationText = loadChars(in);
        assertEquals(knownTranslationText, javaText);
    } finally {
        if (sModel != null)
            sModel.releaseFromRead();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) DOMModelForJSP(org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP) InputStream(java.io.InputStream) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 2 with DOMModelForJSP

use of org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP in project webtools.sourceediting by eclipse.

the class JSPTranslationTest method testUseBeanNoSpace.

/**
 * Makes sure both beans are translated even though they are
 * right next to each other with no space.
 *
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=103004
 */
public void testUseBeanNoSpace() {
    IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/useBean_tester.jsp"));
    DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
    try {
        setupAdapterFactory(sModel);
        JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
        JSPTranslation translation = adapter.getJSPTranslation();
        String javaText = translation.getJavaText();
        boolean bean1 = javaText.indexOf("javax.swing.JButton x = null;") != -1;
        boolean bean2 = javaText.indexOf("javax.swing.JButton y = null;") != -1;
        assertTrue(bean1);
        assertTrue(bean2);
    } finally {
        if (sModel != null)
            sModel.releaseFromRead();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) DOMModelForJSP(org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 3 with DOMModelForJSP

use of org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP in project webtools.sourceediting by eclipse.

the class JSPTranslationTest method testXMLJSPMapping.

public void testXMLJSPMapping() {
    IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/xml-jsp/most-tags-xml-jsp.jsp"));
    DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
    try {
        setupAdapterFactory(sModel);
        JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
        JSPTranslation translation = adapter.getJSPTranslation();
        HashMap jsp2java = translation.getJsp2JavaMap();
        Object[] jspRanges = jsp2java.keySet().toArray();
        Position jspPos = null;
        Position javaPos = null;
        for (int i = 0; i < jspRanges.length; i++) {
            jspPos = (Position) jspRanges[i];
            javaPos = (Position) jsp2java.get(jspPos);
            // System.out.println("jsp:" + printPos(jspPos) + " >> java:" + printPos(javaPos));
            checkPosition(jspPos, javaPos);
        }
    } finally {
        if (sModel != null)
            sModel.releaseFromRead();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) DOMModelForJSP(org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 4 with DOMModelForJSP

use of org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP in project webtools.sourceediting by eclipse.

the class JSPTranslationTest method testXMLJSPCDATAText.

public void testXMLJSPCDATAText() {
    IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/cdata/cdata.jsp"));
    DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
    try {
        setupAdapterFactory(sModel);
        JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
        JSPTranslation translation = adapter.getJSPTranslation();
        String transText = translation.getJavaText();
        // named as .bin so no line conversion occurs (\n is in use)
        InputStream in = getClass().getResourceAsStream("translated_xml_jsp_cdata.bin");
        String knownText = loadChars(in);
        assertEquals(knownText, transText);
    } finally {
        if (sModel != null)
            sModel.releaseFromRead();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) DOMModelForJSP(org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP) InputStream(java.io.InputStream) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Aggregations

IFile (org.eclipse.core.resources.IFile)4 IPath (org.eclipse.core.runtime.IPath)4 Path (org.eclipse.core.runtime.Path)4 DOMModelForJSP (org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP)4 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)4 JSPTranslation (org.eclipse.jst.jsp.core.internal.java.JSPTranslation)4 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)4 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)1 Position (org.eclipse.jface.text.Position)1