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


Java XmlUtils.skipCurrentTag方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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


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