Example usage for com.fasterxml.jackson.core JsonToken FIELD_NAME

List of usage examples for com.fasterxml.jackson.core JsonToken FIELD_NAME

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonToken FIELD_NAME.

Prototype

JsonToken FIELD_NAME

To view the source code for com.fasterxml.jackson.core JsonToken FIELD_NAME.

Click Source Link

Document

FIELD_NAME is returned when a String token is encountered as a field name (same lexical value, different function)

Usage

From source file:com.bazaarvoice.jackson.rison.RisonParser.java

@Override
public int nextIntValue(int defaultValue) throws IOException, JsonParseException {
    if (_currToken == JsonToken.FIELD_NAME) {
        _nameCopied = false;/*from  w  w  w  . j a v  a2  s .  c  o  m*/
        JsonToken t = _nextToken;
        _nextToken = null;
        _currToken = t;
        if (t == JsonToken.VALUE_NUMBER_INT) {
            return getIntValue();
        }
        if (t == JsonToken.START_ARRAY) {
            _parsingContext = _parsingContext.createChildArrayContext(_tokenInputRow, _tokenInputCol);
        } else if (t == JsonToken.START_OBJECT) {
            _parsingContext = _parsingContext.createChildObjectContext(_tokenInputRow, _tokenInputCol);
        }
        return defaultValue;
    }
    // !!! TODO: optimize this case as well
    return (nextToken() == JsonToken.VALUE_NUMBER_INT) ? getIntValue() : defaultValue;
}

From source file:com.github.shyiko.jackson.module.advice.AdvisedBeanDeserializer.java

@SuppressWarnings("resource")
protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser jp, DeserializationContext ctxt)
        throws IOException {
    final PropertyBasedCreator creator = _propertyBasedCreator;
    PropertyValueBuffer buffer = creator.startBuilding(jp, ctxt, _objectIdReader);

    TokenBuffer tokens = new TokenBuffer(jp);
    tokens.writeStartObject();/*from ww w. j a  v a2 s . co  m*/

    JsonToken t = jp.getCurrentToken();
    for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
        String propName = jp.getCurrentName();
        jp.nextToken(); // to point to value
        // creator property?
        SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
        if (creatorProp != null) {
            // Last creator property to set?
            Object value = creatorProp.deserialize(jp, ctxt);
            if (buffer.assignParameter(creatorProp.getCreatorIndex(), value)) {
                t = jp.nextToken(); // to move to following FIELD_NAME/END_OBJECT
                Object bean;
                try {
                    bean = creator.build(ctxt, buffer);
                } catch (Exception e) {
                    wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
                    continue; // never gets here
                }
                // if so, need to copy all remaining tokens into buffer
                while (t == JsonToken.FIELD_NAME) {
                    jp.nextToken(); // to skip name
                    tokens.copyCurrentStructure(jp);
                    t = jp.nextToken();
                }
                tokens.writeEndObject();
                if (bean.getClass() != _beanType.getRawClass()) {
                    // !!! 08-Jul-2011, tatu: Could probably support; but for now
                    //   it's too complicated, so bail out
                    tokens.close();
                    throw ctxt.mappingException("Can not create polymorphic instances with unwrapped values");
                }
                return _unwrappedPropertyHandler.processUnwrapped(jp, ctxt, bean, tokens);
            }
            continue;
        }
        // Object Id property?
        if (buffer.readIdProperty(propName)) {
            continue;
        }

        // regular property? needs buffering
        SettableBeanProperty prop = _beanProperties.find(propName);
        if (prop != null) {
            buffer.bufferProperty(prop, prop.deserialize(jp, ctxt));
            continue;
        }
        /* As per [JACKSON-313], things marked as ignorable should not be
         * passed to any setter
         */
        if (_ignorableProps != null && _ignorableProps.contains(propName)) {
            handleIgnoredProperty(jp, ctxt, handledType(), propName);
            continue;
        }
        tokens.writeFieldName(propName);
        tokens.copyCurrentStructure(jp);
        // "any property"?
        if (_anySetter != null) {
            buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(jp, ctxt));
        }
    }

    // We hit END_OBJECT, so:
    Object bean;
    try {
        bean = creator.build(ctxt, buffer);
    } catch (Exception e) {
        wrapInstantiationProblem(e, ctxt);
        return null; // never gets here
    }
    return _unwrappedPropertyHandler.processUnwrapped(jp, ctxt, bean, tokens);
}

From source file:org.apache.lucene.server.handlers.AddDocumentHandler.java

