/** * Executes a POST request. * * @param url url of resource. * @param content content to be posted. * @param connectTimeout connection timeout in milliseconds. * @param readTimeout read timeout in milliseconds. * @return {@link Post} object. */ public static Post post(String url, byte[] content, int connectTimeout, int readTimeout) { try { return new Post(url, content, connectTimeout, readTimeout); } catch (Exception e) { throw new HttpException("Failed URL: " + url, e); } }
private Post currentPost = new Post(); StringBuffer chars = new StringBuffer(); if (localName.equalsIgnoreCase("title") && currentPost.getTitle() == null && isItem == true) { currentPost.setTitle(chars.toString()); System.out.println("title1: " + currentPost.getTitle()); if (localName.equalsIgnoreCase("category") && currentPost.getCategory() == null) { currentPost.setCategory(chars.toString()); System.out.println("category: " + currentPost.getCategory()); if (localName.equalsIgnoreCase("description") && currentPost.getDescription() == null) { currentPost.setDescription(chars.toString()); if (localName.equalsIgnoreCase("link") && currentPost.getLink() == null) { currentPost.setLink(chars.toString()); System.out.println("link: " + currentPost.getLink()); if (localName.equalsIgnoreCase("pubDate") && currentPost.getPubDate() == null) { currentPost.setPubDate(chars.toString()); String x = currentPost.getPubDate(); String last = x.substring(0, x.length() - 4); int start = last.length() - 8; currentPost = new Post();
@PostConstruct private void initDatabase(){ authorRepository.deleteAll(); Author dv = new Author(); dv.setFirstName("Dan"); dv.setLastName("Vega"); dv.setEmail("danvega@gmail.com"); authorRepository.save( dv ); postRepository.deleteAll(); Post post = new Post(); post.setTitle("Spring Data Rocks!"); post.setSlug("spring-data-rocks"); post.setTeaser("Post Teaser"); post.setBody("Post Body"); post.setPostedOn(new Date()); post.setAuthor(dv); postRepository.save(post); // add the code below dv.posts = new ArrayList<Post>(); dv.posts.add(post); authorRepository.save( dv ); }
for (int j =0; j<ar.length(); j++){ JSONObject obj = ar.getJSONObject(j); Post post = new Post(); post.setId(obj.getInt("id")); post.setTitle(obj.getString("title")); post.setContent(obj.getString("content")); post.setCreated_at(obj.getString("created_at")); post.setUrl_image(obj.getString("url_image")); postList.add(post);
// Crete and populate our Post Post newPost = new Post(); newPost.setUsername("XXX"); newPost.setLink("xxx"); newPost.setDate("xxx"); // Display the post. postContainer.add(newPost);
Post post = new Post(); post.setTitle(title); post.setContent(content); Update updateAction = getBlog().posts().update(BLOG_ID, POST_ID, post); updateAction.setFields("author/displayName,content,published,title,url"); post = updateAction.execute(); System.out.println("Published: " + post.getPublished());
private void writeNewPost(String userId, String username, String title, String body) { String key = mDatabase.child("posts").push().getKey(); Post post = new Post(userId, username, title, body); Map<String, Object> postValues = post.toMap(); Map<String, Object> childUpdates = new HashMap<>(); childUpdates.put("/posts/" + key, postValues); childUpdates.put("/user-posts/" + userId + "/" + key, postValues); mDatabase.updateChildren(childUpdates); }
Elements aElements = doc.select("a"); Elements bElements = doc.select("b"); // This 'if-else' block is optional if( aElements.size() != bElements.size() ) { // Error handling - if required } else { // Iterate over all elements for( int i = 0; i < aElements.size(); i++ ) { Post p = new Post(); // Create a Post p.setA(aElements.get(i).text()); // Set A Value p.setB(bElements.get(i).text()); // Set B Value PostList.add(p); // Add the Post to List } }
Post p = new Post(1); StringBuilder query = new StringBuilder(256); query.append("select "); query.append(session.buildSelect(Post.class, "p")); query.append(", "); query.append(session.buildSelect(User.class, "u")); query.append(" from Posts p join Users u on p.user_id = u.id"); query.append(" where p.id = ?"); stmt = conn.prepareStatement(query.toString()); stmt.setInt(1, p.getId()); rset = stmt.executeQuery(); if (rset.next()) { session.populateBean(rset, p, "p"); u = new User(); session.populateBean(rset, u, "u"); p.setUser(u); }
@Override public void onResponse(String response) { Gson gson = new Gson(); Post object = new Post(); object.setResponse(response); String gson = gson.fromJson(object, Post.class);//as you have overrided toString() it will return you the response you have set System.out.println(gson); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // Handle error } }
//optionally use the com.google.gson.Gson package Gson gson = new Gson(); ArrayList<Post> yourList = new ArrayList<Post>(); String jsonString = "your string"; JSONArray jsonArray = new JSONArray(jsonString); for (int i = 0; i < jsonArray.length(); i++){ Post post = new Post(); //manually parse for all 5 fields, here's an example for message post.setMessage(jsonArray.get(i).getString("message")); //OR using gson...something like this should work //post = gson.fromJson(jsonArray.get(i),Post.class); yourList.Add(post); }
//add this line in you controller static play.data.Form<Model> modelForm = form(Model.class); public static Result addPostSave(){ try{ MultipartFormData body = request().body().asMultipartFormData(); FilePart picture = body.getFile("picture"); File pic = picture.getFile(); if(filledForm.hasErrors()){ return ok(addPost.render(postForm)); }else{ Post post = new Post(); post.picture = pic; post.save(); return ok(index.render("The image is created")); } }catch(IOException e){ return ok(e.to_string) } }
public class PostManager { private List<Post> postList = new ArrayList<Post>(); private static PostManager instance = new PostManager(); private PostManager (){} public static PostManager getInstance(){ return instance; } public List<Post> getPostList(){ return postList; } public static void addPost() { PostManager.getInstance().add(new Post()); } public static Post getPostByUsername(String author) { for (Post p: PostManager.getInstance().getPostList()) if ((p.getUsername() == null && author == null) || (p.getUsername() != null && p.getUsername().equals(author))) return p; return null; } }
Post post = new Post(key,value); final Map<String, Object> postValues = post.toMapBodyStyle(); ref.child("Name").setValue(postValues).addOnSuccessListener(new OnSuccessListener<Void>() { @Override