Example usage for android.content ContentValues getAsString

List of usage examples for android.content ContentValues getAsString

Introduction

In this page you can find the example usage for android.content ContentValues getAsString.

Prototype

public String getAsString(String key) 

Source Link

Document

Gets a value and converts it to a String.

Usage

From source file:com.openerp.orm.ORM.java

/**
 * Write.// w w  w .j  av  a2  s .co  m
 * 
 * @param dbHelper
 *            the db helper
 * @param values
 *            the values
 * @param id
 *            the id
 * @param fromServer
 *            the from server
 * @return true, if successful
 */
public boolean write(BaseDBHelper dbHelper, ContentValues values, int id, boolean fromServer) {

    // Handling many2one records
    HashMap<String, Object> many2onecols = dbHelper.getMany2OneColumns();
    // Handling Many2Many Records
    HashMap<String, Object> many2manycols = dbHelper.getMany2ManyColumns();
    for (String key : many2manycols.keySet()) {
        try {

            JSONArray m2mArray = new JSONArray(values.getAsString(key));
            Many2Many m2m = (Many2Many) many2manycols.get(key);
            updateM2MRecords(values.getAsString("id"), m2mArray, key, dbHelper, m2m, values);
        } catch (Exception e) {

        }
        values.remove(key);
    }
    // Handling many2one records. [id, "name"] to id
    for (String key : many2onecols.keySet()) {
        try {
            String tempVals = values.getAsString(key);
            if (!tempVals.equals("false")) {
                JSONArray m2oArray = new JSONArray(values.getAsString(key));
                int m2oid = m2oArray.getInt(0);
                values.put(key, m2oid);
            } else {
                values.put(key, "false");
            }
        } catch (Exception e) {
        }
    }

    boolean flag = false;
    SQLiteDatabase db = getWritableDatabase();
    try {
        if (OpenERPServerConnection.isNetworkAvailable(context)) {
            String table = modelToTable(dbHelper.getModelName());
            try {

                JSONObject arguments = new JSONObject();
                for (String key : values.keySet()) {
                    try {
                        int keyid = Integer.parseInt(values.getAsString(key));
                        arguments.put(key, keyid);
                    } catch (Exception e) {
                        String temp = values.getAsString(key);
                        if (temp.equals("true") || temp.equals("false")) {
                            arguments.put(key, ((temp.equals("true")) ? true : false));
                        } else {

                            arguments.put(key, values.get(key).toString());

                        }
                    }

                }
                if (fromServer) {
                    int res = db.update(table, values, "id = " + id, null);
                    flag = true;
                } else {

                    if (oe_obj.updateValues(dbHelper.getModelName(), arguments, id)) {
                        int res = db.update(table, values, "id = " + id, null);
                        flag = true;
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
                flag = false;
            }

        } else {
            Toast.makeText(context, "Unable to Connect server ! Please Try again Later. ", Toast.LENGTH_LONG)
                    .show();
            flag = false;
        }
    } catch (Exception e) {
    }
    db.close();
    return flag;
}

From source file:org.frc836.database.DBSyncService.java

private void processConfig(JSONArray config) {
    try {/*  w  w w  .j  a  v a2 s . c  o  m*/
        for (int i = 0; i < config.length(); i++) {
            JSONObject row = config.getJSONObject(i);
            Action action = Action.UPDATE;
            if (row.getInt(CONFIGURATION_LU_Entry.COLUMN_NAME_INVALID) != 0) {
                action = Action.DELETE;
            }
            ContentValues vals = new ContentValues();
            vals.put(CONFIGURATION_LU_Entry.COLUMN_NAME_ID, row.getInt(CONFIGURATION_LU_Entry.COLUMN_NAME_ID));
            vals.put(CONFIGURATION_LU_Entry.COLUMN_NAME_CONFIGURATION_DESC,
                    row.getString(CONFIGURATION_LU_Entry.COLUMN_NAME_CONFIGURATION_DESC));
            vals.put(CONFIGURATION_LU_Entry.COLUMN_NAME_TIMESTAMP, DB.dateParser
                    .format(new Date(row.getLong(CONFIGURATION_LU_Entry.COLUMN_NAME_TIMESTAMP) * 1000)));

            // check if this entry exists already
            String[] projection = { CONFIGURATION_LU_Entry.COLUMN_NAME_CONFIGURATION_DESC };
            String[] where = { vals.getAsString(CONFIGURATION_LU_Entry.COLUMN_NAME_ID) };
            synchronized (ScoutingDBHelper.lock) {

                SQLiteDatabase db = ScoutingDBHelper.getInstance().getWritableDatabase();

                Cursor c = db.query(CONFIGURATION_LU_Entry.TABLE_NAME, projection, // select
                        CONFIGURATION_LU_Entry.COLUMN_NAME_ID + "=?", where, null, // don't
                        // group
                        null, // don't filter
                        null, // don't order
                        "0,1"); // limit to 1
                try {
                    if (!c.moveToFirst()) {
                        if (action == Action.UPDATE)
                            action = Action.INSERT;
                        else if (action == Action.DELETE)
                            action = Action.NOTHING;
                    }

                    switch (action) {
                    case UPDATE:
                        db.update(CONFIGURATION_LU_Entry.TABLE_NAME, vals,
                                CONFIGURATION_LU_Entry.COLUMN_NAME_ID + " = ?", where);
                        break;
                    case INSERT:
                        db.insert(CONFIGURATION_LU_Entry.TABLE_NAME, null, vals);
                        break;
                    case DELETE:
                        db.delete(CONFIGURATION_LU_Entry.TABLE_NAME,
                                CONFIGURATION_LU_Entry.COLUMN_NAME_ID + " = ?", where);
                        break;
                    default:
                    }
                } finally {
                    if (c != null)
                        c.close();
                    ScoutingDBHelper.getInstance().close();
                }
            }
        }
    } catch (JSONException e) {
        // TODO handle error
    }
}

From source file:android.pim.vcard.VCardBuilder.java

private boolean containsNonEmptyName(final ContentValues contentValues) {
    final String familyName = contentValues.getAsString(StructuredName.FAMILY_NAME);
    final String middleName = contentValues.getAsString(StructuredName.MIDDLE_NAME);
    final String givenName = contentValues.getAsString(StructuredName.GIVEN_NAME);
    final String prefix = contentValues.getAsString(StructuredName.PREFIX);
    final String suffix = contentValues.getAsString(StructuredName.SUFFIX);
    final String phoneticFamilyName = contentValues.getAsString(StructuredName.PHONETIC_FAMILY_NAME);
    final String phoneticMiddleName = contentValues.getAsString(StructuredName.PHONETIC_MIDDLE_NAME);
    final String phoneticGivenName = contentValues.getAsString(StructuredName.PHONETIC_GIVEN_NAME);
    final String displayName = contentValues.getAsString(StructuredName.DISPLAY_NAME);
    return !(TextUtils.isEmpty(familyName) && TextUtils.isEmpty(middleName) && TextUtils.isEmpty(givenName)
            && TextUtils.isEmpty(prefix) && TextUtils.isEmpty(suffix) && TextUtils.isEmpty(phoneticFamilyName)
            && TextUtils.isEmpty(phoneticMiddleName) && TextUtils.isEmpty(phoneticGivenName)
            && TextUtils.isEmpty(displayName));
}

From source file:edu.stanford.mobisocial.dungbeetle.DungBeetleContentProvider.java

/**
 * Inserts a message locally that has been received from some agent,
 * typically from a remote device./* www . j a  v a2 s  .c o m*/
 */
@Override
public Uri insert(Uri uri, ContentValues values) {
    ContentResolver resolver = getContext().getContentResolver();
    if (DBG)
        Log.i(TAG, "Inserting at uri: " + uri + ", " + values);

    final String appId = getCallingActivityId();
    if (appId == null) {
        Log.d(TAG, "No AppId for calling activity. Ignoring query.");
        return null;
    }

    List<String> segs = uri.getPathSegments();
    if (match(uri, "feeds", "me")) {
        if (!appId.equals(SUPER_APP_ID)) {
            return null;
        }

        long objId = mHelper.addToFeed(appId, "friend", values);
        Uri objUri = DbObject.uriForObj(objId);
        resolver.notifyChange(Feed.uriForName("me"), null);
        resolver.notifyChange(Feed.uriForName("friend"), null);
        resolver.notifyChange(objUri, null);
        return objUri;
    } else if (match(uri, "feeds", ".+")) {
        String feedName = segs.get(1);
        String type = values.getAsString(DbObject.TYPE);
        try {
            JSONObject json = new JSONObject(values.getAsString(DbObject.JSON));
            String objHash = null;
            if (feedName.contains(":")) {
                String[] parts = feedName.split(":");
                feedName = parts[0];
                objHash = parts[1];
            }
            if (objHash != null) {
                json.put(DbObjects.TARGET_HASH, Long.parseLong(objHash));
                json.put(DbObjects.TARGET_RELATION, DbRelation.RELATION_PARENT);
                values.put(DbObject.JSON, json.toString());
            }

            String appAuthority = appId;
            if (SUPER_APP_ID.equals(appId)) {
                if (AppObj.TYPE.equals(type)) {
                    if (json.has(AppObj.ANDROID_PACKAGE_NAME)) {
                        appAuthority = json.getString(AppObj.ANDROID_PACKAGE_NAME);
                    }
                }
            }

            long objId = mHelper.addToFeed(appAuthority, feedName, values);
            Uri objUri = DbObject.uriForObj(objId);
            resolver.notifyChange(objUri, null);
            notifyDependencies(mHelper, resolver, segs.get(1));
            if (DBG)
                Log.d(TAG, "just inserted " + values.getAsString(DbObject.JSON));
            return objUri;
        } catch (JSONException e) {
            return null;
        }
    } else if (match(uri, "out")) {
        try {
            JSONObject obj = new JSONObject(values.getAsString("json"));
            long objId = mHelper.addToOutgoing(appId, values.getAsString(DbObject.DESTINATION),
                    values.getAsString(DbObject.TYPE), obj);
            resolver.notifyChange(Uri.parse(CONTENT_URI + "/out"), null);
            return DbObject.uriForObj(objId);
        } catch (JSONException e) {
            return null;
        }
    } else if (match(uri, "contacts")) {
        if (!appId.equals(SUPER_APP_ID)) {
            return null;
        }
        long id = mHelper.insertContact(values);
        resolver.notifyChange(Uri.parse(CONTENT_URI + "/contacts"), null);
        return uriWithId(uri, id);
    } else if (match(uri, "subscribers")) {
        // Question: Should this be restricted?
        // if(!appId.equals(SUPER_APP_ID)) return null;
        long id = mHelper.insertSubscriber(values);
        resolver.notifyChange(Uri.parse(CONTENT_URI + "/subscribers"), null);
        return uriWithId(uri, id);
    } else if (match(uri, "groups")) {
        if (!appId.equals(SUPER_APP_ID))
            return null;
        long id = mHelper.insertGroup(values);
        getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/groups"), null);
        return uriWithId(uri, id);
    } else if (match(uri, "group_members")) {
        if (!appId.equals(SUPER_APP_ID)) {
            return null;
        }
        long id = mHelper.insertGroupMember(values);
        getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/group_members"), null);
        getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/group_contacts"), null);
        return uriWithId(uri, id);
    }

    else if (match(uri, "group_invitations")) {
        if (!appId.equals(SUPER_APP_ID)) {
            return null;
        }
        String groupName = values.getAsString(InviteToGroupObj.GROUP_NAME);
        Uri dynUpdateUri = Uri.parse(values.getAsString(InviteToGroupObj.DYN_UPDATE_URI));
        long gid = values.getAsLong("groupId");
        SQLiteDatabase db = mHelper.getWritableDatabase();
        mHelper.addToOutgoing(db, appId, values.getAsString(InviteToGroupObj.PARTICIPANTS),
                InviteToGroupObj.TYPE, InviteToGroupObj.json(groupName, dynUpdateUri));
        getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/out"), null);
        return uriWithId(uri, gid);
    }

    else if (match(uri, "dynamic_groups")) {
        if (!appId.equals(SUPER_APP_ID)) {
            return null;
        }
        Uri gUri = Uri.parse(values.getAsString("uri"));
        GroupProviders.GroupProvider gp = GroupProviders.forUri(gUri);
        String feedName = gp.feedName(gUri);
        Maybe<Group> mg = mHelper.groupByFeedName(feedName);
        long id = -1;
        try {
            Group g = mg.get();
            id = g.id;
        } catch (Maybe.NoValError e) {
            ContentValues cv = new ContentValues();
            cv.put(Group.NAME, gp.groupName(gUri));
            cv.put(Group.FEED_NAME, feedName);
            cv.put(Group.DYN_UPDATE_URI, gUri.toString());

            String table = DbObject.TABLE;
            String[] columns = new String[] { DbObject.FEED_NAME };
            String selection = DbObject.CHILD_FEED_NAME + " = ?";
            String[] selectionArgs = new String[] { feedName };
            Cursor parent = mHelper.getReadableDatabase().query(table, columns, selection, selectionArgs, null,
                    null, null);
            try {
                if (parent.moveToFirst()) {
                    String parentName = parent.getString(0);
                    table = Group.TABLE;
                    columns = new String[] { Group._ID };
                    selection = Group.FEED_NAME + " = ?";
                    selectionArgs = new String[] { parentName };

                    Cursor parent2 = mHelper.getReadableDatabase().query(table, columns, selection,
                            selectionArgs, null, null, null);
                    try {
                        if (parent2.moveToFirst()) {
                            cv.put(Group.PARENT_FEED_ID, parent2.getLong(0));
                        } else {
                            Log.e(TAG, "Parent feed found but no id for " + parentName);
                        }
                    } finally {
                        parent2.close();
                    }
                } else {
                    Log.w(TAG, "No parent feed for " + feedName);
                }
            } finally {
                parent.close();
            }
            id = mHelper.insertGroup(cv);
            getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/dynamic_groups"), null);
            getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/groups"), null);
        }
        return uriWithId(uri, id);
    }

    else if (match(uri, "dynamic_group_member")) {
        if (!appId.equals(SUPER_APP_ID)) {
            return null;
        }
        SQLiteDatabase db = mHelper.getWritableDatabase();
        db.beginTransaction();
        try {
            ContentValues cv = new ContentValues();
            String pubKeyStr = values.getAsString(Contact.PUBLIC_KEY);
            RSAPublicKey k = RSACrypto.publicKeyFromString(pubKeyStr);
            String personId = mIdent.personIdForPublicKey(k);
            if (!personId.equals(mIdent.userPersonId())) {
                cv.put(Contact.PUBLIC_KEY, values.getAsString(Contact.PUBLIC_KEY));
                cv.put(Contact.NAME, values.getAsString(Contact.NAME));
                cv.put(Contact.EMAIL, values.getAsString(Contact.EMAIL));
                if (values.getAsString(Contact.PICTURE) != null) {
                    cv.put(Contact.PICTURE, values.getAsByteArray(Contact.PICTURE));
                }

                long cid = -1;
                Contact contact = mHelper.contactForPersonId(personId).otherwise(Contact.NA());
                if (contact.id > -1) {
                    cid = contact.id;
                } else {
                    cid = mHelper.insertContact(db, cv);
                }

                if (cid > -1) {

                    ContentValues gv = new ContentValues();
                    gv.put(GroupMember.GLOBAL_CONTACT_ID, values.getAsString(GroupMember.GLOBAL_CONTACT_ID));
                    gv.put(GroupMember.GROUP_ID, values.getAsLong(GroupMember.GROUP_ID));
                    gv.put(GroupMember.CONTACT_ID, cid);
                    mHelper.insertGroupMember(db, gv);
                    getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/group_members"),
                            null);
                    getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/contacts"), null);
                    getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/group_contacts"),
                            null);

                    // Add subscription to this private group feed
                    ContentValues sv = new ContentValues();
                    sv = new ContentValues();
                    sv.put(Subscriber.CONTACT_ID, cid);
                    sv.put(Subscriber.FEED_NAME, values.getAsString(Group.FEED_NAME));
                    mHelper.insertSubscriber(db, sv);

                    ContentValues xv = new ContentValues();
                    xv.put(Subscriber.CONTACT_ID, cid);
                    xv.put(Subscriber.FEED_NAME, "friend");
                    mHelper.insertSubscriber(db, xv);

                    getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/subscribers"),
                            null);

                    db.setTransactionSuccessful();
                }
                return uriWithId(uri, cid);
            } else {
                Log.i(TAG, "Omitting self.");
                return uriWithId(uri, Contact.MY_ID);
            }
        } finally {
            db.endTransaction();
        }
    } else {
        Log.e(TAG, "Failed to insert into " + uri);
        return null;
    }
}

