-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Doclink for catalog entries with 'catalog' attr
Any of the catalog entry elements that have the 'catalog' attribute to refer to another catalog are now doclinks. Use xml:base when making catalog doc links Doc links now work inside `<group></group>`. xml:base is taken into account when calculating where a doc link should point in catalog files. Closes #845 Signed-off-by: David Thompson <[email protected]>
- Loading branch information
1 parent
526e2b0
commit dbf43f3
Showing
6 changed files
with
528 additions
and
30 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...pse.lemminx/src/main/java/org/eclipse/lemminx/extensions/catalog/CatalogCatalogEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.extensions.catalog; | ||
|
||
import java.nio.file.Paths; | ||
|
||
import org.eclipse.lemminx.dom.DOMAttr; | ||
import org.eclipse.lemminx.dom.DOMElement; | ||
import org.eclipse.lemminx.dom.DOMRange; | ||
import org.eclipse.lemminx.utils.StringUtils; | ||
import org.eclipse.lsp4j.jsonrpc.validation.NonNull; | ||
|
||
/** | ||
* Represents a catalog entry that uses the "catalog" attribute to reference an external document | ||
*/ | ||
public class CatalogCatalogEntry extends CatalogEntry { | ||
|
||
public CatalogCatalogEntry(@NonNull String baseURI, DOMElement entryElement) { | ||
super(baseURI, entryElement); | ||
} | ||
|
||
@Override | ||
public DOMRange getLinkRange() { | ||
DOMAttr catalogAttr = CatalogUtils.getCatalogEntryCatalog(getEntryElement()); | ||
if (catalogAttr == null) { | ||
return null; | ||
} | ||
return catalogAttr.getNodeAttrValue(); | ||
} | ||
|
||
@Override | ||
public String getResolvedURI() { | ||
DOMAttr catalogAttr = CatalogUtils.getCatalogEntryCatalog(getEntryElement()); | ||
if (catalogAttr == null) { | ||
return null; | ||
} | ||
String lastSegment = catalogAttr.getValue(); | ||
if (StringUtils.isBlank(lastSegment)) { | ||
return null; | ||
} | ||
return Paths.get(getBaseURI(), lastSegment).toString(); | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/catalog/CatalogEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.extensions.catalog; | ||
|
||
import org.eclipse.lemminx.dom.DOMElement; | ||
import org.eclipse.lemminx.dom.DOMRange; | ||
|
||
/** | ||
* Represents a catalog entry that references an external document | ||
*/ | ||
public abstract class CatalogEntry { | ||
|
||
private final String baseURI; | ||
private final DOMElement entryElement; | ||
|
||
/** | ||
* | ||
* @param baseURI <catalog>'s xml:base + <group>'s xml:base (if in a | ||
* <group>) | ||
* @param entryElement the element that corresponds with this catalog entry | ||
*/ | ||
protected CatalogEntry(String baseURI, DOMElement entryElement) { | ||
this.baseURI = baseURI; | ||
this.entryElement = entryElement; | ||
} | ||
|
||
/** | ||
* Returns the base URI for this catalog entry | ||
* | ||
* @return the base URI for this catalog entry | ||
*/ | ||
public String getBaseURI() { | ||
return baseURI; | ||
} | ||
|
||
/** | ||
* Returns the element that corresponds with this catalog entry | ||
* | ||
* @return the element that corresponds with this catalog entry | ||
*/ | ||
protected DOMElement getEntryElement() { | ||
return entryElement; | ||
} | ||
|
||
/** | ||
* Returns the range in the document where the link to an external document is, | ||
* or null if this catalog entry does not refer to an external document | ||
* | ||
* @return the range in the document where the link to an external document is | ||
*/ | ||
public abstract DOMRange getLinkRange(); | ||
|
||
/** | ||
* Returns the URI for the document that this catalog entry references, or null | ||
* if this catalog entry does not refer to an external document | ||
* | ||
* @return the URI for the document that this catalog entry references | ||
*/ | ||
public abstract String getResolvedURI(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/catalog/URICatalogEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.extensions.catalog; | ||
|
||
import java.nio.file.Paths; | ||
|
||
import org.eclipse.lemminx.dom.DOMAttr; | ||
import org.eclipse.lemminx.dom.DOMElement; | ||
import org.eclipse.lemminx.dom.DOMRange; | ||
import org.eclipse.lemminx.utils.StringUtils; | ||
import org.eclipse.lsp4j.jsonrpc.validation.NonNull; | ||
|
||
/** | ||
* Represents a catalog entry that uses the "uri" attribute to reference an external document | ||
*/ | ||
public class URICatalogEntry extends CatalogEntry { | ||
|
||
public URICatalogEntry(@NonNull String baseURI, DOMElement entryElement) { | ||
super(baseURI, entryElement); | ||
} | ||
|
||
@Override | ||
public DOMRange getLinkRange() { | ||
DOMAttr uriAttr = CatalogUtils.getCatalogEntryURI(getEntryElement()); | ||
if (uriAttr == null) { | ||
return null; | ||
} | ||
return uriAttr.getNodeAttrValue(); | ||
} | ||
|
||
@Override | ||
public String getResolvedURI() { | ||
DOMAttr uriAttr = CatalogUtils.getCatalogEntryURI(getEntryElement()); | ||
if (uriAttr == null) { | ||
return null; | ||
} | ||
String lastSegment = uriAttr.getValue(); | ||
if (StringUtils.isBlank(lastSegment)) { | ||
return null; | ||
} | ||
return Paths.get(getBaseURI(), lastSegment).toString(); | ||
} | ||
|
||
} |
Oops, something went wrong.