/** Parse one value for a field, which is either an
 *  object matching the type of the field, or a {boost:
 *  ..., value: ...}. *///  w w  w.  j  a v a  2s  .  c om
private static boolean parseOneValue(FieldDef fd, JsonParser p, Document doc) throws IOException {

    Object o = null;
    float boost = 1.0f;

    JsonToken token = p.nextToken();
    if (token == JsonToken.START_ARRAY) {
        if ("hierarchy".equals(fd.faceted) || fd.valueType == FieldDef.FieldValueType.LAT_LON) {
            o = getNativeValue(fd, token, p);
        } else {
            if (fd.multiValued == false) {
                fail(fd.name, "expected single value, not array, since this field is not multiValued");
            }
            while (true) {
                if (!parseOneValue(fd, p, doc)) {
                    break;
                }
            }
            return true;
        }
    } else {

        if (token == JsonToken.END_ARRAY) {
            assert fd.multiValued;
            return false;
        }

        if (fd.fieldType.indexOptions() != IndexOptions.NONE && token == JsonToken.START_OBJECT) {
            // Parse a {boost: X, value: Y}
            while (true) {
                token = p.nextToken();
                if (token == JsonToken.END_OBJECT) {
                    break;
                }
                assert token == JsonToken.FIELD_NAME;
                String key = p.getText();
                if (key.equals("boost")) {
                    token = p.nextToken();
                    if (token == JsonToken.VALUE_NUMBER_INT || token == JsonToken.VALUE_NUMBER_FLOAT) {
                        boost = p.getFloatValue();
                    } else {
                        fail(fd.name, "boost in inner object field value must have float or int value; got: "
                                + token);
                    }
                } else if (key.equals("value")) {
                    o = getNativeValue(fd, p.nextToken(), p);
                } else {
                    fail(fd.name, "unrecognized json key \"" + key
                            + "\" in inner object field value; must be boost or value");
                }
            }
            if (o == null) {
                fail(fd.name, "missing 'value' key");
            }
        } else {
            // Parse a native value:
            o = getNativeValue(fd, token, p);
        }
    }

    parseOneNativeValue(fd, doc, o, boost);
    return true;
}

From source file:com.zenesis.qx.remote.RequestHandler.java

/**
 * Handles dynamic changes to a qa.data.Array instance without having a complete replacement; expects a 
 * serverId, propertyName, type (one of "add", "remove", "order"), start, end, and optional array of items 
 * @param jp/* ww w. j a va2  s . co  m*/
 * @throws ServletException
 * @throws IOException
 */