From source file:android.pim.vcard.VCardBuilder.java

public VCardBuilder appendWebsites(final List<ContentValues> contentValuesList) {
    if (contentValuesList != null) {
        for (ContentValues contentValues : contentValuesList) {
            String website = contentValues.getAsString(Website.URL);
            if (website != null) {
                website = website.trim();
            }//from   www.j a v  a  2 s . co  m

            // Note: vCard 3.0 does not allow any parameter addition toward "URL"
            //       property, while there's no document in vCard 2.1.
            if (!TextUtils.isEmpty(website)) {
                appendLineWithCharsetAndQPDetection(VCardConstants.PROPERTY_URL, website);
            }
        }
    }
    return this;
}

From source file:org.frc836.database.DBSyncService.java

private void processRobots(JSONArray robots) {
    try {//  ww  w. j  a  va  2s. c  o  m
        for (int i = 0; i < robots.length(); i++) {
            JSONObject row = robots.getJSONObject(i);
            Action action = Action.UPDATE;
            if (row.getInt(ROBOT_LU_Entry.COLUMN_NAME_INVALID) != 0) {
                action = Action.DELETE;
            }
            ContentValues vals = new ContentValues();
            vals.put(ROBOT_LU_Entry.COLUMN_NAME_ID, row.getInt(ROBOT_LU_Entry.COLUMN_NAME_ID));
            vals.put(ROBOT_LU_Entry.COLUMN_NAME_TEAM_ID, row.getString(ROBOT_LU_Entry.COLUMN_NAME_TEAM_ID));
            vals.put(ROBOT_LU_Entry.COLUMN_NAME_ROBOT_PHOTO,
                    row.getString(ROBOT_LU_Entry.COLUMN_NAME_ROBOT_PHOTO));
            vals.put(ROBOT_LU_Entry.COLUMN_NAME_TIMESTAMP,
                    DB.dateParser.format(new Date(row.getLong(ROBOT_LU_Entry.COLUMN_NAME_TIMESTAMP) * 1000)));

            // check if this entry exists already
            String[] projection = { ROBOT_LU_Entry.COLUMN_NAME_ID };
            String[] where = { vals.getAsString(ROBOT_LU_Entry.COLUMN_NAME_TEAM_ID) };
            synchronized (ScoutingDBHelper.lock) {

                SQLiteDatabase db = ScoutingDBHelper.getInstance().getWritableDatabase();

                Cursor c = db.query(ROBOT_LU_Entry.TABLE_NAME, projection, // select
                        ROBOT_LU_Entry.COLUMN_NAME_TEAM_ID + "=?", where, null, // don't
                        // group
                        null, // don't filter
                        null, // don't order
                        "0,1"); // limit to 1
                try {
                    if (!c.moveToFirst()) {
                        if (action == Action.UPDATE)
                            action = Action.INSERT;
                        else if (action == Action.DELETE)
                            action = Action.NOTHING;
                    }

                    switch (action) {
                    case UPDATE:
                        db.update(ROBOT_LU_Entry.TABLE_NAME, vals, ROBOT_LU_Entry.COLUMN_NAME_TEAM_ID + " = ?",
                                where);
                        break;
                    case INSERT:
                        db.insert(ROBOT_LU_Entry.TABLE_NAME, null, vals);
                        break;
                    case DELETE:
                        db.delete(ROBOT_LU_Entry.TABLE_NAME, ROBOT_LU_Entry.COLUMN_NAME_TEAM_ID + " = ?",
                                where);
                        break;
                    default:
                    }
                } finally {
                    if (c != null)
                        c.close();
                    ScoutingDBHelper.getInstance().close();
                }
            }
        }
    } catch (JSONException e) {
        // TODO handle error
    }
}

