Skip to content

Commit

Permalink
improved pull parser with decoder #18
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Mar 27, 2023
1 parent c5c4a04 commit 9cc7852
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public void decode(ResTableMapEntry mapEntry, XMLElement parentElement) {
EntryStore entryStore = getEntryStore();
for(int i=0;i< bagItems.length;i++){
ResValueMap item=bagItems[i];
int resourceId=item.getName();
XMLElement child=new XMLElement("item");
String name = ValueDecoder.decodeAttributeName(
entryStore, currentPackage, item.getName());
Expand All @@ -63,7 +62,7 @@ public void decode(ResTableMapEntry mapEntry, XMLElement parentElement) {
XmlHelper.setTextContent(child, item.getDataAsPoolString());
}else {
String value = ValueDecoder.decode(entryStore, currentPackageId,
resourceId, item.getValueType(), item.getData());
item);
child.setTextContent(value);
}
parentElement.addChild(child);
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/com/reandroid/arsc/chunk/xml/ResXmlAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,7 @@ public XMLAttribute decodeToXml(EntryStore entryStore, int currentPackageId) thr
}
ValueType valueType = getValueType();
int raw = getData();
String value;
if(valueType==ValueType.STRING){
value = ValueDecoder.escapeSpecialCharacter(getValueAsString());
}else {
value = ValueDecoder.decode(entryStore,
currentPackageId,
resourceId,
valueType,
raw);
}
String value = ValueDecoder.decode(entryStore, currentPackageId, (AttributeValue) this);
XMLAttribute attribute = new XMLAttribute(name, value);
attribute.setNameId(resourceId);
if(valueType==ValueType.REFERENCE||valueType==ValueType.ATTRIBUTE){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ private Set<String> recursiveStrings(JSONObject elementJson){
}
return results;
}
void addEvents(ParserEventList parserEventList){
ResXmlElement xmlElement = getResXmlElement();
parserEventList.add(new ParserEvent(ParserEvent.START_DOCUMENT, xmlElement));
if(xmlElement!=null){
xmlElement.addEvents(parserEventList);
}
parserEventList.add(new ParserEvent(ParserEvent.END_DOCUMENT, xmlElement));
}

public static boolean isResXmlBlock(File file){
if(file==null){
Expand Down
54 changes: 50 additions & 4 deletions src/main/java/com/reandroid/arsc/chunk/xml/ResXmlElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,33 @@ public void setAttributesUnitSize(int size, boolean setToAll){
}
}
}
@Override
public String getComment(){
return getStartElement().getComment();
public String getStartComment(){
ResXmlStartElement start = getStartElement();
if(start!=null){
return start.getComment();
}
return null;
}
public String getEndComment(){
ResXmlEndElement end = getEndElement();
if(end!=null){
return end.getComment();
}
return null;
}
public int getStartLineNumber(){
ResXmlStartElement start = getStartElement();
if(start!=null){
return start.getLineNumber();
}
return 0;
}
public int getEndLineNumber(){
ResXmlEndElement end = getEndElement();
if(end!=null){
return end.getLineNumber();
}
return 0;
}
public void setComment(String comment){
getStartElement().setComment(comment);
Expand Down Expand Up @@ -338,6 +362,24 @@ public int getDepth(){
}
return depth;
}
@Override
void addEvents(ParserEventList parserEventList){
String comment = getStartComment();
if(comment!=null){
parserEventList.add(
new ParserEvent(ParserEvent.COMMENT, this, comment, false));
}
parserEventList.add(new ParserEvent(ParserEvent.START_TAG, this));
for(ResXmlNode xmlNode:getXmlNodes()){
xmlNode.addEvents(parserEventList);
}
comment = getEndComment();
if(comment!=null){
parserEventList.add(
new ParserEvent(ParserEvent.COMMENT, this, comment, true));
}
parserEventList.add(new ParserEvent(ParserEvent.END_TAG, this));
}
public int getLevel(){
return mLevel;
}
Expand Down Expand Up @@ -908,7 +950,11 @@ public XMLElement decodeToXml(EntryStore entryStore, int currentPackageId) throw
resXmlAttribute.decodeToXml(entryStore, currentPackageId);
xmlElement.addAttribute(xmlAttribute);
}
String comment=getComment();
String comment=getStartComment();
if(comment!=null){
xmlElement.addComment(new XMLComment(comment));
}
comment=getEndComment();
if(comment!=null){
xmlElement.addComment(new XMLComment(comment));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/reandroid/arsc/chunk/xml/ResXmlNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public abstract class ResXmlNode extends FixedBlockContainer implements JSONCon
}
void onRemove(){
}
public abstract String getComment();
public abstract int getDepth();
abstract void addEvents(ParserEventList parserEventList);

public static final String NAME_node_type="node_type";
}
Loading

0 comments on commit 9cc7852

Please sign in to comment.