Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Servlet/Filter/Listener generation for Jakarta based projects #6984

Merged
merged 2 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
*
* @author Petr Jiricka
*/
// @todo: Support JakartaEE
public final class JspColoringData extends PropertyChangeSupport {

/** An property whose change is fired every time the tag library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import javax.swing.text.Caret;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.source.ClasspathInfo;
import org.netbeans.modules.editor.indent.api.Indent;
import org.netbeans.api.java.source.CompilationController;
Expand All @@ -50,15 +51,14 @@
*
* @author Libor Kotouc
*/
// @todo: Support JakartaEE
public final class JspPaletteUtilities {

public static final String CARET = "&CARET&";// NOI18N
private static final String JSTL_PREFIX = "c"; //NOI18N
private static final String JSTL_URI = "http://java.sun.com/jsp/jstl/core"; //NOI18N
private static final String SQL_PREFIX = "sql"; //NOI18N
private static final String SQL_URI = "http://java.sun.com/jsp/jstl/sql"; //NOI18N

public static void insert(String s, JTextComponent target) throws BadLocationException {
insert(s, target, true);
}
Expand Down Expand Up @@ -143,6 +143,15 @@ public static PageInfo.BeanData[] getAllBeans(JTextComponent target) {
return null;
}

public static boolean isJakartaVariant(JTextComponent target) {
FileObject fobj = getFileObject(target);
if(fobj != null) {
ClassPath cp = ClassPath.getClassPath(fobj, ClassPath.COMPILE);
return cp != null && cp.findResource("jakarta/servlet/http/HttpServletRequest.class") != null;
}
return false;
}

public static boolean idExists(String id, PageInfo.BeanData[] beanData) {
boolean res = false;
if (id != null && beanData != null) {
Expand All @@ -160,11 +169,8 @@ public static boolean idExists(String id, PageInfo.BeanData[] beanData) {
public static boolean typeExists(JTextComponent target, final String fqcn) {
final boolean[] result = {false};
if (fqcn != null) {
runUserActionTask(target, new Task<CompilationController>() {

public void run(CompilationController parameter) throws Exception {
result[0] = parameter.getElements().getTypeElement(fqcn) != null;
}
runUserActionTask(target, (CompilationController parameter) -> {
result[0] = parameter.getElements().getTypeElement(fqcn) != null;
});
}
return result[0];
Expand All @@ -185,10 +191,11 @@ private static void runUserActionTask(JTextComponent target, Task<CompilationCon
}

public static List<String> getTypeProperties(JTextComponent target, final String fqcn, final String[] prefix) {
final List<String> result = new ArrayList<String>();
final List<String> result = new ArrayList<>();
if (prefix != null) {
runUserActionTask(target, new Task<CompilationController>() {

@Override
public void run(CompilationController parameter) throws Exception {
TypeElement te = parameter.getElements().getTypeElement(fqcn);
if (te != null) {
Expand Down Expand Up @@ -236,7 +243,7 @@ private boolean match(String methodName, String[] prefix) {
}
return result;
}

/**************************************************************************/
public static String getTagLibPrefix(JTextComponent target, String tagLibUri) {
FileObject fobj = getFileObject(target);
Expand All @@ -251,7 +258,7 @@ public static String getTagLibPrefix(JTextComponent target, String tagLibUri) {
}
return null;
}

/**************************************************************************/
public static String findJstlPrefix(JTextComponent target) {
String res = getTagLibPrefix(target, JSTL_URI);
Expand Down Expand Up @@ -298,5 +305,5 @@ private static void insertTagLibRef(JTextComponent target, String prefix, String
});
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*
* @author Libor Kotouc
*/
// @todo: Support JakartaEE
public class GetProperty implements ActiveEditorDrop {

public static final String[] implicitBeans = new String[] { // NOI18N
Expand All @@ -43,34 +42,46 @@ public class GetProperty implements ActiveEditorDrop {
"session",
"application",
"out",
"config",
"page",
"exception"
"config",
"page",
"exception"
};
public static final int BEAN_DEFAULT = 0;
public static final String[] implicitTypes = new String[] { // NOI18N
"javax.servlet.http.HttpServletRequest",
"javax.servlet.http.HttpServletRequest",
"javax.servlet.http.HttpServletResponse",
"javax.servlet.jsp.PageContext",
"javax.servlet.http.HttpSession",
"javax.servlet.ServletContext",
"javax.servlet.jsp.JspWriter",
"javax.servlet.ServletConfig",
"java.lang.Object",
"java.lang.Throwable"
"java.lang.Throwable"
};
protected List<BeanDescr> allBeans = new ArrayList<BeanDescr>();
public static final String[] implicitTypesJakarta = new String[] { // NOI18N
"jakarta.servlet.http.HttpServletRequest",
"jakarta.servlet.http.HttpServletResponse",
"jakarta.servlet.jsp.PageContext",
"jakarta.servlet.http.HttpSession",
"jakarta.servlet.ServletContext",
"jakarta.servlet.jsp.JspWriter",
"jakarta.servlet.ServletConfig",
"java.lang.Object",
"java.lang.Throwable"
};
protected List<BeanDescr> allBeans = new ArrayList<>();
private int beanIndex = BEAN_DEFAULT;
private String bean = "";
private String property = "";

public GetProperty() {
}

@Override
public boolean handleTransfer(JTextComponent targetComponent) {
allBeans = initAllBeans(targetComponent);
GetPropertyCustomizer c = new GetPropertyCustomizer(this, targetComponent);

boolean accept = c.showDialog();
if (accept) {
String body = createBody();
Expand All @@ -80,21 +91,20 @@ public boolean handleTransfer(JTextComponent targetComponent) {
accept = false;
}
}

return accept;
}

private String createBody() {
String strBean = " name=\"\""; // NOI18N
if (beanIndex == -1)
String strBean; // NOI18N
if (beanIndex == -1) {
strBean = " name=\"" + bean + "\""; // NOI18N
else
} else {
strBean = " name=\"" + allBeans.get(beanIndex).getId() + "\""; // NOI18N

}

String strProperty = " property=\"" + property + "\""; // NOI18N

String gp = "<jsp:getProperty" + strBean + strProperty + " />"; // NOI18N
return gp;
return "<jsp:getProperty" + strBean + strProperty + " />"; // NOI18N
}

public int getBeanIndex() {
Expand Down Expand Up @@ -122,10 +132,17 @@ public void setProperty(String property) {
}

protected List<BeanDescr> initAllBeans(JTextComponent targetComponent) {
ArrayList<BeanDescr> res = new ArrayList<BeanDescr>();
String[] types;
if(JspPaletteUtilities.isJakartaVariant(targetComponent)) {
types = implicitTypesJakarta;
} else {
types = implicitTypes;
}

ArrayList<BeanDescr> res = new ArrayList<>();
for (int i = 0; i < implicitBeans.length; i++) {
String id = implicitBeans[i];
String fqcn = implicitTypes[i];
String fqcn = types[i];
res.add(new BeanDescr(id, fqcn));
}
PageInfo.BeanData[] bd = JspPaletteUtilities.getAllBeans(targetComponent);
Expand All @@ -137,7 +154,7 @@ protected List<BeanDescr> initAllBeans(JTextComponent targetComponent) {

return res;
}

class BeanDescr {
private String id;
private String fqcn;
Expand Down Expand Up @@ -167,9 +184,9 @@ public BeanDescr(String id, String fqcn) {
public String toString() {
return id;
}

}

public List<BeanDescr> getAllBeans(){
return allBeans;
}
Expand Down
Loading
Loading