mbien commented on code in PR #8550:
URL: https://github.com/apache/netbeans/pull/8550#discussion_r2118145048


##########
enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/HtmlSourceTask.java:
##########
@@ -105,45 +110,45 @@ public void run(HtmlParserResult result, SchedulerEvent 
event) {
         }
 
         //enable css class embedding in default facelets libraries tags
-        //TODO this should be done in some more generic way but so far I 
haven't
-        //found a way how to get an info if a tag's attribute represents css 
class or not.
-        //It seems that almost only html library contains such tags, we should
-        //probably create some metadata also for third party libraries
-
-        //check if the default html library is defined
-        String prefix = NamespaceUtils.getForNs(result.getNamespaces(), 
DefaultLibraryInfo.HTML.getNamespace());
-        if (prefix != null) {
-            //html lib declared, lets build a map of tags containing 
attributes whose values are
-            //supposed to represent a css class. The map is then put into the 
document's
-            //input attributes and then html lexer takes this information into 
account
-            //when lexing the html code
-            Map<String, Collection<String>> cssClassTagAttrMap = new 
HashMap<>();
-            Library lib = 
sup.getLibrary(DefaultLibraryInfo.HTML.getNamespace());
+        Map<String, Collection<String>> cssClassTagAttrMap = new HashMap<>();
+        
+        //lets build a map of tags containing attributes whose values are
+        //supposed to represent a css class. The map is then put into the 
document's
+        //input attributes and then html lexer takes this information into 
account
+        //when lexing the html code
+        for (Map.Entry<String, String> entry : 
result.getNamespaces().entrySet()) {
+            String prefix = entry.getValue();
+            if (prefix == null) {
+                continue;
+            }
+            String namespace = entry.getKey();
+            LibraryInfo libraryInfo = 
DefaultLibraryInfo.forNamespace(namespace);
+            if (libraryInfo == DefaultLibraryInfo.FACELETS || libraryInfo == 
DefaultLibraryInfo.JSF || libraryInfo == DefaultLibraryInfo.COMPOSITE ||
+                    libraryInfo == DefaultLibraryInfo.JSF_CORE || libraryInfo 
== DefaultLibraryInfo.JSTL_CORE
+                    || libraryInfo == DefaultLibraryInfo.JSTL_CORE_FUNCTIONS 
|| libraryInfo == DefaultLibraryInfo.PASSTHROUGH) {
+                continue;
+            }
+
+            Library lib = sup.getLibrary(namespace);
             if (lib != null) {
                 Collection<? extends LibraryComponent> components = 
lib.getComponents();
                 for (LibraryComponent comp : components) {
                     Tag tag = comp.getTag();
-                    //hacking datatable's attributes embedding - waiting for 
Tomasz' tag metadata API
-                    if ("dataTable".equals(tag.getName())) { //NOI18N
-                        cssClassTagAttrMap.put(prefix + ":" + tag.getName(),
-                                Arrays.asList(new 
String[]{STYLE_CLASS_ATTR_NAME,
-                                    "headerClass", "footerClass", 
"rowClasses", "columnClasses", "captionClass"})); //NOI18N
-                    } else {
-                        if (tag.getAttribute(STYLE_CLASS_ATTR_NAME) != null) {
-                            cssClassTagAttrMap.put(prefix + ":" + 
tag.getName(), Collections.singletonList(STYLE_CLASS_ATTR_NAME));
-                        }
+                    if (tag == null) {
+                        continue;
+                    }
+                    List<String> cssClassAttributes = 
tag.getAttributes().stream()
+                            .map(Attribute::getName)
+                            .filter(name -> 
name.toLowerCase(Locale.US).contains(CLASS_LOWERCASE) && 
!CLASS_LOWERCASE.equals(name))

Review Comment:
   I think we use `Locale.ROOT` for situations like this here where no special 
conversion handling is needed.



##########
enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/HtmlSourceTask.java:
##########
@@ -105,45 +110,45 @@ public void run(HtmlParserResult result, SchedulerEvent 
event) {
         }
 
         //enable css class embedding in default facelets libraries tags
-        //TODO this should be done in some more generic way but so far I 
haven't
-        //found a way how to get an info if a tag's attribute represents css 
class or not.
-        //It seems that almost only html library contains such tags, we should
-        //probably create some metadata also for third party libraries
-
-        //check if the default html library is defined
-        String prefix = NamespaceUtils.getForNs(result.getNamespaces(), 
DefaultLibraryInfo.HTML.getNamespace());
-        if (prefix != null) {
-            //html lib declared, lets build a map of tags containing 
attributes whose values are
-            //supposed to represent a css class. The map is then put into the 
document's
-            //input attributes and then html lexer takes this information into 
account
-            //when lexing the html code
-            Map<String, Collection<String>> cssClassTagAttrMap = new 
HashMap<>();
-            Library lib = 
sup.getLibrary(DefaultLibraryInfo.HTML.getNamespace());
+        Map<String, Collection<String>> cssClassTagAttrMap = new HashMap<>();
+        
+        //lets build a map of tags containing attributes whose values are
+        //supposed to represent a css class. The map is then put into the 
document's
+        //input attributes and then html lexer takes this information into 
account
+        //when lexing the html code
+        for (Map.Entry<String, String> entry : 
result.getNamespaces().entrySet()) {
+            String prefix = entry.getValue();
+            if (prefix == null) {
+                continue;
+            }
+            String namespace = entry.getKey();
+            LibraryInfo libraryInfo = 
DefaultLibraryInfo.forNamespace(namespace);
+            if (libraryInfo == DefaultLibraryInfo.FACELETS || libraryInfo == 
DefaultLibraryInfo.JSF || libraryInfo == DefaultLibraryInfo.COMPOSITE ||
+                    libraryInfo == DefaultLibraryInfo.JSF_CORE || libraryInfo 
== DefaultLibraryInfo.JSTL_CORE
+                    || libraryInfo == DefaultLibraryInfo.JSTL_CORE_FUNCTIONS 
|| libraryInfo == DefaultLibraryInfo.PASSTHROUGH) {
+                continue;
+            }

Review Comment:
   This could be extracted to an `EnumSet<DefaultLibraryInfo>` constant and 
replaced with
   
    `if (LIB_INFO_IGNORE.contains(libraryInfo)) {...`



##########
enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/HtmlSourceTask.java:
##########
@@ -105,45 +110,45 @@ public void run(HtmlParserResult result, SchedulerEvent 
event) {
         }
 
         //enable css class embedding in default facelets libraries tags
-        //TODO this should be done in some more generic way but so far I 
haven't
-        //found a way how to get an info if a tag's attribute represents css 
class or not.
-        //It seems that almost only html library contains such tags, we should
-        //probably create some metadata also for third party libraries
-
-        //check if the default html library is defined
-        String prefix = NamespaceUtils.getForNs(result.getNamespaces(), 
DefaultLibraryInfo.HTML.getNamespace());
-        if (prefix != null) {
-            //html lib declared, lets build a map of tags containing 
attributes whose values are
-            //supposed to represent a css class. The map is then put into the 
document's
-            //input attributes and then html lexer takes this information into 
account
-            //when lexing the html code
-            Map<String, Collection<String>> cssClassTagAttrMap = new 
HashMap<>();
-            Library lib = 
sup.getLibrary(DefaultLibraryInfo.HTML.getNamespace());
+        Map<String, Collection<String>> cssClassTagAttrMap = new HashMap<>();
+        
+        //lets build a map of tags containing attributes whose values are
+        //supposed to represent a css class. The map is then put into the 
document's
+        //input attributes and then html lexer takes this information into 
account
+        //when lexing the html code
+        for (Map.Entry<String, String> entry : 
result.getNamespaces().entrySet()) {
+            String prefix = entry.getValue();
+            if (prefix == null) {
+                continue;
+            }
+            String namespace = entry.getKey();
+            LibraryInfo libraryInfo = 
DefaultLibraryInfo.forNamespace(namespace);
+            if (libraryInfo == DefaultLibraryInfo.FACELETS || libraryInfo == 
DefaultLibraryInfo.JSF || libraryInfo == DefaultLibraryInfo.COMPOSITE ||
+                    libraryInfo == DefaultLibraryInfo.JSF_CORE || libraryInfo 
== DefaultLibraryInfo.JSTL_CORE
+                    || libraryInfo == DefaultLibraryInfo.JSTL_CORE_FUNCTIONS 
|| libraryInfo == DefaultLibraryInfo.PASSTHROUGH) {
+                continue;
+            }
+
+            Library lib = sup.getLibrary(namespace);
             if (lib != null) {
                 Collection<? extends LibraryComponent> components = 
lib.getComponents();
                 for (LibraryComponent comp : components) {
                     Tag tag = comp.getTag();
-                    //hacking datatable's attributes embedding - waiting for 
Tomasz' tag metadata API
-                    if ("dataTable".equals(tag.getName())) { //NOI18N
-                        cssClassTagAttrMap.put(prefix + ":" + tag.getName(),
-                                Arrays.asList(new 
String[]{STYLE_CLASS_ATTR_NAME,
-                                    "headerClass", "footerClass", 
"rowClasses", "columnClasses", "captionClass"})); //NOI18N
-                    } else {
-                        if (tag.getAttribute(STYLE_CLASS_ATTR_NAME) != null) {
-                            cssClassTagAttrMap.put(prefix + ":" + 
tag.getName(), Collections.singletonList(STYLE_CLASS_ATTR_NAME));
-                        }
+                    if (tag == null) {
+                        continue;
+                    }
+                    List<String> cssClassAttributes = 
tag.getAttributes().stream()
+                            .map(Attribute::getName)
+                            .filter(name -> 
name.toLowerCase(Locale.US).contains(CLASS_LOWERCASE) && 
!CLASS_LOWERCASE.equals(name))
+                            .collect(Collectors.toList());

Review Comment:
   if you want, you can change this line:
   
https://github.com/apache/netbeans/blob/9ed305642acf53f727ae94b18e88513aa0ea3ab6/enterprise/web.jsf.editor/nbproject/project.properties#L19
   
   into `javac.release=17`, then you can use `stream#toList()`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to