You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
5MI/MetaData.java

103 lines
3.7 KiB

// 多行注释,说明版权信息和许可证
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* 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 net.micode.notes.gtask.data;
import android.database.Cursor;
import android.util.Log;
import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException;
import org.json.JSONObject;
// MetaData类继承自Task类用于处理与任务相关的元数据
public class MetaData extends Task {
// 类的标签,用于日志记录
private final static String TAG = MetaData.class.getSimpleName();
// 用于存储相关任务的全局唯一标识符
private String mRelatedGid = null;
// 设置元数据信息
public void setMeta(String gid, JSONObject metaInfo) {
try {
// 将全局唯一标识符添加到元数据信息中
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
// 如果添加失败,记录错误日志
Log.e(TAG, "failed to put related gid");
}
// 设置任务的备注信息为元数据的字符串表示
setNotes(metaInfo.toString());
// 设置任务的名称为特定的元数据任务名称
setName(GTaskStringUtils.META_NOTE_NAME);
}
// 获取相关任务的全局唯一标识符
public String getRelatedGid() {
return mRelatedGid;
}
// 重写isWorthSaving方法判断任务是否值得保存
@Override
public boolean isWorthSaving() {
// 如果任务的备注信息不为空,则认为值得保存
return getNotes() != null;
}
// 从远程JSON对象设置内容
@Override
public void setContentByRemoteJSON(JSONObject js) {
// 首先调用父类的设置内容方法
super.setContentByRemoteJSON(js);
// 如果备注信息不为空
if (getNotes() != null) {
try {
// 将备注信息转换为JSON对象并获取全局唯一标识符
JSONObject metaInfo = new JSONObject(getNotes().trim());
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
// 如果转换失败记录警告日志并设置全局唯一标识符为null
Log.w(TAG, "failed to get related gid");
mRelatedGid = null;
}
}
}
// 从本地JSON对象设置内容此方法不应该被调用
@Override
public void setContentByLocalJSON(JSONObject js) {
// 如果被调用,抛出异常
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
// 从内容获取本地JSON对象此方法不应该被调用
@Override
public JSONObject getLocalJSONFromContent() {
// 如果被调用,抛出异常
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
// 获取同步操作,此方法不应该被调用
@Override
public int getSyncAction(Cursor c) {
// 如果被调用,抛出异常
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}
}