encode arrays with name attribute

This commit is contained in:
REAndroid 2023-05-04 19:46:11 +02:00
parent de4a6feb24
commit d1e5682d02
2 changed files with 33 additions and 9 deletions

View File

@ -71,7 +71,11 @@ class ValuesEncoder {
type=getType(xmlDocument, type);
XMLValuesEncoder encoder;
if(isBag(xmlDocument, type)){
encoder=getBagEncoder(type);
if("array".equals(type) && hasNameAttributes(xmlDocument)){
encoder = getBagEncoder("style");
}else{
encoder = getBagEncoder(type);
}
}else{
encoder=getEncoder(type);
}
@ -99,13 +103,27 @@ class ValuesEncoder {
XMLElement documentElement=xmlDocument.getDocumentElement();
int count=documentElement.getChildesCount();
for(int i=0;i<count;i++){
XMLElement element=documentElement.getChildAt(0);
XMLElement element=documentElement.getChildAt(i);
if(element.getChildesCount()>0){
return true;
}
}
return false;
}
private boolean hasNameAttributes(XMLDocument xmlDocument){
XMLElement documentElement=xmlDocument.getDocumentElement();
int count=documentElement.getChildesCount();
for(int i=0;i<count;i++){
XMLElement element=documentElement.getChildAt(i);
if(element.getChildesCount()>0){
XMLElement child = element.getChildAt(0);
if(child.getAttributeValue("name") != null){
return true;
}
}
}
return false;
}
private String getType(XMLDocument xmlDocument, String def){
XMLElement documentElement=xmlDocument.getDocumentElement();
if(documentElement.getChildesCount()==0){

View File

@ -35,15 +35,21 @@ class XMLValuesEncoderStyle extends XMLValuesEncoderBag{
XMLElement child=parentElement.getChildAt(i);
ResValueMap item = itemArray.get(i);
String name=child.getAttributeValue("name");
int id=decodeUnknownAttributeHex(name);
if(id!=0){
Integer id = decodeUnknownAttributeHex(name);
if(id != null){
item.setName(id);
String value = child.getTextContent();
ValueDecoder.EncodeResult encodeResult = ValueDecoder.encodeNullReference(value);
if(encodeResult!=null){
item.setTypeAndData(encodeResult.valueType, encodeResult.value);
}else if(ValueDecoder.isReference(value)){
item.setTypeAndData(ValueType.REFERENCE,
ValueType valueType;
if(value.charAt(0) == '?'){
valueType = ValueType.ATTRIBUTE;
}else {
valueType = ValueType.REFERENCE;
}
item.setTypeAndData(valueType,
getMaterials().resolveReference(value));
}else {
encodeResult = ValueDecoder.encodeGuessAny(value);
@ -65,13 +71,13 @@ class XMLValuesEncoderStyle extends XMLValuesEncoderBag{
encodeChild(child, attributeEntry, item);
}
}
private int decodeUnknownAttributeHex(String name){
if(name.length()==0||name.charAt(0)!='@'){
return 0;
private Integer decodeUnknownAttributeHex(String name){
if(name.length()==0||(name.charAt(0)!='@' && name.charAt(0)!='?')){
return null;
}
name=name.substring(1);
if(!ValueDecoder.isHex(name)){
return 0;
return null;
}
return ValueDecoder.parseHex(name);
}