Example usage for java.lang String toString

List of usage examples for java.lang String toString

Introduction

In this page you can find the example usage for java.lang String toString.

Prototype

public String toString() 

Source Link

Document

This object (which is already a string!) is itself returned.

Usage

From source file:com.redhat.rhn.manager.kickstart.KickstartUrlHelper.java

/**
 * Get the --url parameter for this kickstart that is used
 * during a Kickstart Session that tracks the downloads.
 *
 * eg: http://spacewalk.example.com/ks/dist/session/
 *                35x45fed383beaeb31a184166b4c1040633/ks-f9-x86_64
 * @param session to compute tracking URL for.
 *
 * @return String url to this KickstartData's media (packages, kernel
 * etc...)//w ww. ja v  a  2  s. c  o m
 */
public String getKickstartMediaSessionUrl(KickstartSession session) {
    log.debug("Formatting for session use.");
    // /ks/dist/session/
    // 94xe86321bae3cb74551d995e5eafa065c0/ks-rhel-i386-as-4-u2
    String file = getLongMediaPath(session);
    TinyUrl turl = CommonFactory.createTinyUrl(file.toString(), new Date());
    CommonFactory.saveTinyUrl(turl);
    log.debug("returning: " + turl.computeTinyUrl(this.host));
    return turl.computeTinyUrl(this.host);
}

From source file:edu.ku.brc.af.ui.forms.validation.TypeSearchForQueryFactory.java

/**
 * Saves an Discipline level XML document to a Database Resource.
 * @param resName the name of the resource
 * @param xml the XML to be saved./*from   w  w  w.  j av a 2  s .  c  o m*/
 */
public void saveResource(final String resName, final String xml) {
    // Default implementation is to disk
    writeToFile(xml.toString());
}

From source file:africastalkinggateway.AfricasTalkingGateway.java

public JSONObject createSubscription(String phoneNumber_, String shortCode_, String keyword_) throws Exception {
    if (phoneNumber_.length() == 0 || shortCode_.length() == 0 || keyword_.length() == 0)
        throw new Exception("Please supply phoneNumber, shortCode and keyword");

    HashMap<String, String> data_ = new HashMap<String, String>();
    data_.put("username", _username);
    data_.put("phoneNumber", phoneNumber_);
    data_.put("shortCode", shortCode_);
    data_.put("keyword", keyword_);
    String requestUrl = SUBSCRIPTION_URL + "/create";

    String response = sendPOSTRequest(data_, requestUrl);

    if (responseCode != HTTP_CODE_CREATED)
        throw new Exception(response.toString());

    JSONObject jsObject = new JSONObject(response);
    return jsObject;
}

From source file:africastalkinggateway.AfricasTalkingGateway.java

public JSONObject deleteSubscription(String phoneNumber_, String shortCode_, String keyword_) throws Exception {
    if (phoneNumber_.length() == 0 || shortCode_.length() == 0 || keyword_.length() == 0)
        throw new Exception("Please supply phone number, short code and keyword");

    HashMap<String, String> data_ = new HashMap<String, String>();
    data_.put("username", _username);
    data_.put("phoneNumber", phoneNumber_);
    data_.put("shortCode", shortCode_);
    data_.put("keyword", keyword_);
    String requestUrl = SUBSCRIPTION_URL + "/delete";

    String response = sendPOSTRequest(data_, requestUrl);

    if (responseCode != HTTP_CODE_CREATED)
        throw new Exception(response.toString());

    JSONObject jsObject = new JSONObject(response);
    return jsObject;
}

From source file:org.craftercms.security.authentication.impl.RestLoginSuccessHandlerTest.java

@Test
public void testHandle() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/login.json");
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response);

    String ticket = UUID.randomUUID().toString();
    ObjectId profileId = new ObjectId();

    Profile profile = new Profile();
    profile.setId(profileId);//  w ww  .  j av  a2 s  . com
    profile.setUsername("jdoe");
    profile.setPassword("1234");
    profile.setEmail("jdoe@craftercms.org");

    Authentication auth = new DefaultAuthentication(ticket.toString(), profile);

    handler.handle(context, auth);

    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    assertEquals(
            "{\"ticket\":\"" + ticket + "\",\"profile\":{\"username\":\"jdoe\","
                    + "\"password\":\"1234\",\"email\":\"jdoe@craftercms.org\",\"verified\":false,"
                    + "\"enabled\":false,\"createdOn\":null,\"lastModified\":null,\"tenant\":null,\"roles\":[],"
                    + "\"attributes\":{},\"id\":\"" + profileId.toString() + "\"},\"remembered\":false}",
            response.getContentAsString());
}

From source file:edu.scripps.fl.pubchem.web.entrez.EUtilsWebSession.java

private MultipartEntity addParts(MultipartEntity entity, Collection<Object> pairs)
        throws UnsupportedEncodingException {
    Iterator<Object> iter = pairs.iterator();
    while (iter.hasNext()) {
        String name = iter.next().toString();
        String key = iter.hasNext() ? iter.next().toString() : "";
        entity.addPart(name, new StringBody(key.toString()));
    }/*from   w w  w  . j av a 2  s .c  o m*/
    return entity;
}

From source file:org.syncany.connection.plugins.webdav.WebdavTransferManager.java

