Skip to content

Commit

Permalink
How to set catalog prefer as public in vscode setting?
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Aug 13, 2020
1 parent f145059 commit 1f02416
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ private void updateSettings(ISaveContext saveContext) {
private void updateSettings(ContentModelSettings settings, ISaveContext context) {
if (settings.getCatalogs() != null) {
// Update XML catalog settings
boolean catalogPathsChanged = contentModelManager.setCatalogs(settings.getCatalogs());
boolean catalogPathsChanged = contentModelManager.setCatalogs(settings.getCatalogs(),
settings.getCatalog().isPreferPublic(), settings.getCatalog().isUseLiteralSystemId());
if (catalogPathsChanged) {
// Validate all opened XML files
context.collectDocumentToValidate(d -> {
Expand Down Expand Up @@ -165,9 +166,9 @@ public void stop(XMLExtensionsRegistry registry) {
public ContentModelSettings getContentModelSettings() {
return cmSettings;
}

public ContentModelManager getContentModelManager() {
return contentModelManager;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ public ContentModelProvider getModelProviderByURI(String uri) {
* @param catalogs list of XML catalog files.
* @return true if catalogs changed and false otherwise
*/
public boolean setCatalogs(String[] catalogs) {
return catalogResolverExtension.setCatalogs(catalogs);
public boolean setCatalogs(String[] catalogs, boolean preferPublic, boolean useLiteralSystemId) {
return catalogResolverExtension.setCatalogs(catalogs, preferPublic, useLiteralSystemId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ContentModelSettings {

private String[] catalogs;

private XMLCatalog catalog;

private XMLFileAssociation[] fileAssociations;

private XMLValidationSettings validation;
Expand Down Expand Up @@ -94,4 +96,11 @@ public XMLValidationSettings getValidation() {
return validation;
}

public XMLCatalog getCatalog() {
return catalog != null ? catalog : XMLCatalog.DEFAULT_CATALOG;
}

public void setCatalog(XMLCatalog catalog) {
this.catalog = catalog;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.eclipse.lemminx.extensions.contentmodel.settings;

public class XMLCatalog {

public static final XMLCatalog DEFAULT_CATALOG = new XMLCatalog();

private boolean preferPublic;

private boolean useLiteralSystemId;

public XMLCatalog() {
setPreferPublic(true);
setUseLiteralSystemId(true);
}

public boolean isPreferPublic() {
return preferPublic;
}

public void setPreferPublic(boolean preferPublic) {
this.preferPublic = preferPublic;
}

public boolean isUseLiteralSystemId() {
return useLiteralSystemId;
}

public void setUseLiteralSystemId(boolean useLiteralSystemId) {
this.useLiteralSystemId = useLiteralSystemId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ public void setRootUri(String rootUri) {
/**
* Initialize catalogs path.
*
* @param catalogs the catalog path array.
* @param catalogs the catalog path array.
* @param preferPublic
* @param useLiteralSystemId
* @return true if catalogs changed and false otherwise
*/
public boolean setCatalogs(String[] catalogs) {
public boolean setCatalogs(String[] catalogs, boolean preferPublic, boolean useLiteralSystemId) {
String[] oldCatalogs = catalogResolver != null ? catalogResolver.getCatalogList() : null;
boolean oldPreferPublic = catalogResolver != null ? catalogResolver.getPreferPublic() : true;
boolean oldUseLiteralSystemId = catalogResolver != null ? catalogResolver.getUseLiteralSystemId() : true;
if (catalogs != null) {
List<String> xmlCatalogFiles = new ArrayList<>();
for (String catalogPath : catalogs) {
Expand All @@ -119,6 +123,8 @@ public boolean setCatalogs(String[] catalogs) {
}
if (xmlCatalogFiles.size() > 0) {
XMLCatalogResolver catalogResolver = new XMLCatalogResolver(xmlCatalogFiles.toArray(new String[0]));
catalogResolver.setPreferPublic(preferPublic);
catalogResolver.setUseLiteralSystemId(useLiteralSystemId);
setCatalogResolver(catalogResolver);
} else {
setCatalogResolver(null);
Expand All @@ -127,7 +133,8 @@ public boolean setCatalogs(String[] catalogs) {
setCatalogResolver(null);
}
String[] newCatalogs = catalogResolver != null ? catalogResolver.getCatalogList() : null;
return !Objects.equals(oldCatalogs, newCatalogs);
return !Objects.equals(oldCatalogs, newCatalogs) || catalogResolver.getPreferPublic() != oldPreferPublic
|| catalogResolver.getUseLiteralSystemId() != oldUseLiteralSystemId;
}

private String expandSystemId(String path) {
Expand Down Expand Up @@ -161,7 +168,8 @@ private void setCatalogResolver(XMLCatalogResolver catalogResolver) {
*/
public void refreshCatalogs() {
if (catalogResolver != null) {
setCatalogs(catalogResolver.getCatalogList());
setCatalogs(catalogResolver.getCatalogList(), catalogResolver.getPreferPublic(),
catalogResolver.getUseLiteralSystemId());
}
}
}

0 comments on commit 1f02416

Please sign in to comment.