| 1 |
/* |
| 2 |
* Copyright (C) 2011 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Eclipse Public License, Version 1.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.eclipse.org/org/documents/epl-v10.php |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
package com.android.ide.common.resources; |
| 17 |
|
| 18 |
import com.android.annotations.NonNull; |
| 19 |
import com.android.annotations.Nullable; |
| 20 |
|
| 21 |
import java.util.ArrayList; |
| 22 |
import java.util.List; |
| 23 |
|
| 24 |
/** |
| 25 |
* A {@link ScanningContext} keeps track of state during a resource file scan, |
| 26 |
* such as any parsing errors encountered, whether Android ids have changed, and |
| 27 |
* so on. |
| 28 |
*/ |
| 29 |
public class ScanningContext { |
| 30 |
protected final ResourceRepository mRepository; |
| 31 |
private boolean mNeedsFullAapt; |
| 32 |
private List<String> mErrors = null; |
| 33 |
|
| 34 |
/** |
| 35 |
* Constructs a new {@link ScanningContext} |
| 36 |
* |
| 37 |
* @param repository the associated resource repository |
| 38 |
*/ |
| 39 |
public ScanningContext(@NonNull ResourceRepository repository) { |
| 40 |
super(); |
| 41 |
mRepository = repository; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Returns a list of errors encountered during scanning |
| 46 |
* |
| 47 |
* @return a list of errors encountered during scanning (or null) |
| 48 |
*/ |
| 49 |
@Nullable |
| 50 |
public List<String> getErrors() { |
| 51 |
return mErrors; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Adds the given error to the scanning context. The error should use the |
| 56 |
* same syntax as real aapt error messages such that the aapt parser can |
| 57 |
* properly detect the filename, line number, etc. |
| 58 |
* |
| 59 |
* @param error the error message, including file name and line number at |
| 60 |
* the beginning |
| 61 |
*/ |
| 62 |
public void addError(@NonNull String error) { |
| 63 |
if (mErrors == null) { |
| 64 |
mErrors = new ArrayList<String>(); |
| 65 |
} |
| 66 |
mErrors.add(error); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Returns the repository associated with this scanning context |
| 71 |
* |
| 72 |
* @return the associated repository, never null |
| 73 |
*/ |
| 74 |
@NonNull |
| 75 |
public ResourceRepository getRepository() { |
| 76 |
return mRepository; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Marks that a full aapt compilation of the resources is necessary because it has |
| 81 |
* detected a change that cannot be incrementally handled. |
| 82 |
*/ |
| 83 |
protected void requestFullAapt() { |
| 84 |
mNeedsFullAapt = true; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Returns whether this repository has been marked as "dirty"; if one or |
| 89 |
* more of the constituent files have declared that the resource item names |
| 90 |
* that they provide have changed. |
| 91 |
* |
| 92 |
* @return true if a full aapt compilation is required |
| 93 |
*/ |
| 94 |
public boolean needsFullAapt() { |
| 95 |
return mNeedsFullAapt; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Asks the context to check whether the given attribute name and value is valid |
| 100 |
* in this context. |
| 101 |
* |
| 102 |
* @param uri the XML namespace URI |
| 103 |
* @param name the attribute local name |
| 104 |
* @param value the attribute value |
| 105 |
* @return true if the attribute is valid |
| 106 |
*/ |
| 107 |
public boolean checkValue(@Nullable String uri, @NonNull String name, @NonNull String value) { |
| 108 |
return true; |
| 109 |
} |
| 110 |
} |