com.abubusoft.kripton.android.sqlite.ContentProviderURIParamsExtractor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kripton-orm Show documentation
Show all versions of kripton-orm Show documentation
Kripton Persistence Library - ORM module
The newest version!
/*******************************************************************************
* Copyright 2015, 2017 Francesco Benincasa ([email protected]).
*
* 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.abubusoft.kripton.android.sqlite;
import com.abubusoft.kripton.exception.KriptonRuntimeException;
/**
*
* Extracts from an content provider URI, its path segments, after check that URI has
* right lenght, just to prevent URI manipulation. An example of URI is:
*
*
*
* content://androi.authority/masters/${master}/details/${detail}/subdetails/${subdetail}
*
*
*
* With param value:
*
*
*
* content://androi.authority/masters/1/details/2/subdetails/3
*
*
* Path segment index start from 0, so index of parameters are:
*
*
* - master: 1
* - detail: 3
* - subdetail: 5
*
*
*/
public class ContentProviderURIParamsExtractor {
/** The array. */
private String[] array;
/**
*
* Split an URI and check its size in terms of segment path.
*
*
* @param uri the uri
* @param expectedPathSegments the expected path segments
*/
public ContentProviderURIParamsExtractor(String uri, int expectedPathSegments) {
array = uri.split("/");
if (array.length != expectedPathSegments) {
throw (new KriptonRuntimeException(String.format("Uri '%s' has a wrong path size", uri)));
}
}
/**
* Extract a specific segment by its index.
*
* Path segment index start from 0.
*
* @param segmentIndex the segment index
* @return the path segment
*/
public String getPathSegment(int segmentIndex) {
return array[3 + segmentIndex];
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy