jimu-decompiled/sources/com/thoughtworks/xstream/persistence/FilePersistenceStrategy.java
2025-05-13 19:24:51 +02:00

105 lines
4.3 KiB
Java

package com.thoughtworks.xstream.persistence;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.SingleValueConverter;
import com.thoughtworks.xstream.io.xml.DomDriver;
import java.io.File;
/* loaded from: classes.dex */
public class FilePersistenceStrategy extends AbstractFilePersistenceStrategy {
private final String illegalChars;
public FilePersistenceStrategy(File file) {
this(file, new XStream(new DomDriver()));
}
protected String escape(String str) {
StringBuffer stringBuffer = new StringBuffer();
for (char c : str.toCharArray()) {
if (c < ' ' || this.illegalChars.indexOf(c) >= 0) {
StringBuffer stringBuffer2 = new StringBuffer();
stringBuffer2.append("%");
stringBuffer2.append(Integer.toHexString(c).toUpperCase());
stringBuffer.append(stringBuffer2.toString());
} else {
stringBuffer.append(c);
}
}
return stringBuffer.toString();
}
@Override // com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
protected Object extractKey(String str) {
String unescape = unescape(str.substring(0, str.length() - 4));
if ("null@null".equals(unescape)) {
return null;
}
int indexOf = unescape.indexOf(64);
if (indexOf < 0) {
ConversionException conversionException = new ConversionException("No valid key");
conversionException.add("key", unescape);
throw conversionException;
}
Class realClass = getMapper().realClass(unescape.substring(0, indexOf));
Converter lookupConverterForType = getConverterLookup().lookupConverterForType(realClass);
if (lookupConverterForType instanceof SingleValueConverter) {
return ((SingleValueConverter) lookupConverterForType).fromString(unescape.substring(indexOf + 1));
}
ConversionException conversionException2 = new ConversionException("No SingleValueConverter available for key type");
conversionException2.add("key-type", realClass.getName());
throw conversionException2;
}
@Override // com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
protected String getName(Object obj) {
if (obj == null) {
return "null@null.xml";
}
Class<?> cls = obj.getClass();
Converter lookupConverterForType = getConverterLookup().lookupConverterForType(cls);
if (!(lookupConverterForType instanceof SingleValueConverter)) {
ConversionException conversionException = new ConversionException("No SingleValueConverter available for key type");
conversionException.add("key-type", cls.getName());
throw conversionException;
}
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(getMapper().serializedClass(cls));
stringBuffer.append('@');
stringBuffer.append(escape(((SingleValueConverter) lookupConverterForType).toString(obj)));
stringBuffer.append(".xml");
return stringBuffer.toString();
}
@Override // com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
protected boolean isValid(File file, String str) {
return super.isValid(file, str) && str.indexOf(64) > 0;
}
protected String unescape(String str) {
StringBuffer stringBuffer = new StringBuffer();
while (true) {
int indexOf = str.indexOf(37);
if (indexOf < 0) {
stringBuffer.append(str);
return stringBuffer.toString();
}
stringBuffer.append(str.substring(0, indexOf));
int i = indexOf + 1;
int i2 = indexOf + 3;
stringBuffer.append((char) Integer.parseInt(str.substring(i, i2), 16));
str = str.substring(i2);
}
}
public FilePersistenceStrategy(File file, XStream xStream) {
this(file, xStream, "utf-8", "<>?:/\\\"|*%");
}
public FilePersistenceStrategy(File file, XStream xStream, String str, String str2) {
super(file, xStream, str);
this.illegalChars = str2;
}
}