当前位置: 首页>>代码示例>>Java>>正文


Java XmlUtils类代码示例

本文整理汇总了Java中com.android.internal.util.XmlUtils的典型用法代码示例。如果您正苦于以下问题:Java XmlUtils类的具体用法?Java XmlUtils怎么用?Java XmlUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XmlUtils类属于com.android.internal.util包,在下文中一共展示了XmlUtils类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newFilter

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
@Override
public Filter newFilter(XmlPullParser parser)
        throws IOException, XmlPullParserException {
    Filter child = null;
    int outerDepth = parser.getDepth();
    while (XmlUtils.nextElementWithin(parser, outerDepth)) {
        Filter filter = IntentFirewall.parseFilter(parser);
        if (child == null) {
            child = filter;
        } else {
            throw new XmlPullParserException(
                    "<not> tag can only contain a single child filter.", parser, null);
        }
    }
    return new NotFilter(child);
}
 
开发者ID:TaRGroup,项目名称:IFWManager,代码行数:17,代码来源:NotFilter.java

示例2: parseCertificatesEntry

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
private CertificatesEntryRef parseCertificatesEntry(XmlResourceParser parser,
            boolean defaultOverridePins)
            throws IOException, XmlPullParserException, ParserException {
        boolean overridePins =
                parser.getAttributeBooleanValue(null, "overridePins", defaultOverridePins);
        int sourceId = parser.getAttributeResourceValue(null, "src", -1);
        String sourceString = parser.getAttributeValue(null, "src");
        CertificateSource source = null;
        if (sourceString == null) {
            throw new ParserException(parser, "certificates element missing src attribute");
        }
        if (sourceId != -1) {
            // TODO: Cache ResourceCertificateSources by sourceId
            source = new ResourceCertificateSource(sourceId, mContext);
        } else if ("system".equals(sourceString) || "user".equals(sourceString)) {
            // MLM treat user as system
            source = SystemCertificateSource.getInstance();
//        } else if ("user".equals(sourceString)) {
//            source = UserCertificateSource.getInstance();
        } else {
            throw new ParserException(parser, "Unknown certificates src. "
                    + "Should be one of system|user|@resourceVal");
        }
        XmlUtils.skipCurrentTag(parser);
        return new CertificatesEntryRef(source, overridePins);
    }
 
开发者ID:commonsguy,项目名称:cwac-netsecurity,代码行数:27,代码来源:XmlConfigSource.java

示例3: readFromXml

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
public FilterList readFromXml(XmlPullParser parser) throws IOException, XmlPullParserException {
    int outerDepth = parser.getDepth();
    while (XmlUtils.nextElementWithin(parser, outerDepth)) {
        readChild(parser);
    }
    return this;
}
 
开发者ID:TaRGroup,项目名称:IFWManager,代码行数:8,代码来源:FilterList.java

示例4: parsePinSet

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
private PinSet parsePinSet(XmlResourceParser parser)
        throws IOException, XmlPullParserException, ParserException {
    String expirationDate = parser.getAttributeValue(null, "expiration");
    long expirationTimestampMilis = Long.MAX_VALUE;
    if (expirationDate != null) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            sdf.setLenient(false);
            Date date = sdf.parse(expirationDate);
            if (date == null) {
                throw new ParserException(parser, "Invalid expiration date in pin-set");
            }
            expirationTimestampMilis = date.getTime();
        } catch (ParseException e) {
            throw new ParserException(parser, "Invalid expiration date in pin-set", e);
        }
    }

    int outerDepth = parser.getDepth();
    Set<Pin> pins = new HashSet<>();
    while (XmlUtils.nextElementWithin(parser, outerDepth)) {
        String tagName = parser.getName();
        if (tagName.equals("pin")) {
            pins.add(parsePin(parser));
        } else {
            XmlUtils.skipCurrentTag(parser);
        }
    }
    return new PinSet(pins, expirationTimestampMilis);
}
 
开发者ID:commonsguy,项目名称:cwac-netsecurity,代码行数:31,代码来源:XmlConfigSource.java