From source file:org.kontalk.provider.UsersProvider.java

@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
    try {//from  www  .ja  v a  2  s.  c o m
        int match = sUriMatcher.match(uri);
        switch (match) {
        case USERS:
        case USERS_JID:
            return insertUser(values, Boolean.parseBoolean(uri.getQueryParameter(Users.OFFLINE)),
                    Boolean.parseBoolean(uri.getQueryParameter(Users.DISCARD_NAME)));

        case KEYS:
        case KEYS_JID:
        case KEYS_JID_FINGERPRINT:
            List<String> segs = uri.getPathSegments();
            String jid, fingerprint;
            if (segs.size() >= 2) {
                // Uri-based insert/update
                jid = segs.get(1);
                fingerprint = segs.get(2);
            } else {
                // take jid and fingerprint from values
                jid = values.getAsString(Keys.JID);
                fingerprint = values.getAsString(Keys.FINGERPRINT);
            }

            return insertOrUpdateKey(jid, fingerprint, values,
                    Boolean.parseBoolean(uri.getQueryParameter(Keys.INSERT_ONLY)));

        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
        }
    } finally {
        invalidateFastScrollingIndexCache();
    }
}

From source file:android.pim.vcard.VCardBuilder.java

public VCardBuilder appendNickNames(final List<ContentValues> contentValuesList) {
    final boolean useAndroidProperty;
    if (mIsV30) {
        useAndroidProperty = false;//ww  w . j av  a 2  s  .c o  m
    } else if (mUsesAndroidProperty) {
        useAndroidProperty = true;
    } else {
        // There's no way to add this field.
        return this;
    }
    if (contentValuesList != null) {
        for (ContentValues contentValues : contentValuesList) {
            final String nickname = contentValues.getAsString(Nickname.NAME);
            if (TextUtils.isEmpty(nickname)) {
                continue;
            }
            if (useAndroidProperty) {
                appendAndroidSpecificProperty(Nickname.CONTENT_ITEM_TYPE, contentValues);
            } else {
                appendLineWithCharsetAndQPDetection(VCardConstants.PROPERTY_NICKNAME, nickname);
            }
        }
    }
    return this;
}

