Example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml4

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeHtml4

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml4.

Prototype

public static final String escapeHtml4(final String input) 

Source Link

Document

Escapes the characters in a String using HTML entities.

For example:

"bread" & "butter"

becomes:

"bread" & "butter".

Usage

From source file:org.ng200.openolympus.markup.HtmlUtils.java

public static String convertCommonWhitespaceToHtml(final String str) {
    return StringEscapeUtils.escapeHtml4(str).replaceAll("\n", "<br/>").replaceAll(" ", "&nbsp;")
            .replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
}

From source file:org.opendatakit.aggregate.constants.HtmlUtil.java

public static String encodeFormInHiddenInput(String formXml, String xmlFileName) throws IOException {

    if (formXml == null) {
        throw new IOException(LOST_FORM_RE_ENCODING);
    }/*from   w w  w .java2 s  .c  o m*/

    if (xmlFileName == null) {
        xmlFileName = "default.xml";
    }

    StringBuilder html = new StringBuilder();
    html.append(HtmlConsts.BEGIN_OPEN_TAG + INPUT);
    html.append(BasicConsts.SPACE);
    html.append(createAttribute(ATTR_TYPE, HtmlConsts.INPUT_TYPE_HIDDEN));
    html.append(BasicConsts.SPACE);
    html.append(createAttribute(ATTR_NAME, ServletConsts.FORM_DEF_PRAM));
    html.append(BasicConsts.SPACE);
    html.append(createAttribute(ATTR_VALUE, StringEscapeUtils.escapeHtml4(formXml)));
    html.append(BasicConsts.SPACE);
    html.append(createAttribute(ATTR_SRC, xmlFileName));
    html.append(BasicConsts.SPACE);
    html.append(HtmlConsts.END_SELF_CLOSING_TAG);
    return html.toString();
}

From source file:org.opendatakit.aggregate.servlet.FormXmlServlet.java

