Skip to content
Open
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
8 changes: 7 additions & 1 deletion org.eclipse.wildwebdeveloper.xml/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ XMLCodeMiningsPreferencePage.preferenceKeywords.xmlcodeminings=xml codeminings
XMLFormattingPreferencePage.name=Formatting
XMLFormattingPreferencePage.preferenceKeywords.xmlformatting=xml formatting
XMLValidationPreferencePage.name=Validation & Resolution
XMLValidationPreferencePage.preferenceKeywords.xmlvalidation=xml validation resolution download external sources
XMLValidationPreferencePage.preferenceKeywords.xmlvalidation=xml validation resolution download external sources
XMLFileRulesPreferencePage.name=File Rules
XMLFileRulesPreferencePage.preferenceKeywords.xmlfilerules=xml file rules patterns document matcher colors references
XMLColorsPreferencePage.name=Colors
XMLColorsPreferencePage.preferenceKeywords.xmlcolors=xml colors xpath color document
XMLReferencesPreferencePage.name=References
XMLReferencesPreferencePage.preferenceKeywords.xmlreferences=xml references xpath from to navigation rename
30 changes: 30 additions & 0 deletions org.eclipse.wildwebdeveloper.xml/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,27 @@
name="%XMLValidationPreferencePage.name">
<keywordReference id="org.eclipse.wildwebdeveloper.xml.ui.xmlvalidation"/>
</page>
<page
category="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferencePage"
class="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.XMLFileRulesPreferencePage"
id="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.XMLFileRulesPreferencePage"
name="%XMLFileRulesPreferencePage.name">
<keywordReference id="org.eclipse.wildwebdeveloper.xml.ui.xmlfilerules"/>
</page>
<page
category="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.XMLFileRulesPreferencePage"
class="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.colors.XMLColorsPreferencePage"
id="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.colors.XMLColorsPreferencePage"
name="%XMLColorsPreferencePage.name">
<keywordReference id="org.eclipse.wildwebdeveloper.xml.ui.xmlcolors"/>
</page>
<page
category="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.XMLFileRulesPreferencePage"
class="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references.XMLReferencesPreferencePage"
id="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references.XMLReferencesPreferencePage"
name="%XMLReferencesPreferencePage.name">
<keywordReference id="org.eclipse.wildwebdeveloper.xml.ui.xmlreferences"/>
</page>
</extension>

<!-- Keywords for preference and properties pages -->
Expand All @@ -219,6 +240,15 @@
<keyword
label="%XMLValidationPreferencesPage.preferenceKeywords.xmlvalidation"
id="org.eclipse.wildwebdeveloper.xml.ui.xmlvalidation"/>
<keyword
label="%XMLFileRulesPreferencePage.preferenceKeywords.xmlfilerules"
id="org.eclipse.wildwebdeveloper.xml.ui.xmlfilerules"/>
<keyword
label="%XMLColorsPreferencePage.preferenceKeywords.xmlcolors"
id="org.eclipse.wildwebdeveloper.xml.ui.xmlcolors"/>
<keyword
label="%XMLReferencesPreferencePage.preferenceKeywords.xmlreferences"
id="org.eclipse.wildwebdeveloper.xml.ui.xmlreferences"/>
</extension>

<extension
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*******************************************************************************
* Copyright (c) 2026 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Angelo ZERR (Red Hat Inc.) - initial implementation
*******************************************************************************/
package org.eclipse.wildwebdeveloper.xml.internal;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter;
import org.eclipse.lsp4j.jsonrpc.json.adapters.EnumTypeAdapter;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

