diff --git a/lib/src/main/java/com/alphawallet/token/entity/TSTokenView.java b/lib/src/main/java/com/alphawallet/token/entity/TSTokenView.java index 2edf7c22e8..97356ebbe7 100644 --- a/lib/src/main/java/com/alphawallet/token/entity/TSTokenView.java +++ b/lib/src/main/java/com/alphawallet/token/entity/TSTokenView.java @@ -3,6 +3,8 @@ import org.w3c.dom.Element; import org.w3c.dom.EntityReference; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; import static org.w3c.dom.Node.ELEMENT_NODE; import static org.w3c.dom.Node.TEXT_NODE; @@ -20,19 +22,82 @@ public class TSTokenView { private String tokenView = ""; private String style = ""; + private String label = ""; + private String url; + private String urlFragment; - private Element element; - private TokenDefinition tokenDef; + public TSTokenView(Element element, TokenDefinition td) throws SAXException + { + //handle raw view card, only need to process the view element itself + if (element.getLocalName().equals("view")) + { + handleView(element, td); + return; + } - public TSTokenView(Element element, TokenDefinition tokenDef) + for (int j = 0; j < element.getAttributes().getLength(); j++) + { + Node node = element.getAttributes().item(j); + switch (node.getLocalName()) + { + case "name": + label = node.getTextContent(); + break; + default: + break; + } + } + + NodeList ll = element.getChildNodes(); + + for (int j = 0; j < ll.getLength(); j++) + { + Node node = ll.item(j); + if (node.getNodeType() != ELEMENT_NODE) + continue; + + Element thisElement = (Element) node; + switch (node.getLocalName()) + { + case "attribute": + Attribute attr = new Attribute(thisElement, td); + td.addLocalAttr(attr); //TODO: This should be stored in this class + break; + case "view": //TODO: Localisation + case "item-view": + handleView(thisElement, td); + break; + case "view-iconified": + throw new SAXException("Deprecated used in . Replace with "); + case "style": + td.addGlobalStyle(thisElement); + break; + case "script": + //misplaced script tag + throw new SAXException("Misplaced "; - - return new TSTokenView(style, view); - } } diff --git a/lib/src/main/java/com/alphawallet/token/tools/TokenDefinition.java b/lib/src/main/java/com/alphawallet/token/tools/TokenDefinition.java index a82d460e60..1e69bee944 100644 --- a/lib/src/main/java/com/alphawallet/token/tools/TokenDefinition.java +++ b/lib/src/main/java/com/alphawallet/token/tools/TokenDefinition.java @@ -344,6 +344,16 @@ public boolean matchCollection(String attestationCollectionId) } } + public void addLocalAttr(Attribute attr) + { + tokenViews.localAttributeTypes.put(attr.name, attr); //TODO: Refactor as it appears this doesn't respect scope + } + + public void addGlobalStyle(Element element) + { + tokenViews.globalStyle = getHTMLContent(element); //TODO: Refactor this as it appears global style is located elsewhere. This may have been deprecated + } + public enum Syntax { DirectoryString, IA5String, Integer, GeneralizedTime, Boolean, BitString, CountryString, JPEG, NumericString @@ -612,7 +622,8 @@ private void handleCards(Element cards) throws Exception { case "token": case "token-card": - processTokenCardElements(card); + TSTokenView tv = new TSTokenView(card, this); + tokenViews.views.put(tv.getLabel(), tv); break; case "card": extractCard(card); @@ -661,42 +672,6 @@ private TSActivityView processActivityView(Element card) throws Exception return activityView; } - private void processTokenCardElements(Element card) throws Exception - { - NodeList ll = card.getChildNodes(); - - for (int j = 0; j < ll.getLength(); j++) - { - Node node = ll.item(j); - if (node.getNodeType() != ELEMENT_NODE) - continue; - - Element element = (Element) node; - switch (node.getLocalName()) - { - case "attribute": - Attribute attr = new Attribute(element, this); - tokenViews.localAttributeTypes.put(attr.name, attr); - break; - case "view": //TODO: Localisation - case "item-view": - TSTokenView v = new TSTokenView(element, this); - tokenViews.views.put(node.getLocalName(), v); - break; - case "view-iconified": - throw new SAXException("Deprecated used in . Replace with "); - case "style": - tokenViews.globalStyle = getHTMLContent(element); - break; - case "script": - //misplaced script tag - throw new SAXException("Misplaced