/**
 * Handler for HTTP Get request that responds with the XML in plain
 *
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *//* w  w  w . j ava 2 s  . c o  m*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    // get parameters
    String formId = getParameter(req, ServletConsts.FORM_ID);
    if (formId == null) {
        errorMissingKeyParam(resp);
        return;
    }

    String readable = getParameter(req, ServletConsts.HUMAN_READABLE);
    boolean humanReadable = false;
    if (readable != null) {
        humanReadable = Boolean.parseBoolean(readable);
    }

    CallingContext cc = ContextFactory.getCallingContext(this, req);

    IForm form;
    try {
        form = FormFactory.retrieveFormByFormId(formId, cc);
    } catch (ODKFormNotFoundException e) {
        e.printStackTrace();
        odkIdNotFoundError(resp);
        return;
    } catch (ODKOverQuotaException e) {
        e.printStackTrace();
        quotaExceededError(resp);
        return;
    } catch (ODKDatastoreException e) {
        e.printStackTrace();
        datastoreError(resp);
        return;
    }
    String xmlString = null;

    try {
        if (form != null) {
            xmlString = form.getFormXml(cc);
        } else {
            odkIdNotFoundError(resp);
            return;
        }

        // Debug: String debugDisplay = WebUtils.escapeUTF8String(xmlString);

        if (humanReadable) {
            Map<String, String> properties = new HashMap<String, String>();
            properties.put(ServletConsts.FORM_ID, formId);
            String downloadXmlButton = HtmlUtil.createHtmlButtonToGetServlet(cc.getWebApplicationURL(ADDR),
                    ServletConsts.DOWNLOAD_XML_BUTTON_TXT, properties);

            beginBasicHtmlResponse(TITLE_INFO, resp, cc); // header info
            PrintWriter out = resp.getWriter();
            out.println("<h3>Form Name: <FONT COLOR=0000FF>" + form.getViewableName() + "</FONT></h3>");
            if (form.getFormFilename(cc) != null) {
                out.println("<h3>File Name: <FONT COLOR=0000FF>" + form.getFormFilename(cc) + "</FONT></h3>");
            }
            out.println(downloadXmlButton); // download button
            out.println("<PRE>");
            out.print(StringEscapeUtils.escapeHtml4(xmlString));// form xml
            out.println("</PRE>");
            finishBasicHtmlResponse(resp); // footer info
        } else {
            resp.setCharacterEncoding(HtmlConsts.UTF8_ENCODE);
            resp.setContentType(HtmlConsts.RESP_TYPE_XML);
            PrintWriter out = resp.getWriter();
            if (form.getFormFilename(cc) != null) {
                resp.setHeader(HtmlConsts.CONTENT_DISPOSITION, HtmlConsts.ATTACHMENT_FILENAME_TXT
                        + form.getFormFilename(cc) + BasicConsts.QUOTE + BasicConsts.SEMI_COLON);
            } else {
                resp.setHeader(HtmlConsts.CONTENT_DISPOSITION,
                        HtmlConsts.ATTACHMENT_FILENAME_TXT + form.getViewableFormNameSuitableAsFileName()
                                + ".xml" + BasicConsts.QUOTE + BasicConsts.SEMI_COLON);
            }
            out.print(xmlString);
        }
    } catch (ODKOverQuotaException e) {
        e.printStackTrace();
        quotaExceededError(resp);
    } catch (ODKDatastoreException e) {
        e.printStackTrace();
        odkIdNotFoundError(resp);
    }
}

From source file:org.opendatakit.aggregate.servlet.ServiceAccountPrivateKeyUploadServlet.java

/**
 * Handler for HTTP Get request to create xform upload page
 *
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *//*w w  w .  j a  v  a2 s.  c  om*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    CallingContext cc = ContextFactory.getCallingContext(this, req);

    StringBuilder headerString = new StringBuilder();
    headerString.append("<script type=\"application/javascript\" src=\"");
    headerString.append(cc.getWebApplicationURL(ServletConsts.UPLOAD_SCRIPT_RESOURCE));
    headerString.append("\"></script>");
    headerString.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
    headerString.append(cc.getWebApplicationURL(ServletConsts.UPLOAD_STYLE_RESOURCE));
    headerString.append("\" />");
    headerString.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
    headerString.append(cc.getWebApplicationURL(ServletConsts.UPLOAD_BUTTON_STYLE_RESOURCE));
    headerString.append("\" />");
    headerString.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
    headerString.append(cc.getWebApplicationURL(ServletConsts.AGGREGATE_STYLE));
    headerString.append("\" />");

    // header info
    beginBasicHtmlResponse(TITLE_INFO, headerString.toString(), resp, cc);

    String simpleApiKey;
    String clientId;
    String clientEmail;
    try {
        simpleApiKey = ServerPreferencesProperties.getGoogleSimpleApiKey(cc);
        clientId = ServerPreferencesProperties.getServerPreferencesProperty(cc,
                ServerPreferencesProperties.GOOGLE_API_CLIENT_ID);
        clientEmail = ServerPreferencesProperties.getServerPreferencesProperty(cc,
                ServerPreferencesProperties.GOOGLE_API_SERVICE_ACCOUNT_EMAIL);
    } catch (ODKEntityNotFoundException e) {
        logger.warn("Get service account information error: " + e.getMessage());
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                ErrorConsts.PERSISTENCE_LAYER_PROBLEM + "\n" + e.getMessage());
        return;
    } catch (ODKOverQuotaException e) {
        logger.error("Get service account information error: " + e.getMessage());
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                ErrorConsts.QUOTA_EXCEEDED + "\n" + e.getMessage());
        return;
    }

    PrintWriter out = resp.getWriter();
    out.write(UPLOAD_PAGE_BODY_START);
    out.write(cc.getWebApplicationURL(ADDR));
    out.write(UPLOAD_PAGE_BODY_MIDDLE_B4_API_KEY);
    if (simpleApiKey != null) {
        out.write(StringEscapeUtils.escapeHtml4(simpleApiKey));
    }
    out.write(UPLOAD_PAGE_BODY_MIDDLE_B4_CLIENT_ID);
    if (clientId != null) {
        out.write(StringEscapeUtils.escapeHtml4(clientId));
    }
    out.write(UPLOAD_PAGE_BODY_MIDDLE_B4_CLIENT_EMAIL);
    if (clientEmail != null) {
        out.write(StringEscapeUtils.escapeHtml4(clientEmail));
    }
    out.write(UPLOAD_PAGE_BODY_END);
    finishBasicHtmlResponse(resp);
}

From source file:org.opendatakit.common.utils.HtmlUtil.java

/**
 *
 * @param name/*from   w w w .  j  a  v a  2s .co  m*/
 *          The select name.
 * @param values
 *          A list of pairs [option value, option title (text displayed to
 *          user)] for each option.
 * @return
 */