protected void cmdEditArray(JsonParser jp) throws ServletException, IOException {
    // Get the basics
    int serverId = getFieldValue(jp, "serverId", Integer.class);
    String propertyName = getFieldValue(jp, "propertyName", String.class);
    String action = getFieldValue(jp, "type", String.class);
    Integer start = null;
    Integer end = null;

    if (!action.equals("replaceAll")) {
        start = getFieldValue(jp, "start", Integer.class);
        end = getFieldValue(jp, "end", Integer.class);
    }

    // Get our info
    Proxied serverObject = getProxied(serverId);
    ProxyType type = ProxyTypeManager.INSTANCE.getProxyType(serverObject.getClass());
    ProxyProperty prop = getProperty(type, propertyName);

    if (prop.getPropertyClass().isMap()) {
        Map items = null;

        // Get the optional array of items
        if (jp.nextToken() == JsonToken.FIELD_NAME && jp.getCurrentName().equals("items")
                && jp.nextToken() == JsonToken.START_OBJECT) {

            items = readMap(jp, prop.getPropertyClass().getKeyClass(), prop.getPropertyClass().getJavaType());
        }

        // Quick logging
        if (log.isInfoEnabled()) {
            String str = "";
            if (items != null)
                for (Object key : items.keySet()) {
                    if (str.length() > 0)
                        str += ", ";
                    str += String.valueOf(key) + "=" + String.valueOf(items.get(key));
                }
            log.info("edit-array: property=" + prop + ", type=" + action + ", start=" + start + ", end=" + end
                    + str);
        }

        if (action.equals("replaceAll")) {
            Map map = (Map) prop.getValue(serverObject);
            if (map == null) {
                try {
                    map = (Map) prop.getPropertyClass().getCollectionClass().newInstance();
                } catch (Exception e) {
                    throw new IllegalArgumentException(e.getMessage(), e);
                }
                prop.setValue(serverObject, map);
            }
            map.clear();
            map.putAll(items);
        } else
            throw new IllegalArgumentException("Unsupported action in cmdEditArray: " + action);

        // Because collection properties are objects and we change them without the serverObject's
        //   knowledge, we have to make sure we notify other trackers ourselves
        ProxyManager.propertyChanged(serverObject, propertyName, items, null);

        jp.nextToken();
    } else {
        // NOTE: items is an Array!!  But because it may be an array of primitive types, we have
        //   to use java.lang.reflect.Array to access members because we cannot cast arrays of
        //   primitives to Object[]
        Object items = null;

        // Get the optional array of items
        if (jp.nextToken() == JsonToken.FIELD_NAME && jp.getCurrentName().equals("items")
                && jp.nextToken() == JsonToken.START_ARRAY) {

            items = readArray(jp, prop.getPropertyClass().getJavaType());
        }
        int itemsLength = Array.getLength(items);

        // Quick logging
        if (log.isInfoEnabled()) {
            String str = "";
            if (items != null)
                for (int i = 0; i < itemsLength; i++) {
                    if (str.length() != 0)
                        str += ", ";
                    str += Array.get(items, i);
                }
            log.info("edit-array: property=" + prop + ", type=" + action + ", start=" + start + ", end=" + end
                    + str);
        }

        if (action.equals("replaceAll")) {
            if (prop.getPropertyClass().isCollection()) {
                Collection list = (Collection) prop.getValue(serverObject);
                if (list == null) {
                    try {
                        list = (Collection) prop.getPropertyClass().getCollectionClass().newInstance();
                    } catch (Exception e) {
                        throw new IllegalArgumentException(e.getMessage(), e);
                    }
                    prop.setValue(serverObject, list);
                }
                list.clear();
                if (items != null)
                    for (int i = 0; i < itemsLength; i++)
                        list.add(Array.get(items, i));

                // Because collection properties are objects and we change them without the serverObject's
                //   knowledge, we have to make sure we notify other trackers ourselves
                ProxyManager.propertyChanged(serverObject, propertyName, list, null);
            } else {
                prop.setValue(serverObject, items);
            }
        } else
            throw new IllegalArgumentException("Unsupported action in cmdEditArray: " + action);

        jp.nextToken();
    }
}

From source file:com.microsoft.windowsazure.storage.table.TableParser.java

/**
 * Reserved for internal use. Parses the operation response as a collection of entities. Reads entity data from the
 * specified input stream using the specified class type and optionally projects each entity result with the
 * specified resolver into an {@link ODataPayload} containing a collection of {@link TableResult} objects.
 * /*from   w  ww . java  2s .co m*/
 * @param inStream
 *            The <code>InputStream</code> to read the data to parse from.
 * @param clazzType
 *            The class type <code>T</code> implementing {@link TableEntity} for the entities returned. Set to
 *            <code>null</code> to ignore the returned entities and copy only response properties into the
 *            {@link TableResult} objects.
 * @param resolver
 *            An {@link EntityResolver} instance to project the entities into instances of type <code>R</code>. Set
 *            to <code>null</code> to return the entities as instances of the class type <code>T</code>.
 * @param opContext
 *            An {@link OperationContext} object used to track the execution of the operation.
 * @return
 *         An {@link ODataPayload} containing a collection of {@link TableResult} objects with the parsed operation
 *         response.
 * @throws ParseException
 *             if an error occurs while parsing the stream.
 * @throws InstantiationException
 *             if an error occurs while constructing the result.
 * @throws IllegalAccessException
 *             if an error occurs in reflection while parsing the result.
 * @throws StorageException
 *             if a storage service error occurs.
 * @throws IOException
 *             if an error occurs while accessing the stream.
 * @throws JsonParseException
 *             if an error occurs while parsing the stream.
 */