示例5: parseTrustAnchors

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
private Collection<CertificatesEntryRef> parseTrustAnchors(XmlResourceParser parser,
        boolean defaultOverridePins)
        throws IOException, XmlPullParserException, ParserException {
    int outerDepth = parser.getDepth();
    List<CertificatesEntryRef> anchors = new ArrayList<>();
    while (XmlUtils.nextElementWithin(parser, outerDepth)) {
        String tagName = parser.getName();
        if (tagName.equals("certificates")) {
            anchors.add(parseCertificatesEntry(parser, defaultOverridePins));
        } else {
            XmlUtils.skipCurrentTag(parser);
        }
    }
    return anchors;
}
 
开发者ID:commonsguy,项目名称:cwac-netsecurity,代码行数:16,代码来源:XmlConfigSource.java

示例6: getHtmlColor

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
/**
 * Converts an HTML color (named or numeric) to an integer RGB value.
 *
 * @param color Non-null color string.
 * @return A color value, or {@code -1} if the color string could not be interpreted.
 */
private static int getHtmlColor(String color) {
    Integer i = COLORS.get(color.toLowerCase());
    if (i != null) {
        return i;
    } else {
        try {
            return XmlUtils.convertValueToInt(color, -1);
        } catch (NumberFormatException nfe) {
            return -1;
        }
    }
  }
 
开发者ID:rdmwfs,项目名称:dobroreader-mod,代码行数:19,代码来源:DobroHtml.java

示例7: parseConfigEntry

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
private List<Pair<NetworkSecurityConfig.Builder, Set<Domain>>> parseConfigEntry(
        XmlResourceParser parser, Set<String> seenDomains,
        NetworkSecurityConfig.Builder parentBuilder, int configType)
        throws IOException, XmlPullParserException, ParserException {
    List<Pair<NetworkSecurityConfig.Builder, Set<Domain>>> builders = new ArrayList<>();
    NetworkSecurityConfig.Builder builder = new NetworkSecurityConfig.Builder();
    builder.setParent(parentBuilder);
    Set<Domain> domains = new HashSet<>();
    boolean seenPinSet = false;
    boolean seenTrustAnchors = false;
    boolean defaultOverridePins = configType == CONFIG_DEBUG;
    String configName = parser.getName();
    int outerDepth = parser.getDepth();
    // Add this builder now so that this builder occurs before any of its children. This
    // makes the final build pass easier.
    builders.add(new Pair<>(builder, domains));
    // Parse config attributes. Only set values that are present, config inheritence will
    // handle the rest.
    for (int i = 0; i < parser.getAttributeCount(); i++) {
        String name = parser.getAttributeName(i);
        if ("hstsEnforced".equals(name)) {
            builder.setHstsEnforced(
                    parser.getAttributeBooleanValue(i,
                            NetworkSecurityConfig.DEFAULT_HSTS_ENFORCED));
        } else if ("cleartextTrafficPermitted".equals(name)) {
            builder.setCleartextTrafficPermitted(
                    parser.getAttributeBooleanValue(i,
                            NetworkSecurityConfig.DEFAULT_CLEARTEXT_TRAFFIC_PERMITTED));
        }
    }
    // Parse the config elements.
    while (XmlUtils.nextElementWithin(parser, outerDepth)) {
        String tagName = parser.getName();
        if ("domain".equals(tagName)) {
            if (configType != CONFIG_DOMAIN) {
                throw new ParserException(parser,
                        "domain element not allowed in " + getConfigString(configType));
            }
            Domain domain = parseDomain(parser, seenDomains);
            domains.add(domain);
        } else if ("trust-anchors".equals(tagName)) {
            if (seenTrustAnchors) {
                throw new ParserException(parser,
                        "Multiple trust-anchor elements not allowed");
            }
            builder.addCertificatesEntryRefs(
                    parseTrustAnchors(parser, defaultOverridePins));
            seenTrustAnchors = true;
        } else if ("pin-set".equals(tagName)) {
            if (configType != CONFIG_DOMAIN) {
                throw new ParserException(parser,
                        "pin-set element not allowed in " + getConfigString(configType));
            }
            if (seenPinSet) {
                throw new ParserException(parser, "Multiple pin-set elements not allowed");
            }
            builder.setPinSet(parsePinSet(parser));
            seenPinSet = true;
        } else if ("domain-config".equals(tagName)) {
            if (configType != CONFIG_DOMAIN) {
                throw new ParserException(parser,
                        "Nested domain-config not allowed in " + getConfigString(configType));
            }
            builders.addAll(parseConfigEntry(parser, seenDomains, builder, configType));
        } else {
            XmlUtils.skipCurrentTag(parser);
        }
    }
    if (configType == CONFIG_DOMAIN && domains.isEmpty()) {
        throw new ParserException(parser, "No domain elements in domain-config");
    }
    return builders;
}
 