/**
* Json Utilities
*/
public class JsonUtils {

private static Gson gson = getDefaultGsonBuilder().create();

public static <T> T toModel(Object object, Class<T> clazz) {
if (object == null) {
return null;
}
if (clazz == null) {
throw new IllegalArgumentException("Class can not be null");
}
if (object instanceof JsonElement) {
return gson.fromJson((JsonElement) object, clazz);
}
if (object instanceof Map) {
return gson.fromJson(gson.toJsonTree(object), clazz);
}
if (clazz.isInstance(object)) {
return clazz.cast(object);
}
return null;
}

private static GsonBuilder getDefaultGsonBuilder() {
return new GsonBuilder() //
.registerTypeAdapterFactory(new EnumTypeAdapter.Factory()) //
.registerTypeAdapterFactory(new EitherTypeAdapter.Factory());
}

/**
* Loads a list of objects from a preference store.
*
* @param <T> the type of objects in the list
* @param store the preference store
* @param key the preference key
* @param clazz the class of the objects in the list
* @return a list of objects, or an empty list if preference is null/empty or
* parsing fails
*/
public static <T> List<T> getList(IPreferenceStore store, String key, Class<T> clazz) {
String json = store.getString(key);
return loadList(json, clazz);
}

/**
* Loads a list of objects from a JSON array string.
*
* @param <T> the type of objects in the list
* @param json the JSON array string to parse
* @param clazz the class of the objects in the list
* @return a list of objects, or an empty list if json is null/empty or parsing
* fails
*/
private static <T> List<T> loadList(String json, Class<T> clazz) {
List<T> entries = new ArrayList<>();
if (json == null || json.trim().isEmpty()) {
return entries;
}
try {
JsonElement element = JsonParser.parseString(json);
if (element.isJsonArray()) {
JsonArray array = element.getAsJsonArray();
for (int i = 0; i < array.size(); i++) {
T entry = toModel(array.get(i), clazz);
if (entry != null) {
entries.add(entry);
}
}
}
} catch (Exception e) {
// Log or handle parse error silently
}
return entries;
}

/**
* Saves a list of objects to a preference store.
*
* @param store the preference store
* @param key the preference key
* @param entries the list of objects to serialize
*/
public static void setValue(IPreferenceStore store, String key, List<?> entries) {
String json = toJsonArray(entries);
store.setValue(key, json);
}

/**
* Saves a list of objects to a preference default store.
*
* @param store the preference store
* @param key the preference key
* @param entries the list of objects to serialize
*/
public static void setDefault(IPreferenceStore store, String key, List<?> entries) {
String json = toJsonArray(entries);
store.setDefault(key, json);
}

/**
* Saves a list of objects to a JSON array string.
*
* @param entries the list of objects to serialize
* @return a JSON array string, or an empty string if the list is null or empty
*/
private static String toJsonArray(List<?> entries) {
if (entries == null || entries.isEmpty()) {
return "";
}
JsonArray array = new JsonArray();
for (Object entry : entries) {
JsonElement element = gson.toJsonTree(entry);
array.add(element);
}
return array.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.lsp4e.LanguageServerWrapper;
import org.eclipse.lsp4e.LanguageServers;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@
package org.eclipse.wildwebdeveloper.xml.internal.commands;

import java.util.List;
import java.util.Map;

import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter;
import org.eclipse.lsp4j.jsonrpc.json.adapters.EnumTypeAdapter;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import org.eclipse.wildwebdeveloper.xml.internal.JsonUtils;

/**
* Arguments utilities.
Expand All @@ -30,8 +24,6 @@
*/
public class ArgumentsUtils {

private static Gson gson = getDefaultGsonBuilder().create();

/**
* Returns the object from the given index as a given class type and null
* otherwise.
Expand All @@ -50,7 +42,7 @@ public static <T> T getArgAt(Command command, int index, Class<T> clazz) {
if (obj == null) {
throw new IllegalArgumentException("Cannot find command argument at " + index);
}
return toModel(obj, clazz);
return JsonUtils.toModel(obj, clazz);
}

/**
Expand All @@ -68,29 +60,4 @@ public static Object getArgAt(List<Object> arguments, int index) {
return arguments.get(index);
}

private static <T> T toModel(Object object, Class<T> clazz) {
if (object == null) {
return null;
}
if (clazz == null) {
throw new IllegalArgumentException("Class can not be null");
}
if (object instanceof JsonElement) {
return gson.fromJson((JsonElement) object, clazz);
}
if (object instanceof Map) {
return gson.fromJson(gson.toJsonTree(object), clazz);
}
if (clazz.isInstance(object)) {
return clazz.cast(object);
}
return null;
}

private static GsonBuilder getDefaultGsonBuilder() {
return new GsonBuilder() //
.registerTypeAdapterFactory(new EnumTypeAdapter.Factory()) //
.registerTypeAdapterFactory(new EitherTypeAdapter.Factory());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,58 @@ public class Messages extends NLS {
public static String AssociateGrammarDialog_download_prompt_message;
public static String AssociateGrammarDialog_download_prompt_toggle;

// --------- DocumentMatcherWidget
public static String DocumentMatcherWidget_pattern;
public static String DocumentMatcherWidget_namespaceURI;
public static String DocumentMatcherWidget_rootElement;
public static String DocumentMatcherWidget_publicId;
public static String DocumentMatcherWidget_systemId;
public static String DocumentMatcherWidget_grammarURI;

// --------- XML Colors preference page
public static String XMLColorsPreferencePage_description;
public static String XMLColorsPreferencePage_entries;
public static String XMLColorsPreferencePage_column_pattern;
public static String XMLColorsPreferencePage_column_expressions;

// --------- XML Colors entry dialog
public static String XMLColorsEntryDialog_title_add;
public static String XMLColorsEntryDialog_title_edit;
public static String XMLColorsEntryDialog_matcher_group;
public static String XMLColorsEntryDialog_expressions_group;
public static String XMLColorsEntryDialog_column_xpath;
public static String XMLColorsEntryDialog_error_pattern_required;
public static String XMLColorsEntryDialog_error_expression_required;
public static String XMLColorsEntryDialog_input_xpath_title;
public static String XMLColorsEntryDialog_input_xpath_message;
public static String XMLColorsEntryDialog_edit_button;

// --------- XML References preference page
public static String XMLReferencesPreferencePage_description;
public static String XMLReferencesPreferencePage_entries;
public static String XMLReferencesPreferencePage_column_pattern;
public static String XMLReferencesPreferencePage_column_expressions;

// --------- XML References entry dialog
public static String XMLReferencesEntryDialog_title_add;
public static String XMLReferencesEntryDialog_title_edit;
public static String XMLReferencesEntryDialog_matcher_group;
public static String XMLReferencesEntryDialog_expressions_group;
public static String XMLReferencesEntryDialog_column_from;
public static String XMLReferencesEntryDialog_column_to;
public static String XMLReferencesEntryDialog_column_prefix;
public static String XMLReferencesEntryDialog_column_multiple;
public static String XMLReferencesEntryDialog_error_pattern_required;
public static String XMLReferencesEntryDialog_error_expression_required;
public static String XMLReferencesEntryDialog_error_from_required;
public static String XMLReferencesEntryDialog_error_to_required;
public static String XMLReferencesEntryDialog_edit_expression_title;
public static String XMLReferencesEntryDialog_edit_expression_title_add;
public static String XMLReferencesEntryDialog_edit_expression_from;
public static String XMLReferencesEntryDialog_edit_expression_to;
public static String XMLReferencesEntryDialog_edit_expression_prefix;
public static String XMLReferencesEntryDialog_edit_expression_multiple;

// --------- Buttons
public static String Add_button;
public static String Remove_button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,58 @@ AssociateGrammarDialog_download_prompt_title=Enable download of external resourc
AssociateGrammarDialog_download_prompt_message=The preference "Download external resources like referenced DTD, XSD" is currently disabled.\n\nWithout it, LemMinX will not fetch the remote grammar and grammar-driven features (completion, validation, hover, code actions…) will be unavailable.\n\nDo you want to enable it now?
AssociateGrammarDialog_download_prompt_toggle=Don''t ask again

# DocumentMatcherWidget
DocumentMatcherWidget_pattern=&Pattern:
DocumentMatcherWidget_namespaceURI=Namespace URI:
DocumentMatcherWidget_rootElement=Root &Element:
DocumentMatcherWidget_publicId=Public ID:
DocumentMatcherWidget_systemId=System ID:
DocumentMatcherWidget_grammarURI=Grammar URI:

# XML Colors preference page
XMLColorsPreferencePage_description=Configure which XML attributes or text nodes contain color values, matched by XPath expressions per file pattern.
XMLColorsPreferencePage_entries=Color entries
XMLColorsPreferencePage_column_pattern=File Pattern
XMLColorsPreferencePage_column_expressions=XPath Expression(s)

# XML Colors entry dialog
XMLColorsEntryDialog_title_add=Add Color Entry
XMLColorsEntryDialog_title_edit=Edit Color Entry
XMLColorsEntryDialog_matcher_group=Document Matcher
XMLColorsEntryDialog_expressions_group=XPath Expressions
XMLColorsEntryDialog_column_xpath=XPath Expression
XMLColorsEntryDialog_error_pattern_required=A file pattern is required.
XMLColorsEntryDialog_error_expression_required=At least one XPath expression is required.
XMLColorsEntryDialog_input_xpath_title=XPath Expression
XMLColorsEntryDialog_input_xpath_message=Enter an XPath expression (e.g. resources/color/text() or @color):
XMLColorsEntryDialog_edit_button=\uD83D\uDD0F &Edit...

# XML References preference page
XMLReferencesPreferencePage_description=Configure cross-element references using XPath from/to expressions, enabling navigation, completion, and rename across XML documents.
XMLReferencesPreferencePage_entries=Reference entries
XMLReferencesPreferencePage_column_pattern=File Pattern
XMLReferencesPreferencePage_column_expressions=Expression(s)

# XML References entry dialog
XMLReferencesEntryDialog_title_add=Add Reference Entry
XMLReferencesEntryDialog_title_edit=Edit Reference Entry
XMLReferencesEntryDialog_matcher_group=Document Matcher
XMLReferencesEntryDialog_expressions_group=Reference Expressions
XMLReferencesEntryDialog_column_from=From XPath
XMLReferencesEntryDialog_column_to=To XPath
XMLReferencesEntryDialog_column_prefix=Prefix
XMLReferencesEntryDialog_column_multiple=Multiple
XMLReferencesEntryDialog_error_pattern_required=A file pattern is required.
XMLReferencesEntryDialog_error_expression_required=At least one reference expression is required.
XMLReferencesEntryDialog_error_from_required=The 'from' XPath is required.
XMLReferencesEntryDialog_error_to_required=The 'to' XPath is required.
XMLReferencesEntryDialog_edit_expression_title=Edit Reference Expression
XMLReferencesEntryDialog_edit_expression_title_add=Add Reference Expression
XMLReferencesEntryDialog_edit_expression_from=&From XPath:
XMLReferencesEntryDialog_edit_expression_to=&To XPath:
XMLReferencesEntryDialog_edit_expression_prefix=Pre&fix:
XMLReferencesEntryDialog_edit_expression_multiple=&Multiple values

# Buttons
Add_button=\u2795 &Add...
Remove_button=\uD83D\uDDD1 &Remove
Expand Down
Loading
Loading