@SuppressWarnings("unchecked")
private static <T extends TableEntity, R> ODataPayload<?> parseJsonQueryResponse(final InputStream inStream,
        final Class<T> clazzType, final EntityResolver<R> resolver, final TableRequestOptions options,
        final OperationContext opContext) throws ParseException, InstantiationException, IllegalAccessException,
        StorageException, JsonParseException, IOException {
    ODataPayload<T> corePayload = null;
    ODataPayload<R> resolvedPayload = null;
    ODataPayload<?> commonPayload = null;

    JsonParser parser = createJsonParserFromStream(inStream);

    try {

        if (resolver != null) {
            resolvedPayload = new ODataPayload<R>();
            commonPayload = resolvedPayload;
        } else {
            corePayload = new ODataPayload<T>();
            commonPayload = corePayload;
        }

        if (!parser.hasCurrentToken()) {
            parser.nextToken();
        }

        ODataUtilities.assertIsStartObjectJsonToken(parser);

        // move into data  
        parser.nextToken();

        // if there is a clazz type and if JsonNoMetadata, create a classProperties dictionary to use for type inference once 
        // instead of querying the cache many times
        HashMap<String, PropertyPair> classProperties = null;
        if (options.getTablePayloadFormat() == TablePayloadFormat.JsonNoMetadata && clazzType != null) {
            classProperties = PropertyPair.generatePropertyPairs(clazzType);
        }

        while (parser.getCurrentToken() != null) {
            if (parser.getCurrentToken() == JsonToken.FIELD_NAME
                    && parser.getCurrentName().equals(ODataConstants.VALUE)) {
                // move to start of array
                parser.nextToken();

                ODataUtilities.assertIsStartArrayJsonToken(parser);

                // go to properties
                parser.nextToken();

                while (parser.getCurrentToken() == JsonToken.START_OBJECT) {
                    final TableResult res = parseJsonEntity(parser, clazzType, classProperties, resolver,
                            options, opContext);
                    if (corePayload != null) {
                        corePayload.tableResults.add(res);
                    }

                    if (resolver != null) {
                        resolvedPayload.results.add((R) res.getResult());
                    } else {
                        corePayload.results.add((T) res.getResult());
                    }

                    parser.nextToken();
                }

                ODataUtilities.assertIsEndArrayJsonToken(parser);
            }

            parser.nextToken();
        }
    } finally {
        parser.close();
    }

    return commonPayload;
}

From source file:com.bazaarvoice.jackson.rison.RisonParser.java

@Override
public long nextLongValue(long defaultValue) throws IOException, JsonParseException {
    if (_currToken == JsonToken.FIELD_NAME) { // mostly copied from '_nextAfterName'
        _nameCopied = false;//from www. j av a2s.c  o m
        JsonToken t = _nextToken;
        _nextToken = null;
        _currToken = t;
        if (t == JsonToken.VALUE_NUMBER_INT) {
            return getLongValue();
        }
        if (t == JsonToken.START_ARRAY) {
            _parsingContext = _parsingContext.createChildArrayContext(_tokenInputRow, _tokenInputCol);
        } else if (t == JsonToken.START_OBJECT) {
            _parsingContext = _parsingContext.createChildObjectContext(_tokenInputRow, _tokenInputCol);
        }
        return defaultValue;
    }
    // !!! TODO: optimize this case as well
    return (nextToken() == JsonToken.VALUE_NUMBER_INT) ? getLongValue() : defaultValue;
}

From source file:com.quinsoft.zeidon.standardoe.ActivateOisFromJsonStream.java

private JsonToken readOiMeta() throws Exception {
    String odName = null;/*w w  w.  ja va 2  s  . c  o m*/
    readOnlyOi = false;
    readOnly = false;
    totalRootCount = null;

    jp.nextToken();
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        String fieldName = jp.getCurrentName();
        jp.nextToken(); // Move to value.
        switch (fieldName) {
        case "application":
            application = task.getApplication(jp.getValueAsString());
            break;
        case "odName":
            odName = jp.getValueAsString();
            break; // Save OD name for later.
        case "incremental":
            incremental = jp.getValueAsBoolean();
            break;
        case "readOnlyOi":
            readOnlyOi = jp.getValueAsBoolean();
            break;
        case "readOnly":
            readOnly = jp.getValueAsBoolean();
            break;
        case "totalRootCount":
            totalRootCount = jp.getValueAsInt();
            break;

        default:
            task.log().warn("Unknown .oimeta fieldname %s", fieldName);
            break;
        }
    }

    if (odName == null)
        throw new ZeidonException("LodDef not specified in JSON .oimeta");

    // We don't load the LodDef until now because it's valid JSON to reorder
    // the values in the .oimeta object.
    lodDef = application.getLodDef(task, odName);
    view = task.activateEmptyObjectInstance(lodDef);
    returnList.add(view);
    JsonToken token = jp.nextToken();

    // Create a list to keep track of selected instances.
    selectedInstances = new ArrayList<>();

    // If the next token is FIELD_NAME then OI data is next so get the next token.
    // If it's not the the OI is EMPTY and token should be END_OBJECT.
    if (token == JsonToken.FIELD_NAME)
        token = jp.nextToken();
    else
        assert token == JsonToken.END_OBJECT;

    return token;
}

