This repository was archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathAbstractSnippet.java
More file actions
89 lines (75 loc) · 3.05 KB
/
AbstractSnippet.java
File metadata and controls
89 lines (75 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
* See LICENSE in the project root for license information.
*/
package com.microsoft.graph.snippets.snippet;
import com.microsoft.graph.concurrency.ICallback;
import com.microsoft.graph.models.extensions.IGraphServiceClient;
import com.microsoft.graph.snippets.application.SnippetApp;
public abstract class AbstractSnippet<Result> {
private static final int mNameIndex = 0;
private static final int mDescIndex = 1;
private static final int mUrlIndex = 2;
private static final int mIsAdminRequiredIndex = 3;
private static final int mCodeSnippetIndex = 4;
protected final IGraphServiceClient mGraphServiceClient;
boolean mIsAdminRequired;
private String mName, mDesc, mUrl, mCodeSnippet;
/**
* Snippet constructor
*
* @param category Snippet category as corresponds to UI displayed sections (organization, me, groups, etc...)
* @param descriptionArray The String array for the specified snippet
*/
public AbstractSnippet(
SnippetCategory category,
Integer descriptionArray) {
//Get snippet configuration information from the
//XML configuration for the snippet
getSnippetArrayContent(category, descriptionArray);
mGraphServiceClient = SnippetApp.getApp().getGraphServiceClient();
}
/**
* Gets the items from the specified snippet XML string array and stores the values
* in private class fields
*
* @param category Snippet category as corresponds to UI displayed sections (organization, me, groups, etc...)
* @param descriptionArray The String array for the specified snippet
*/
private void getSnippetArrayContent(SnippetCategory category, Integer descriptionArray) {
if (null != descriptionArray) {
String[] params = SnippetApp.getApp().getResources().getStringArray(descriptionArray);
try {
mName = params[mNameIndex];
mDesc = params[mDescIndex];
mUrl = params[mUrlIndex];
mCodeSnippet = params[mCodeSnippetIndex];
String isAdminRequired = params[mIsAdminRequiredIndex];
mIsAdminRequired = isAdminRequired.equalsIgnoreCase("true");
} catch (IndexOutOfBoundsException ex) {
throw new RuntimeException(
"Invalid array in "
+ category.mSection
+ " snippet XML file"
, ex);
}
} else {
mName = category.mSection;
mDesc = mUrl = null;
}
}
public String getName() {
return mName;
}
public String getDescription() {
return mDesc;
}
public String getCodeSnippet() { return mCodeSnippet; }
public String getUrl() {
return mUrl;
}
public boolean getIsAdminRequired() {
return mIsAdminRequired;
}
public abstract void request(ICallback<Result> callback);
}