public static final String createSelect(String name, List<String> values) {
    if (name == null) {
        return null;
    }
    StringBuilder html = new StringBuilder();
    html.append("<select name='" + StringEscapeUtils.escapeHtml4(name) + "'>");

    if (values != null) {
        for (String v : values) {
            html.append("<option value='" + StringEscapeUtils.escapeHtml4(v) + "'>");
            html.append(StringEscapeUtils.escapeHtml4(v));
            html.append("</option>");
        }
    }
    html.append("</select>");
    return html.toString();
}

From source file:org.opendatakit.services.legacy.tasks.InstanceUploaderTask.java

@Override
protected InstanceUploadOutcome doInBackground(String... toUpload) {
    mOutcome = new InstanceUploadOutcome();
    mOutcome.mResults = new HashMap<String, String>();
    mOutcome.mAuthRequestingServer = null;

    PropertiesSingleton props = CommonToolProperties.get(appContext, appName);

    String urlString = null;/*www.  j av  a  2s.co m*/
    urlString = props.getProperty(CommonToolProperties.KEY_SYNC_SERVER_URL);
    urlString = urlString + "/submission";
    URI u = null;
    try {
        URL url = new URL(URLDecoder.decode(urlString, CharEncoding.UTF_8));
        u = url.toURI();
    } catch (MalformedURLException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        mOutcome.mResults.put("unknown", fail + "invalid url: " + urlString + " :: details: " + e.getMessage());
        return mOutcome;
    } catch (URISyntaxException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        mOutcome.mResults.put("unknown", fail + "invalid uri: " + urlString + " :: details: " + e.getMessage());
        return mOutcome;
    } catch (UnsupportedEncodingException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        mOutcome.mResults.put("unknown", fail + "invalid url: " + urlString + " :: details: " + e.getMessage());
        return mOutcome;
    }

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    CookieStore cookieStore = new BasicCookieStore();

    String authType = props.getProperty(CommonToolProperties.KEY_AUTHENTICATION_TYPE);
    if (authType.equals(appContext.getString(R.string.credential_type_username_password))) {
        String username = props.getProperty(CommonToolProperties.KEY_USERNAME);
        String password = props.getProperty(CommonToolProperties.KEY_PASSWORD);
        registerUsernamePassword(credsProvider, username, password, u.getHost());
    } else if (authType.equals(appContext.getString(R.string.credential_type_google_account))) {
        throw new IllegalStateException("legacy doesn't support Google Authentication");
    }

    // context holds authentication state machine, so it cannot be
    // shared across independent activities.
    HttpClientContext localContext = HttpClientContext.create();

    localContext.setCookieStore(cookieStore);
    localContext.setCredentialsProvider(credsProvider);

    CloseableHttpClient httpclient = WebUtils.createHttpClient(WebUtils.CONNECTION_TIMEOUT);

    Map<URI, URI> uriRemap = new HashMap<URI, URI>();

    for (int i = 0; i < toUpload.length; ++i) {
        if (isCancelled()) {
            return mOutcome;
        }
        publishProgress(i + 1, toUpload.length);

        Uri toUpdate = Uri.withAppendedPath(InstanceProviderAPI.CONTENT_URI,
                appName + "/" + uploadTableId + "/" + StringEscapeUtils.escapeHtml4(toUpload[i]));
        Cursor c = null;
        try {
            c = appContext.getContentResolver().query(toUpdate, null, null, null, null);
            if (c.getCount() == 1 && c.moveToFirst()) {

                String id = CursorUtils.getIndexAsString(c, c.getColumnIndex(InstanceColumns._ID));
                String dataTableInstanceId = CursorUtils.getIndexAsString(c,
                        c.getColumnIndex(InstanceColumns.DATA_INSTANCE_ID));
                String lastOutcome = CursorUtils.getIndexAsString(c,
                        c.getColumnIndex(InstanceColumns.XML_PUBLISH_STATUS));
                String submissionInstanceId = LocalizationUtils.genUUID();
                // submissions always get a new legacy instance id UNLESS the last
                // submission failed,
                // in which case we retry the submission using the legacy instance id
                // associated with
                // that failure. This supports resumption of sends of forms with many
                // attachments.
                if (lastOutcome != null && lastOutcome.equals(InstanceColumns.STATUS_SUBMISSION_FAILED)) {
                    String lastId = CursorUtils.getIndexAsString(c,
                            c.getColumnIndex(InstanceColumns.SUBMISSION_INSTANCE_ID));
                    if (lastId != null) {
                        submissionInstanceId = lastId;
                    }
                }
                c.close();

                FileSet instanceFiles;
                try {
                    instanceFiles = constructSubmissionFiles(dataTableInstanceId, submissionInstanceId);
                    // NOTE: /submission must not be translated! It is
                    // the well-known path on the server.

                    if (!uploadOneSubmission(urlString, toUpdate, id, submissionInstanceId, instanceFiles,
                            httpclient, localContext, uriRemap)) {
                        return mOutcome; // get credentials...
                    }
                } catch (JsonParseException e) {
                    WebLogger.getLogger(appName).printStackTrace(e);
                    mOutcome.mResults.put(id, fail + "unable to obtain manifest: " + dataTableInstanceId
                            + " :: details: " + e.toString());
                } catch (JsonMappingException e) {
                    WebLogger.getLogger(appName).printStackTrace(e);
                    mOutcome.mResults.put(id, fail + "unable to obtain manifest: " + dataTableInstanceId
                            + " :: details: " + e.toString());
                } catch (IOException e) {
                    WebLogger.getLogger(appName).printStackTrace(e);
                    mOutcome.mResults.put(id, fail + "unable to obtain manifest: " + dataTableInstanceId
                            + " :: details: " + e.toString());
                }
            } else {
                mOutcome.mResults.put("unknown",
                        fail + "unable to retrieve instance information via: " + toUpdate.toString());
            }
        } finally {
            if (c != null && !c.isClosed()) {
                c.close();
            }
        }
    }

    return mOutcome;
}