开发者ID:commonsguy,项目名称:cwac-netsecurity,代码行数:74,代码来源:XmlConfigSource.java

示例8: parseNetworkSecurityConfig

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
private void parseNetworkSecurityConfig(XmlResourceParser parser)
        throws IOException, XmlPullParserException, ParserException {
    Set<String> seenDomains = new HashSet<>();
    List<Pair<NetworkSecurityConfig.Builder, Set<Domain>>> builders = new ArrayList<>();
    NetworkSecurityConfig.Builder baseConfigBuilder = null;
    NetworkSecurityConfig.Builder debugConfigBuilder = null;
    boolean seenDebugOverrides = false;
    boolean seenBaseConfig = false;

    XmlUtils.beginDocument(parser, "network-security-config");
    int outerDepth = parser.getDepth();
    while (XmlUtils.nextElementWithin(parser, outerDepth)) {
        if ("base-config".equals(parser.getName())) {
            if (seenBaseConfig) {
                throw new ParserException(parser, "Only one base-config allowed");
            }
            seenBaseConfig = true;
            baseConfigBuilder =
                    parseConfigEntry(parser, seenDomains, null, CONFIG_BASE).get(0).first;
        } else if ("domain-config".equals(parser.getName())) {
            builders.addAll(
                    parseConfigEntry(parser, seenDomains, baseConfigBuilder, CONFIG_DOMAIN));
        } else if ("debug-overrides".equals(parser.getName())) {
            if (seenDebugOverrides) {
                throw new ParserException(parser, "Only one debug-overrides allowed");
            }
            if (mDebugBuild) {
                debugConfigBuilder =
                        parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first;
            } else {
                XmlUtils.skipCurrentTag(parser);
            }
            seenDebugOverrides = true;
        } else {
            XmlUtils.skipCurrentTag(parser);
        }
    }
    // If debug is true and there was no debug-overrides in the file check for an extra
    // _debug resource.
    if (mDebugBuild && debugConfigBuilder == null) {
        debugConfigBuilder = parseDebugOverridesResource();
    }

    // Use the platform default as the parent of the base config for any values not provided
    // there. If there is no base config use the platform default.
    NetworkSecurityConfig.Builder platformDefaultBuilder =
            NetworkSecurityConfig.getDefaultBuilder(mTargetSdkVersion);
    addDebugAnchorsIfNeeded(debugConfigBuilder, platformDefaultBuilder);
    if (baseConfigBuilder != null) {
        baseConfigBuilder.setParent(platformDefaultBuilder);
        addDebugAnchorsIfNeeded(debugConfigBuilder, baseConfigBuilder);
    } else {
        baseConfigBuilder = platformDefaultBuilder;
    }
    // Build the per-domain config mapping.
    Set<Pair<Domain, NetworkSecurityConfig>> configs = new HashSet<>();

    for (Pair<NetworkSecurityConfig.Builder, Set<Domain>> entry : builders) {
        NetworkSecurityConfig.Builder builder = entry.first;
        Set<Domain> domains = entry.second;
        // Set the parent of configs that do not have a parent to the base-config. This can
        // happen if the base-config comes after a domain-config in the file.
        // Note that this is safe with regards to children because of the order that
        // parseConfigEntry returns builders, the parent is always before the children. The
        // children builders will not have build called until _after_ their parents have their
        // parent set so everything is consistent.
        if (builder.getParent() == null) {
            builder.setParent(baseConfigBuilder);
        }
        addDebugAnchorsIfNeeded(debugConfigBuilder, builder);
        NetworkSecurityConfig config = builder.build();
        for (Domain domain : domains) {
            configs.add(new Pair<>(domain, config));
        }
    }
    mDefaultConfig = baseConfigBuilder.build();
    mDomainMap = configs;
}
 