From source file:com.bazaarvoice.jackson.rison.RisonParser.java

@Override
public Boolean nextBooleanValue() throws IOException, JsonParseException {
    if (_currToken == JsonToken.FIELD_NAME) { // mostly copied from '_nextAfterName'
        _nameCopied = false;/* www .j a  v  a 2s  . c o m*/
        JsonToken t = _nextToken;
        _nextToken = null;
        _currToken = t;
        if (t == JsonToken.VALUE_TRUE) {
            return Boolean.TRUE;
        }
        if (t == JsonToken.VALUE_FALSE) {
            return Boolean.FALSE;
        }
        if (t == JsonToken.START_ARRAY) {
            _parsingContext = _parsingContext.createChildArrayContext(_tokenInputRow, _tokenInputCol);
        } else if (t == JsonToken.START_OBJECT) {
            _parsingContext = _parsingContext.createChildObjectContext(_tokenInputRow, _tokenInputCol);
        }
        return null;
    }
    switch (nextToken()) {
    case VALUE_TRUE:
        return Boolean.TRUE;
    case VALUE_FALSE:
        return Boolean.FALSE;
    }
    return null;
}

From source file:mobile.tiis.appv2.LoginActivity.java

/**
 * This method will take the url built to use the webservice
 * and will try to parse JSON from the webservice stream to get
 * the user and password if they are correct or not. In case correct, fills
 * the Android Account Manager.// w  w w. j a va  2  s. co m
 *
 * <p>This method will throw a Toast message when user and password
 * are not valid
 *
 */