From source file:android.pim.vcard.VCardBuilder.java

public VCardBuilder appendEmails(final List<ContentValues> contentValuesList) {
    boolean emailAddressExists = false;
    if (contentValuesList != null) {
        final Set<String> addressSet = new HashSet<String>();
        for (ContentValues contentValues : contentValuesList) {
            String emailAddress = contentValues.getAsString(Email.DATA);
            if (emailAddress != null) {
                emailAddress = emailAddress.trim();
            }//from  ww w.j ava  2s .c o m
            if (TextUtils.isEmpty(emailAddress)) {
                continue;
            }
            Integer typeAsObject = contentValues.getAsInteger(Email.TYPE);
            final int type = (typeAsObject != null ? typeAsObject : DEFAULT_EMAIL_TYPE);
            final String label = contentValues.getAsString(Email.LABEL);
            Integer isPrimaryAsInteger = contentValues.getAsInteger(Email.IS_PRIMARY);
            final boolean isPrimary = (isPrimaryAsInteger != null ? (isPrimaryAsInteger > 0) : false);
            emailAddressExists = true;
            if (!addressSet.contains(emailAddress)) {
                addressSet.add(emailAddress);
                appendEmailLine(type, label, emailAddress, isPrimary);
            }
        }
    }

    if (!emailAddressExists && mIsDoCoMo) {
        appendEmailLine(Email.TYPE_HOME, "", "", false);
    }

    return this;
}