@Override
public <T extends RemoteFile> Map<String, T> list(Class<T> remoteFileClass) throws StorageException {
    connect();/*from w  w w .  j  a  v  a  2  s. co m*/

    try {
        // List folder
        String remoteFileUrl = getRemoteFilePath(remoteFileClass);
        logger.log(Level.INFO, "WebDAV: Listing objects in " + remoteFileUrl + " ...");

        List<DavResource> resources = sardine.list(remoteFileUrl);

        // Create RemoteFile objects
        String rootPath = repoPath.substring(0, repoPath.length() - new URI(repoPath).getRawPath().length());
        Map<String, T> remoteFiles = new HashMap<String, T>();

        for (DavResource res : resources) {
            // WebDAV returns the parent resource itself; ignore it
            String fullResourceUrl = rootPath + res.getPath().replaceAll("/$", "") + "/";
            boolean isParentResource = remoteFileUrl.equals(fullResourceUrl.toString());

            if (!isParentResource) {
                try {
                    T remoteFile = RemoteFile.createRemoteFile(res.getName(), remoteFileClass);
                    remoteFiles.put(res.getName(), remoteFile);

                    logger.log(Level.FINE, "WebDAV: Matching WebDAV resource: " + res);
                } catch (Exception e) {
                    logger.log(Level.FINEST,
                            "Cannot create instance of " + remoteFileClass.getSimpleName() + " for object "
                                    + res.getName() + "; maybe invalid file name pattern. Ignoring file.");
                }
            }
        }

        return remoteFiles;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "WebDAV: Unable to list WebDAV directory.", ex);
        throw new StorageException(ex);
    }
}

From source file:com.azure.webapi.MobileServiceTableBase.java

protected void initialize(String name, MobileServiceClient client) {
    if (name == null || name.toString().trim().length() == 0) {
        throw new IllegalArgumentException("Invalid Table Name");
    }//  ww  w.  j  av a2  s .  c  om

    if (client == null) {
        throw new IllegalArgumentException("Invalid Mobile Service Client");
    }

    mClient = client;
    mTableName = name;
}

From source file:com.kloudtek.kloudmake.service.filestore.FileStore.java

/**
 * This function is used to generate an url to a file contained in a library. This is generally used to generate
 * an url to be passed as a 'source' attribute to a 'core.file' resource. For example:
 * <code>core.file { path = "/etc/tomcat/server.xml" , source = lfile('tomcat6.xml.ftl') }</code>
 *
 * @param path     Path to the file.// w  w w. ja  v  a  2s  .  c  o  m
 * @param encoding encoding
 * @return file url.
 */
@Function("lfile")
public String createLibraryFileUrl(@Param("path") String path,
        @Param("encoding") @Default("UTF-8") String encoding) {
    if (!path.startsWith("/")) {
        String sourceUrl = KMContextImpl.get().getSourceUrl();
        if (sourceUrl != null) {
            String urlStr = sourceUrl.toString();
            int idx = urlStr.lastIndexOf('/');
            if (idx == -1) {
                throw new IllegalArgumentException("Invalid source path (no '/' found): " + path);
            }
            path = urlStr.substring(0, idx + 1) + path;
        }
    }
    return "libfile:" + path;
}

From source file:com.ericsson.eiffel.remrem.publish.service.EventTemplateHandler.java

public JsonNode eventTemplateParser(String jsonData, String eventName) {
    JsonNode updatedJson = null;//from w  ww  .  j a v a 2s. c  om
    JsonFactory factory = new JsonFactory();
    ObjectMapper mapper = new ObjectMapper(factory);
    JsonNode rootNode = null;
    try {
        String eventTemplate = accessFileInSemanticJar(EVENT_TEMPLATE_PATH + eventName.toLowerCase() + ".json");

        rootNode = mapper.readTree(jsonData);
        updatedJson = mapper.readValue(eventTemplate, JsonNode.class);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }

    // For each key/value pair for parsing to template
    Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
    while (fieldsIterator.hasNext()) {
        Map.Entry<String, JsonNode> field = fieldsIterator.next();
        // Parse values to template
        // Check if POJO required for update in event template
        Pattern p = Pattern.compile(REGEXP_END_DIGITS); // if ends with [d+]
        Matcher m = p.matcher(field.getKey());

        String myKey = "$." + templateParamHandler(field.getKey());

        if (field.getValue().toString().equals("\"<%DELETE%>\"")) {
            updatedJson = jsonPathHandlerDelete(updatedJson, myKey);
        } else if (m.find()) {
            String myValue = field.getValue().toString();
            try {
                // Fetch Class name in Event Schema
                String eventSchema = accessFileInSemanticJar(EVENT_SCHEMA_PATH + eventName + ".json");
                // Filter javatype from Event Schema = class name
                JsonNode jsonFromSchema = JsonPath.using(configuration).parse(eventSchema.toString())
                        .read(schemaClassPathHandler(field.getKey().replaceAll(REGEXP_END_DIGITS, "")));
                String myClassName = jsonFromSchema.toString().replace("[", "").replace("]", "").replace("\"",
                        ""); // Ex ["com.ericsson.eiffel.semantics.events.PersistentLog"] to com.ericsson.eiffel.semantics.events.PersistentLog
                // Initiate Class via reflection and map values - POJO
                Class myClass = Class.forName(myClassName);
                Object mapped2Pojo = mapper.readValue(myValue, myClass);
                updatedJson = jsonPathHandlerSet(updatedJson, myKey, mapped2Pojo);
            } catch (ClassNotFoundException e) {
                // No POJO required for adding new item in Array (ie no key/value pairs)
                updatedJson = jsonPathHandlerSet(updatedJson, myKey, myValue.toString().replace("\"", ""));
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }

        } else { // No POJO needed for update
            Object myValue = field.getValue();
            updatedJson = jsonPathHandlerSet(updatedJson, myKey, myValue);
        }
    } // while
    return updatedJson;
}