protected void startWebService(final CharSequence loginURL, final String username, final String password) {
    client.setBasicAuth(username, password, true);

    //new handler in case of login error in the thread
    handler = new Handler();

    Thread thread = new Thread(new Runnable() {
        public void run() {
            try {
                int balanceCounter = 0;
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(loginURL.toString());
                Utils.writeNetworkLogFileOnSD(
                        Utils.returnDeviceIdAndTimestamp(getApplicationContext()) + loginURL.toString());
                httpGet.setHeader("Authorization", "Basic "
                        + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP));
                HttpResponse httpResponse = httpClient.execute(httpGet);
                InputStream inputStream = httpResponse.getEntity().getContent();
                Log.d("", loginURL.toString());

                ByteArrayInputStream bais = Utils.getMultiReadInputStream(inputStream);
                Utils.writeNetworkLogFileOnSD(Utils.returnDeviceIdAndTimestamp(getApplicationContext())
                        + Utils.getStringFromInputStreamAndLeaveStreamOpen(bais));
                bais.reset();
                JsonFactory factory = new JsonFactory();
                JsonParser jsonParser = factory.createJsonParser(bais);
                JsonToken token = jsonParser.nextToken();

                if (token == JsonToken.START_OBJECT) {
                    balanceCounter++;
                    boolean idNextToHfId = false;
                    while (!(balanceCounter == 0)) {
                        token = jsonParser.nextToken();

                        if (token == JsonToken.START_OBJECT) {
                            balanceCounter++;
                        } else if (token == JsonToken.END_OBJECT) {
                            balanceCounter--;
                        } else if (token == JsonToken.FIELD_NAME) {
                            String object = jsonParser.getCurrentName();
                            switch (object) {
                            case "HealthFacilityId":
                                token = jsonParser.nextToken();
                                app.setLoggedInUserHealthFacilityId(jsonParser.getText());
                                Log.d("", "healthFacilityId is: " + jsonParser.getText());
                                idNextToHfId = true;
                                break;
                            case "Firstname":
                                token = jsonParser.nextToken();
                                app.setLoggedInFirstname(jsonParser.getText());
                                Log.d("", "firstname is: " + jsonParser.getText());
                                break;
                            case "Lastname":
                                token = jsonParser.nextToken();
                                app.setLoggedInLastname(jsonParser.getText());
                                Log.d("", "lastname is: " + jsonParser.getText());
                                break;
                            case "Username":
                                token = jsonParser.nextToken();
                                app.setLoggedInUsername(jsonParser.getText());
                                Log.d("", "username is: " + jsonParser.getText());
                                break;
                            case "Lastlogin":
                                token = jsonParser.nextToken();
                                Log.d("", "lastlogin is: " + jsonParser.getText());
                                break;
                            case "Id":
                                if (idNextToHfId) {
                                    token = jsonParser.nextToken();
                                    app.setLoggedInUserId(jsonParser.getText());
                                    Log.d("", "Id is: " + jsonParser.getText());
                                }
                                break;
                            default:
                                break;
                            }
                        }
                    }

                    Account account = new Account(username, ACCOUNT_TYPE);
                    AccountManager accountManager = AccountManager.get(LoginActivity.this);
                    //                        boolean accountCreated = accountManager.addAccountExplicitly(account, LoginActivity.this.password, null);
                    boolean accountCreated = accountManager.addAccountExplicitly(account, password, null);

                    Bundle extras = LoginActivity.this.getIntent().getExtras();
                    if (extras != null) {
                        if (accountCreated) { //Pass the new account back to the account manager
                            AccountAuthenticatorResponse response = extras
                                    .getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
                            Bundle res = new Bundle();
                            res.putString(AccountManager.KEY_ACCOUNT_NAME, username);
                            res.putString(AccountManager.KEY_ACCOUNT_TYPE, ACCOUNT_TYPE);
                            res.putString(AccountManager.KEY_PASSWORD, password);
                            response.onResult(res);
                        }
                    }

                    SharedPreferences prefs = PreferenceManager
                            .getDefaultSharedPreferences(getApplicationContext());
                    SharedPreferences.Editor editor = prefs.edit();
                    editor.putBoolean("secondSyncNeeded", true);
                    editor.commit();

                    ContentValues values = new ContentValues();
                    values.put(SQLHandler.SyncColumns.UPDATED, 1);
                    values.put(SQLHandler.UserColumns.FIRSTNAME, app.getLOGGED_IN_FIRSTNAME());
                    values.put(SQLHandler.UserColumns.LASTNAME, app.getLOGGED_IN_LASTNAME());
                    values.put(SQLHandler.UserColumns.HEALTH_FACILITY_ID, app.getLOGGED_IN_USER_HF_ID());
                    values.put(SQLHandler.UserColumns.ID, app.getLOGGED_IN_USER_ID());
                    values.put(SQLHandler.UserColumns.USERNAME, app.getLOGGED_IN_USERNAME());
                    values.put(SQLHandler.UserColumns.PASSWORD, password);
                    databaseHandler.addUser(values);

                    Log.d(TAG, "initiating offline for " + username + " password = " + password);
                    app.initializeOffline(username, password);

                    Intent intent;
                    if (prefs.getBoolean("synchronization_needed", true)) {
                        Log.d("supportLog", "call the loggin second time before the account was found");
                        intent = new Intent(LoginActivity.this, LotSettingsActivity.class);
                    } else {
                        Log.d("supportLog", "call the loggin second time before the account was found");
                        intent = new Intent(LoginActivity.this, LotSettingsActivity.class);
                        evaluateIfFirstLogin(app.getLOGGED_IN_USER_ID());
                    }
                    app.setUsername(username);

                    startActivity(intent);
                }
                //if login failed show error
                else {
                    handler.post(new Runnable() {
                        public void run() {
                            progressDialog.show();
                            progressDialog.dismiss();
                            toastMessage("Login failed.\nPlease check your details!");
                            loginButton.setEnabled(true);
                        }
                    });
                }
            } catch (Exception e) {
                handler.post(new Runnable() {
                    public void run() {
                        progressDialog.show();
                        progressDialog.dismiss();
                        toastMessage("Login failed Login failed.\n"
                                + "Please check your details or your web connectivity");
                        loginButton.setEnabled(true);

                    }
                });
                e.printStackTrace();
            }
        }
    });
    thread.start();

}

From source file:org.apache.cxf.cwiki.SiteExporter.java

private String renderPage(AbstractPage p) throws ParserConfigurationException, IOException {
    ContentResource content = getContentResource();
    InputStream ins = content.getContentById(p.getId(), null, null, "body.export_view")
            .readEntity(InputStream.class);

    JsonParser parser = new JsonFactory().createParser(ins);
    JsonToken tok = parser.nextToken();//w w w. j  a  va 2s  .  c o  m
    boolean inExportView = false;
    while (tok != null) {
        if (tok == JsonToken.FIELD_NAME) {
            if (parser.getCurrentName().equals("export_view")) {
                inExportView = true;
            }
        } else if (tok == JsonToken.VALUE_STRING && inExportView && parser.getCurrentName().equals("value")) {
            return "<div id='ConfluenceContent'>" + parser.getText() + "</div>";
        }
        tok = parser.nextToken();
    }
    System.out.println("No text for page \"" + p.getTitle() + "\"");
    return "";
}