From source file:org.opendatakit.survey.activities.MainMenuActivity.java

@Override
public String getUrlLocationHash() {
    if (currentForm == null) {
        // we want framework...
        File frameworkFormDef = new File(ODKFileUtils.getFormFolder(appName, FormsColumns.COMMON_BASE_FORM_ID,
                FormsColumns.COMMON_BASE_FORM_ID), "formDef.json");

        String hashUrl = "#formPath="
                + StringEscapeUtils.escapeHtml4(ODKFileUtils.getRelativeFormPath(appName, frameworkFormDef))
                + ((instanceId == null) ? "" : "&instanceId=" + StringEscapeUtils.escapeHtml4(instanceId))
                + ((getScreenPath() == null) ? ""
                        : "&screenPath=" + StringEscapeUtils.escapeHtml4(getScreenPath()))
                + ("&refId=" + StringEscapeUtils.escapeHtml4(refId))
                + ((auxillaryHash == null) ? "" : "&" + auxillaryHash);
        return hashUrl;
    } else {/*from ww w.  ja  va2s.  com*/
        String hashUrl = "#formPath="
                + StringEscapeUtils.escapeHtml4((currentForm == null) ? "" : currentForm.formPath)
                + ((instanceId == null) ? "" : "&instanceId=" + StringEscapeUtils.escapeHtml4(instanceId))
                + ((getScreenPath() == null) ? ""
                        : "&screenPath=" + StringEscapeUtils.escapeHtml4(getScreenPath()))
                + ("&refId=" + StringEscapeUtils.escapeHtml4(refId))
                + ((auxillaryHash == null) ? "" : "&" + auxillaryHash);

        return hashUrl;
    }
}

From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java

@Override
public String getUrlLocationHash() {
    if (currentForm == null) {
        // we want framework...
        FrameworkFormPathInfo info = getFrameworkFormPathInfo();
        if (info == null) {
            return "";
        }// w  ww . ja  v  a 2s .  co m
        String hashUrl = "#formPath=" + StringEscapeUtils.escapeHtml4(info.relativePath)
                + ((instanceId == null) ? "" : "&instanceId=" + StringEscapeUtils.escapeHtml4(instanceId))
                + ((getScreenPath() == null) ? ""
                        : "&screenPath=" + StringEscapeUtils.escapeHtml4(getScreenPath()))
                + ((refId == null) ? "" : "&refId=" + StringEscapeUtils.escapeHtml4(refId))
                + ((auxillaryHash == null) ? "" : "&" + auxillaryHash);
        return hashUrl;
    } else {
        String hashUrl = "#formPath="
                + StringEscapeUtils.escapeHtml4((currentForm == null) ? "" : currentForm.formPath)
                + ((instanceId == null) ? "" : "&instanceId=" + StringEscapeUtils.escapeHtml4(instanceId))
                + ((getScreenPath() == null) ? ""
                        : "&screenPath=" + StringEscapeUtils.escapeHtml4(getScreenPath()))
                + ((refId == null) ? "" : "&refId=" + StringEscapeUtils.escapeHtml4(refId))
                + ((auxillaryHash == null) ? "" : "&" + auxillaryHash);

        return hashUrl;
    }
}