From source file:android.pim.vcard.VCardBuilder.java

public VCardBuilder appendOrganizations(final List<ContentValues> contentValuesList) {
    if (contentValuesList != null) {
        for (ContentValues contentValues : contentValuesList) {
            String company = contentValues.getAsString(Organization.COMPANY);
            if (company != null) {
                company = company.trim();
            }/* ww w.  j  a  v  a  2 s  . co  m*/
            String department = contentValues.getAsString(Organization.DEPARTMENT);
            if (department != null) {
                department = department.trim();
            }
            String title = contentValues.getAsString(Organization.TITLE);
            if (title != null) {
                title = title.trim();
            }

            StringBuilder orgBuilder = new StringBuilder();
            if (!TextUtils.isEmpty(company)) {
                orgBuilder.append(company);
            }
            if (!TextUtils.isEmpty(department)) {
                if (orgBuilder.length() > 0) {
                    orgBuilder.append(';');
                }
                orgBuilder.append(department);
            }
            final String orgline = orgBuilder.toString();
            appendLine(VCardConstants.PROPERTY_ORG, orgline, !VCardUtils.containsOnlyPrintableAscii(orgline),
                    (mShouldUseQuotedPrintable && !VCardUtils.containsOnlyNonCrLfPrintableAscii(orgline)));

            if (!TextUtils.isEmpty(title)) {
                appendLine(VCardConstants.PROPERTY_TITLE, title, !VCardUtils.containsOnlyPrintableAscii(title),
                        (mShouldUseQuotedPrintable && !VCardUtils.containsOnlyNonCrLfPrintableAscii(title)));
            }
        }
    }
    return this;
}