/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.firewall; import android.content.ComponentName; import android.content.Intent; import android.net.Uri; import android.os.PatternMatcher; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.regex.Pattern; abstract class StringFilter implements Filter { private static final String ATTR_EQUALS = "equals"; private static final String ATTR_STARTS_WITH = "startsWith"; private static final String ATTR_CONTAINS = "contains"; private static final String ATTR_PATTERN = "pattern"; private static final String ATTR_REGEX = "regex"; private static final String ATTR_IS_NULL = "isNull"; private final ValueProvider mValueProvider; private StringFilter(ValueProvider valueProvider) { this.mValueProvider = valueProvider; } /** * Constructs a new StringFilter based on the string filter attribute on the current * element, and the given StringValueMatcher. * * The current node should contain exactly 1 string filter attribute. E.g. equals, * contains, etc. Otherwise, an XmlPullParserException will be thrown. * * @param parser An XmlPullParser object positioned at an element that should * contain a string filter attribute * @return This StringFilter object */ public static StringFilter readFromXml(ValueProvider valueProvider, XmlPullParser parser) throws IOException, XmlPullParserException { StringFilter filter = null; for (int i=0; i