Skip to content

Commit

Permalink
DTD parsing/scanner updated. More properties for DTD types implemented.
Browse files Browse the repository at this point in the history
Fixes eclipse#231

Signed-off-by: Nikolas Komonen <[email protected]>
  • Loading branch information
NikolasKomonen committed Dec 14, 2018
1 parent f4e8319 commit 9dfe620
Show file tree
Hide file tree
Showing 19 changed files with 1,684 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,20 @@ public enum DocumentTypeKind {
}

// Offset values relative to start of the XML Document
int nameStart = -1;
int nameEnd = -1;
int kindStart = -1;
int kindEnd = -1;
int publicIdStart = -1;
int publicIdEnd = -1;
int systemIdStart = -1;
int systemIdEnd = -1;
Integer startInternalSubset;
Integer endInternalSubset;
Integer nameStart, nameEnd;
Integer kindStart, kindEnd;
Integer publicIdStart, publicIdEnd;
Integer systemIdStart, systemIdEnd;
Integer internalSubsetStart, internalSubsetEnd;


private String name;
private String kind;
private String kind; // SYSTEM || PUBLIC
private String publicId;
private String systemId;
private String internalSubset;

private String content;
private String content; // |<!DOCTYPE ... >|

public DOMDocumentType(int start, int end, DOMDocument ownerDocument) {
super(start, end, ownerDocument);
Expand All @@ -63,7 +59,7 @@ void setEnd(int end) {
*/
@Override
public String getName() {
if (name == null && this.nameStart != -1 && this.nameEnd != -1) {
if (name == null && this.nameStart != null && this.nameEnd != null) {
name = getSubstring(nameStart, nameEnd);
}
return name;
Expand All @@ -78,7 +74,7 @@ void setName(int start, int end) {
* @return the DocumentTypeKind
*/
public String getKind() {
if (kind == null && kindStart != -1 && kindEnd != -1) {
if (kind == null && kindStart != null && kindEnd != null) {
kind = getSubstring(kindStart, kindEnd);
}
return kind;
Expand Down Expand Up @@ -129,8 +125,8 @@ public NamedNodeMap getEntities() {
*/
@Override
public String getInternalSubset() {
if (internalSubset == null && startInternalSubset != null && endInternalSubset != null) {
internalSubset = getSubstring(startInternalSubset + 1, endInternalSubset);
if (internalSubset == null && internalSubsetStart != null && internalSubsetEnd != null) {
internalSubset = getSubstring(internalSubsetStart + 1, internalSubsetEnd - 1);
}
return internalSubset;
}
Expand All @@ -141,7 +137,7 @@ public String getInternalSubset() {
* @return the start offset of internal subset and null otherwise.
*/
public Integer getStartInternalSubset() {
return startInternalSubset;
return internalSubsetStart;
}

/**
Expand All @@ -150,7 +146,7 @@ public Integer getStartInternalSubset() {
* @return the end offset of internal subset and null otherwise.
*/
public Integer getEndInternalSubset() {
return endInternalSubset;
return internalSubsetEnd;
}

/*
Expand All @@ -170,7 +166,7 @@ public NamedNodeMap getNotations() {
*/
@Override
public String getPublicId() {
if (publicId == null && publicIdStart != -1 && publicIdEnd != -1) {
if (publicId == null && publicIdStart != null && publicIdEnd != null) {
publicId = cleanURL(getSubstring(publicIdStart, publicIdEnd));
}
return publicId;
Expand All @@ -191,7 +187,7 @@ void setPublicId(int start, int end) {
*/
@Override
public String getSystemId() {
if (systemId == null && systemIdStart != -1 && systemIdEnd != -1) {
if (systemId == null && systemIdStart != null && systemIdEnd != null) {
systemId = cleanURL(getSubstring(systemIdStart, systemIdEnd));
}
return systemId;
Expand Down Expand Up @@ -220,7 +216,11 @@ private static String cleanURL(String url) {
return url.substring(start, end);
}

private String getSubstring(int start, int end) {
/**
* Since offset values are relative to 'this.start' we need to
* subtract getStart() to make them relative to 'content'
*/
public String getSubstring(int start, int end) {
return getContent().substring(start - getStart(), end - getStart());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ public abstract class DOMNode implements Node {
*/
public static final short DTD_ATT_LIST_NODE = 102;

/**
* The node is a <code>DTD Entity Declaraction</code>.
*/
public static final short DTD_ENTITY_DECL_NODE = 103;

/**
* The node is a <code>DTD Notation Declaraction</code>.
*/
public static final short DTD_NOTATION_DECL = 104;

/**
* The node is a generic <code>DTD Decl Node</code>.
*/
public static final short DTD_DECL_NODE = 105;

boolean closed = false;

private XMLNamedNodeMap<DOMAttr> attributeNodes;
Expand Down Expand Up @@ -119,6 +134,7 @@ public DOMNode(int start, int end, DOMDocument ownerDocument) {
this.start = start;
this.end = end;
this.ownerDocument = ownerDocument;
this.closed = false;
}

public DOMDocument getOwnerDocument() {
Expand Down Expand Up @@ -341,7 +357,7 @@ public List<DOMNode> getChildren() {
}

/**
* Add node child and set child.parent to this.
* Add node child and set child.parent to {@code this}
*
* @param child the node child to add.
*/
Expand Down Expand Up @@ -398,6 +414,11 @@ public boolean isDoctype() {
return getNodeType() == DOMNode.DOCUMENT_TYPE_NODE;
}

public boolean isGenericDTDDecl() {
return getNodeType() == DOMNode.DTD_DECL_NODE;
}


public boolean isElement() {
return getNodeType() == DOMNode.ELEMENT_NODE;
}
Expand Down Expand Up @@ -426,6 +447,10 @@ public boolean isDTDEntityDecl() {
return getNodeType() == Node.ENTITY_NODE;
}

public boolean isDTDNotationDecl() {
return getNodeType() == DOMNode.DTD_NOTATION_DECL;
}

public int getStart() {
return start;
}
Expand Down
Loading

0 comments on commit 9dfe620

Please sign in to comment.