From source file:org.opendatakit.survey.android.fragments.InstanceUploaderListFragment.java

@Override
public void uploadingComplete(InstanceUploadOutcome outcome) {
    try {//from   w ww  .  ja v  a2s . c o  m
        mDialogState = DialogState.None;
        dismissProgressDialog();
    } catch (Exception e) {
        WebLogger.getLogger(((ODKActivity) getActivity()).getAppName()).printStackTrace(e);
        WebLogger.getLogger(((ODKActivity) getActivity()).getAppName()).i(t,
                "Attempting to close a dialog that was not previously opened");
    }

    BackgroundTaskFragment f = (BackgroundTaskFragment) getFragmentManager().findFragmentByTag("background");
    f.clearUploadInstancesTask();

    if (outcome.mAuthRequestingServer == null && ((ODKActivity) getActivity()).getUploadTableId() != null) {
        StringBuilder message = new StringBuilder();

        Set<String> keys = outcome.mResults.keySet();
        for (String id : keys) {

            Cursor results = null;
            try {
                Uri uri = Uri.withAppendedPath(InstanceProviderAPI.CONTENT_URI,
                        ((ODKActivity) getActivity()).getAppName() + "/"
                                + ((ODKActivity) getActivity()).getUploadTableId() + "/"
                                + StringEscapeUtils.escapeHtml4(id));
                results = getActivity().getContentResolver().query(uri, null, null, null, null);
                if (results.getCount() == 1 && results.moveToFirst()) {
                    String name = ODKDatabaseUtils.get().getIndexAsString(results,
                            results.getColumnIndex(InstanceColumns.DISPLAY_NAME));
                    message.append(name + " - " + outcome.mResults.get(id) + "\n\n");
                }
            } finally {
                if (results != null) {
                    results.close();
                }
            }
        }

        if (message.length() == 0) {
            message.append(getString(R.string.no_forms_uploaded));
        }

        createAlertDialog(getString(R.string.uploading_data), message.toString().trim());
    } else {
        // add our list of completed uploads to "completed"
        // and remove them from our toSend list.
        if (outcome.mResults != null) {
            Set<String> uploadedInstances = outcome.mResults.keySet();
            Iterator<String> itr = uploadedInstances.iterator();

            while (itr.hasNext()) {
                String removeMe = itr.next();
                boolean removed = mSelected.remove(removeMe);
                if (removed) {
                    WebLogger.getLogger(((ODKActivity) getActivity()).getAppName()).i(t,
                            removeMe + " was already sent, removing from queue before restarting task");
                }
            }
        }

        // Bundle b = new Bundle();
        // b.putString(AUTH_URI, url.toString());
        // showDialog(AUTH_DIALOG, b);
        mUrl = outcome.mAuthRequestingServer;
        showAuthDialog();
    }
}

From source file:org.opendatakit.survey.android.tasks.InstanceUploaderTask.java