开发者ID:commonsguy,项目名称:cwac-netsecurity,代码行数:79,代码来源:XmlConfigSource.java

示例9: parseDebugOverridesResource

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
private NetworkSecurityConfig.Builder parseDebugOverridesResource()
        throws IOException, XmlPullParserException, ParserException {
    Resources resources = mContext.getResources();
    String packageName = resources.getResourcePackageName(mResourceId);
    String entryName = resources.getResourceEntryName(mResourceId);
    int resId = resources.getIdentifier(entryName + "_debug", "xml", packageName);
    // No debug-overrides resource was found, nothing to parse.
    if (resId == 0) {
        return null;
    }
    NetworkSecurityConfig.Builder debugConfigBuilder = null;
    // Parse debug-overrides out of the _debug resource.
    XmlResourceParser parser=null;

    try {
        parser = resources.getXml(resId);

        XmlUtils.beginDocument(parser, "network-security-config");
        int outerDepth = parser.getDepth();
        boolean seenDebugOverrides = false;
        while (XmlUtils.nextElementWithin(parser, outerDepth)) {
            if ("debug-overrides".equals(parser.getName())) {
                if (seenDebugOverrides) {
                    throw new ParserException(parser, "Only one debug-overrides allowed");
                }
                if (mDebugBuild) {
                    debugConfigBuilder =
                            parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first;
                } else {
                    XmlUtils.skipCurrentTag(parser);
                }
                seenDebugOverrides = true;
            } else {
                XmlUtils.skipCurrentTag(parser);
            }
        }
    }
    finally {
        if (parser!=null) parser.close();
    }

    return debugConfigBuilder;
}
 
开发者ID:commonsguy,项目名称:cwac-netsecurity,代码行数:44,代码来源:XmlConfigSource.java

示例10: getAttributeListValue

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
public int getAttributeListValue(String namespace, String attribute,
        String[] options, int defaultValue) {
    return XmlUtils.convertValueToList(
        getAttributeValue(namespace, attribute), options, defaultValue);
}
 
开发者ID:Gracker,项目名称:Android-Framework-Tools-Utils,代码行数:6,代码来源:XmlPullAttributes.java

示例11: getAttributeBooleanValue

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
public boolean getAttributeBooleanValue(String namespace, String attribute,
        boolean defaultValue) {
    return XmlUtils.convertValueToBoolean(
        getAttributeValue(namespace, attribute), defaultValue);
}
 
开发者ID:Gracker,项目名称:Android-Framework-Tools-Utils,代码行数:6,代码来源:XmlPullAttributes.java

示例12: getAttributeResourceValue

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
public int getAttributeResourceValue(String namespace, String attribute,
        int defaultValue) {
    return XmlUtils.convertValueToInt(
        getAttributeValue(namespace, attribute), defaultValue);
}
 
开发者ID:Gracker,项目名称:Android-Framework-Tools-Utils,代码行数:6,代码来源:XmlPullAttributes.java

示例13: getAttributeIntValue

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
public int getAttributeIntValue(String namespace, String attribute,
        int defaultValue) {
    return XmlUtils.convertValueToInt(
        getAttributeValue(namespace, attribute), defaultValue);
}
 
开发者ID:Gracker,项目名称:Android-Framework-Tools-Utils,代码行数:6,代码来源:XmlPullAttributes.java

示例14: getAttributeUnsignedIntValue

import com.android.internal.util.XmlUtils; //导入依赖的package包/类
public int getAttributeUnsignedIntValue(String namespace, String attribute,
        int defaultValue) {
    return XmlUtils.convertValueToUnsignedInt(
        getAttributeValue(namespace, attribute), defaultValue);
}
 
开发者ID:Gracker,项目名称:Android-Framework-Tools-Utils,代码行数:6,代码来源:XmlPullAttributes.java


注:本文中的com.android.internal.util.XmlUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。