You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
src/api-impl: fix up code style, mainly for code imported from AOSP
used the following (plus manual edits):
`clang-format --style="{BasedOnStyle: LLVM, IndentWidth: 8, UseTab: Always, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: true, ColumnLimit: 0}`
This commit is contained in:
@@ -36,145 +36,149 @@ import org.xmlpull.v1.XmlSerializer;
|
||||
* XML utility methods.
|
||||
*/
|
||||
public class Xml {
|
||||
/** @hide */ public Xml() {}
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public Xml() {}
|
||||
|
||||
/**
|
||||
* {@link org.xmlpull.v1.XmlPullParser} "relaxed" feature name.
|
||||
*
|
||||
* @see <a href="http://xmlpull.org/v1/doc/features.html#relaxed">
|
||||
* specification</a>
|
||||
*/
|
||||
public static String FEATURE_RELAXED = "http://xmlpull.org/v1/doc/features.html#relaxed";
|
||||
/**
|
||||
* {@link org.xmlpull.v1.XmlPullParser} "relaxed" feature name.
|
||||
*
|
||||
* @see <a href="http://xmlpull.org/v1/doc/features.html#relaxed">
|
||||
* specification</a>
|
||||
*/
|
||||
public static String FEATURE_RELAXED = "http://xmlpull.org/v1/doc/features.html#relaxed";
|
||||
|
||||
/**
|
||||
* Parses the given xml string and fires events on the given SAX handler.
|
||||
*/
|
||||
public static void parse(String xml, ContentHandler contentHandler)
|
||||
throws SAXException {
|
||||
try {
|
||||
XMLReader reader = new ExpatReader();
|
||||
reader.setContentHandler(contentHandler);
|
||||
reader.parse(new InputSource(new StringReader(xml)));
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Parses the given xml string and fires events on the given SAX handler.
|
||||
*/
|
||||
public static void parse(String xml, ContentHandler contentHandler)
|
||||
throws SAXException {
|
||||
try {
|
||||
XMLReader reader = new ExpatReader();
|
||||
reader.setContentHandler(contentHandler);
|
||||
reader.parse(new InputSource(new StringReader(xml)));
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses xml from the given reader and fires events on the given SAX
|
||||
* handler.
|
||||
*/
|
||||
public static void parse(Reader in, ContentHandler contentHandler)
|
||||
throws IOException, SAXException {
|
||||
XMLReader reader = new ExpatReader();
|
||||
reader.setContentHandler(contentHandler);
|
||||
reader.parse(new InputSource(in));
|
||||
}
|
||||
/**
|
||||
* Parses xml from the given reader and fires events on the given SAX
|
||||
* handler.
|
||||
*/
|
||||
public static void parse(Reader in, ContentHandler contentHandler)
|
||||
throws IOException, SAXException {
|
||||
XMLReader reader = new ExpatReader();
|
||||
reader.setContentHandler(contentHandler);
|
||||
reader.parse(new InputSource(in));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses xml from the given input stream and fires events on the given SAX
|
||||
* handler.
|
||||
*/
|
||||
public static void parse(InputStream in, Encoding encoding,
|
||||
ContentHandler contentHandler) throws IOException, SAXException {
|
||||
XMLReader reader = new ExpatReader();
|
||||
reader.setContentHandler(contentHandler);
|
||||
InputSource source = new InputSource(in);
|
||||
source.setEncoding(encoding.expatName);
|
||||
reader.parse(source);
|
||||
}
|
||||
/**
|
||||
* Parses xml from the given input stream and fires events on the given SAX
|
||||
* handler.
|
||||
*/
|
||||
public static void parse(InputStream in, Encoding encoding,
|
||||
ContentHandler contentHandler) throws IOException, SAXException {
|
||||
XMLReader reader = new ExpatReader();
|
||||
reader.setContentHandler(contentHandler);
|
||||
InputSource source = new InputSource(in);
|
||||
source.setEncoding(encoding.expatName);
|
||||
reader.parse(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new pull parser with namespace support.
|
||||
*/
|
||||
public static XmlPullParser newPullParser() {
|
||||
try {
|
||||
KXmlParser parser = new KXmlParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
return parser;
|
||||
} catch (XmlPullParserException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns a new pull parser with namespace support.
|
||||
*/
|
||||
public static XmlPullParser newPullParser() {
|
||||
try {
|
||||
KXmlParser parser = new KXmlParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
return parser;
|
||||
} catch (XmlPullParserException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new xml serializer.
|
||||
*/
|
||||
public static XmlSerializer newSerializer() {
|
||||
try {
|
||||
return XmlSerializerFactory.instance.newSerializer();
|
||||
} catch (XmlPullParserException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new xml serializer.
|
||||
*/
|
||||
public static XmlSerializer newSerializer() {
|
||||
try {
|
||||
return XmlSerializerFactory.instance.newSerializer();
|
||||
} catch (XmlPullParserException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Factory for xml serializers. Initialized on demand. */
|
||||
static class XmlSerializerFactory {
|
||||
static final String TYPE
|
||||
= "org.kxml2.io.KXmlParser,org.kxml2.io.KXmlSerializer";
|
||||
static final XmlPullParserFactory instance;
|
||||
static {
|
||||
try {
|
||||
instance = XmlPullParserFactory.newInstance(TYPE, null);
|
||||
} catch (XmlPullParserException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Factory for xml serializers. Initialized on demand.
|
||||
*/
|
||||
static class XmlSerializerFactory {
|
||||
static final String TYPE = "org.kxml2.io.KXmlParser,org.kxml2.io.KXmlSerializer";
|
||||
static final XmlPullParserFactory instance;
|
||||
static {
|
||||
try {
|
||||
instance = XmlPullParserFactory.newInstance(TYPE, null);
|
||||
} catch (XmlPullParserException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Supported character encodings.
|
||||
*/
|
||||
public enum Encoding {
|
||||
/**
|
||||
* Supported character encodings.
|
||||
*/
|
||||
public enum Encoding {
|
||||
|
||||
US_ASCII("US-ASCII"),
|
||||
UTF_8("UTF-8"),
|
||||
UTF_16("UTF-16"),
|
||||
ISO_8859_1("ISO-8859-1");
|
||||
US_ASCII("US-ASCII"),
|
||||
UTF_8("UTF-8"),
|
||||
UTF_16("UTF-16"),
|
||||
ISO_8859_1("ISO-8859-1");
|
||||
|
||||
final String expatName;
|
||||
final String expatName;
|
||||
|
||||
Encoding(String expatName) {
|
||||
this.expatName = expatName;
|
||||
}
|
||||
}
|
||||
Encoding(String expatName) {
|
||||
this.expatName = expatName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an encoding by name. Returns UTF-8 if you pass {@code null}.
|
||||
*/
|
||||
public static Encoding findEncodingByName(String encodingName)
|
||||
throws UnsupportedEncodingException {
|
||||
if (encodingName == null) {
|
||||
return Encoding.UTF_8;
|
||||
}
|
||||
/**
|
||||
* Finds an encoding by name. Returns UTF-8 if you pass {@code null}.
|
||||
*/
|
||||
public static Encoding findEncodingByName(String encodingName)
|
||||
throws UnsupportedEncodingException {
|
||||
if (encodingName == null) {
|
||||
return Encoding.UTF_8;
|
||||
}
|
||||
|
||||
for (Encoding encoding : Encoding.values()) {
|
||||
if (encoding.expatName.equalsIgnoreCase(encodingName))
|
||||
return encoding;
|
||||
}
|
||||
throw new UnsupportedEncodingException(encodingName);
|
||||
}
|
||||
for (Encoding encoding : Encoding.values()) {
|
||||
if (encoding.expatName.equalsIgnoreCase(encodingName))
|
||||
return encoding;
|
||||
}
|
||||
throw new UnsupportedEncodingException(encodingName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AttributeSet interface for use with the given XmlPullParser.
|
||||
* If the given parser itself implements AttributeSet, that implementation
|
||||
* is simply returned. Otherwise a wrapper class is
|
||||
* instantiated on top of the XmlPullParser, as a proxy for retrieving its
|
||||
* attributes, and returned to you.
|
||||
*
|
||||
* @param parser The existing parser for which you would like an
|
||||
* AttributeSet.
|
||||
*
|
||||
* @return An AttributeSet you can use to retrieve the
|
||||
* attribute values at each of the tags as the parser moves
|
||||
* through its XML document.
|
||||
*
|
||||
* @see AttributeSet
|
||||
*/
|
||||
public static AttributeSet asAttributeSet(XmlPullParser parser) {
|
||||
return (parser instanceof AttributeSet)
|
||||
? (AttributeSet) parser
|
||||
: new XmlPullAttributes(parser);
|
||||
}
|
||||
/**
|
||||
* Return an AttributeSet interface for use with the given XmlPullParser.
|
||||
* If the given parser itself implements AttributeSet, that implementation
|
||||
* is simply returned. Otherwise a wrapper class is
|
||||
* instantiated on top of the XmlPullParser, as a proxy for retrieving its
|
||||
* attributes, and returned to you.
|
||||
*
|
||||
* @param parser The existing parser for which you would like an
|
||||
* AttributeSet.
|
||||
*
|
||||
* @return An AttributeSet you can use to retrieve the
|
||||
* attribute values at each of the tags as the parser moves
|
||||
* through its XML document.
|
||||
*
|
||||
* @see AttributeSet
|
||||
*/
|
||||
public static AttributeSet asAttributeSet(XmlPullParser parser) {
|
||||
return (parser instanceof AttributeSet)
|
||||
? (AttributeSet)parser
|
||||
: new XmlPullAttributes(parser);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user