@Override
protected InstanceUploadOutcome doInBackground(String... toUpload) {
    mOutcome = new InstanceUploadOutcome();
    mOutcome.mResults = new HashMap<String, String>();
    mOutcome.mAuthRequestingServer = null;

    String auth = PropertiesSingleton.getProperty(appName, PreferencesActivity.KEY_AUTH);
    setAuth(auth);/*from   ww w.j  ava  2 s .  c  o m*/

    String urlString = null;

    /**
     * retrieve the URL string for the table, if defined... otherwise, use the
     * app property values to construct it.
     */
    {
        SQLiteDatabase db = null;

        Cursor c = null;
        try {
            db = DatabaseFactory.get().getDatabase(appContext, appName);
            c = db.query(DatabaseConstants.KEY_VALUE_STORE_ACTIVE_TABLE_NAME, null,
                    KeyValueStoreColumns.TABLE_ID + "=? AND " + KeyValueStoreColumns.PARTITION + "=? AND "
                            + KeyValueStoreColumns.ASPECT + "=? AND " + KeyValueStoreColumns.KEY + "=?",
                    new String[] { uploadTableId, KeyValueStoreConstants.PARTITION_TABLE,
                            KeyValueStoreConstants.ASPECT_DEFAULT, KeyValueStoreConstants.XML_SUBMISSION_URL },
                    null, null, null);
            if (c.getCount() == 1) {
                c.moveToFirst();
                int idxValue = c.getColumnIndex(KeyValueStoreColumns.VALUE);
                urlString = c.getString(idxValue);
            } else if (c.getCount() != 0) {
                throw new IllegalStateException(
                        "two or more entries for " + KeyValueStoreConstants.XML_SUBMISSION_URL);
            }
        } finally {
            c.close();
            db.releaseReference();
        }

        if (urlString == null) {
            urlString = PropertiesSingleton.getProperty(appName, PreferencesActivity.KEY_SERVER_URL);
            String submissionUrl = PropertiesSingleton.getProperty(appName,
                    PreferencesActivity.KEY_SUBMISSION_URL);
            urlString = urlString + submissionUrl;
        }
    }

    // FormInfo fi = new FormInfo(appContext, appName,
    // ODKFileUtils.getuploadingForm.formDefFile);
    // get shared HttpContext so that authentication and cookies are
    // retained.
    HttpContext localContext = ClientConnectionManagerFactory.get(appName).getHttpContext();
    HttpClient httpclient = ClientConnectionManagerFactory.get(appName)
            .createHttpClient(WebUtils.CONNECTION_TIMEOUT);

    Map<URI, URI> uriRemap = new HashMap<URI, URI>();

    for (int i = 0; i < toUpload.length; ++i) {
        if (isCancelled()) {
            return mOutcome;
        }
        publishProgress(i + 1, toUpload.length);

        Uri toUpdate = Uri.withAppendedPath(InstanceProviderAPI.CONTENT_URI,
                appName + "/" + uploadTableId + "/" + StringEscapeUtils.escapeHtml4(toUpload[i]));
        Cursor c = null;
        try {
            c = appContext.getContentResolver().query(toUpdate, null, null, null, null);
            if (c.getCount() == 1 && c.moveToFirst()) {

                String id = ODKDatabaseUtils.get().getIndexAsString(c, c.getColumnIndex(InstanceColumns._ID));
                String dataTableInstanceId = ODKDatabaseUtils.get().getIndexAsString(c,
                        c.getColumnIndex(InstanceColumns.DATA_INSTANCE_ID));
                String lastOutcome = ODKDatabaseUtils.get().getIndexAsString(c,
                        c.getColumnIndex(InstanceColumns.XML_PUBLISH_STATUS));
                String submissionInstanceId = ODKDataUtils.genUUID();
                // submissions always get a new legacy instance id UNLESS the last
                // submission failed,
                // in which case we retry the submission using the legacy instance id
                // associated with
                // that failure. This supports resumption of sends of forms with many
                // attachments.
                if (lastOutcome != null && lastOutcome.equals(InstanceColumns.STATUS_SUBMISSION_FAILED)) {
                    String lastId = ODKDatabaseUtils.get().getIndexAsString(c,
                            c.getColumnIndex(InstanceColumns.SUBMISSION_INSTANCE_ID));
                    if (lastId != null) {
                        submissionInstanceId = lastId;
                    }
                }
                c.close();

                FileSet instanceFiles;
                try {
                    instanceFiles = constructSubmissionFiles(dataTableInstanceId, submissionInstanceId);
                    // NOTE: /submission must not be translated! It is
                    // the well-known path on the server.

                    if (!uploadOneSubmission(urlString, toUpdate, id, submissionInstanceId, instanceFiles,
                            httpclient, localContext, uriRemap)) {
                        return mOutcome; // get credentials...
                    }
                } catch (JsonParseException e) {
                    WebLogger.getLogger(appName).printStackTrace(e);
                    mOutcome.mResults.put(id, fail + "unable to obtain manifest: " + dataTableInstanceId
                            + " :: details: " + e.toString());
                } catch (JsonMappingException e) {
                    WebLogger.getLogger(appName).printStackTrace(e);
                    mOutcome.mResults.put(id, fail + "unable to obtain manifest: " + dataTableInstanceId
                            + " :: details: " + e.toString());
                } catch (IOException e) {
                    WebLogger.getLogger(appName).printStackTrace(e);
                    mOutcome.mResults.put(id, fail + "unable to obtain manifest: " + dataTableInstanceId
                            + " :: details: " + e.toString());
                }
            } else {
                mOutcome.mResults.put("unknown",
                        fail + "unable to retrieve instance information via: " + toUpdate.toString());
            }
        } finally {
            if (c != null && !c.isClosed()) {
                c.close();
            }
        }
    }

    return mOutcome;
}