com.google.api.gbase.client.GoogleBaseEntry

Here are the examples of the java api class com.google.api.gbase.client.GoogleBaseEntry taken from open source projects.

1. RecipeDisplayServlet#recipeDisplay()

View license
/**
   * Retrieves a recipe and forwards the request 
   * to the {@link #DISPLAY_JSP} jsp page that displays the recipe.
   *
   * @param request
   * @param response
   * @param service the service used to retrieve the recipe
   * @param id the id of the recipe
   */
private void recipeDisplay(HttpServletRequest request, HttpServletResponse response, GoogleBaseService service, String id) throws ServletException, IOException {
    GoogleBaseEntry entry;
    try {
        URL feedUrl = urlFactory.getSnippetsEntryURL(id);
        entry = service.getEntry(feedUrl, GoogleBaseEntry.class);
    } catch (ServiceException e) {
        RecipeUtil.logServiceException(this, e);
        RecipeUtil.forwardToErrorPage(request, response, e);
        return;
    }
    Recipe recipe = new Recipe(entry);
    request.setAttribute(RecipeUtil.RECIPE_ATTRIBUTE, recipe);
    RecipeSearch results = new RecipeSearch(service, urlFactory, false);
    RecipeUtil.setRecipeSearch(request, results);
    // Forward to the JSP
    request.getRequestDispatcher(DISPLAY_JSP).forward(request, response);
}

2. EventPublisher#publishEventToBase()

View license
/**
   * Publishes an individual event to Base 
   *
   * @param event The <code>Event</code> to publish
   * @throws EPAuthenticationException 
   * @throws IOException 
   * @throws ServiceException
   */
private void publishEventToBase(Event event) throws EPAuthenticationException, IOException, ServiceException {
    GoogleBaseService baseService = getBaseService();
    GoogleBaseEntry entry = null;
    if (event.getBaseUrl() != null) {
        // updating base entry
        entry = baseService.getEntry(event.getBaseUrl(), GoogleBaseEntry.class);
        entry = new GoogleBaseEntry();
    } else {
        // publishing new entry
        entry = new GoogleBaseEntry();
    }
    // prepare an 'events and activities' item for publishing
    GoogleBaseAttributesExtension gbaseAttributes = entry.getGoogleBaseAttributes();
    entry.setTitle(new PlainTextConstruct(event.getTitle()));
    entry.setContent(new PlainTextConstruct(event.getDescription()));
    gbaseAttributes.setItemType("events and activities");
    // this sample currently only demonstrates publishing all-day events
    // an event in Google Base must have a start-time and end-time, so
    // this simulates that by adding 1 day to the end-date specified, if the
    // start and end times are identical
    DateTime startDateTime = new DateTime(event.getStartDate());
    startDateTime.setDateOnly(true);
    DateTime endDateTime = null;
    if (event.getStartDate().equals(event.getEndDate())) {
        Calendar endDateCal = new GregorianCalendar();
        endDateCal.setTime(event.getEndDate());
        endDateCal.add(Calendar.DATE, 1);
        endDateTime = new DateTime(endDateCal.getTime());
    } else {
        endDateTime = new DateTime(event.getEndDate());
    }
    endDateTime.setDateOnly(true);
    gbaseAttributes.addDateTimeRangeAttribute("event date range", new DateTimeRange(startDateTime, endDateTime));
    gbaseAttributes.addTextAttribute("event performer", "Google mashup test");
    gbaseAttributes.addUrlAttribute("performer url", "http://code.google.com/apis/gdata.html");
    if (event.getBaseUrl() != null) {
        // updating event
        baseService.update(event.getBaseUrl(), entry);
    } else {
        // insert event
        GoogleBaseEntry resultEntry = baseService.insert(FeedURLFactory.getDefault().getItemsFeedURL(), entry);
        updateSsEventEditUrl(event.getSsEditUrl(), null, resultEntry.getEditLink().getHref());
    }
}

3. Recipe#toGoogleBaseEntry()

Project: gdata-java-client
Source File: Recipe.java
View license
public GoogleBaseEntry toGoogleBaseEntry(String idUrl) {
    GoogleBaseEntry entry = new GoogleBaseEntry();
    entry.getGoogleBaseAttributes().setItemType(RECIPE_ITEMTYPE);
    if (idUrl != null) {
        entry.setId(idUrl);
    }
    entry.setTitle(TextConstruct.create(TextConstruct.Type.TEXT, title, null));
    if (url != null) {
        entry.addHtmlLink(url, null, null);
    }
    if (description != null) {
        // If the original content was not TEXT, the formatting is lost
        entry.setContent(TextConstruct.create(TextConstruct.Type.TEXT, description, null));
    }
    for (String ingredient : mainIngredient) {
        entry.getGoogleBaseAttributes().addTextAttribute(MAIN_INGREDIENT_ATTRIBUTE, ingredient);
    }
    for (String cuisineItem : cuisine) {
        entry.getGoogleBaseAttributes().addTextAttribute(CUISINE_ATTRIBUTE, cuisineItem);
    }
    if (cookingTime != null) {
        entry.getGoogleBaseAttributes().addIntUnitAttribute(COOKING_TIME_ATTRIBUTE, cookingTime);
    }
    return entry;
}

4. ItemTypesExample#printItemTypeFeed()

View license
/**
   * Prints each itemtype item in the feed to the output.
   * Uses {@link #printItemTypeEntry(GoogleBaseEntry)}.
   *
   * @param feed a Google Base data API itemtypes feed
   */
private static void printItemTypeFeed(GoogleBaseFeed feed) {
    if (feed.getTotalResults() == 0) {
        System.out.println("No matches.");
        return;
    }
    for (GoogleBaseEntry entry : feed.getEntries()) {
        printItemTypeEntry(entry);
    }
}

5. MetadataExample#printMetadataFeed()

View license
/**
   * Prints each metadata item in the feed to the output.
   * Uses {@link #printMetadataEntry(GoogleBaseEntry)}.
   *
   * @param feed a Google Base data API metadata feed
   */
private static void printMetadataFeed(GoogleBaseFeed feed) {
    if (feed.getTotalResults() == 0) {
        System.out.println("No matches.");
        return;
    }
    for (GoogleBaseEntry entry : feed.getEntries()) {
        printMetadataEntry(entry);
    }
}

6. RecipeActionServlet#recipeAdd()

View license
/**
   * Inserts a recipe using the specified authenticated service.
   * 
   * @param service an authenticated GoogleBaseService
   * @param recipe recipe to be inserted
   * @throws IOException
   * @throws ServiceException
   */
protected void recipeAdd(GoogleBaseService service, Recipe recipe) throws IOException, ServiceException {
    URL feedUrl = urlFactory.getItemsFeedURL();
    GoogleBaseEntry entry = recipe.toGoogleBaseEntry(null);
    service.insert(feedUrl, entry);
}

7. RecipeActionServlet#recipeUpdate()

View license
/**
   * Updates a recipe using the specified authenticated service.
   * 
   * The recipe must have a valid GoogleBase id.
   * 
   * @param service an authenticted GoogleBaseService
   * @param recipe recipe to be updated
   * @throws ServiceException
   * @throws IOException
   */
protected void recipeUpdate(GoogleBaseService service, Recipe recipe) throws ServiceException, IOException {
    URL feedUrl = urlFactory.getItemsEntryURL(recipe.getId());
    GoogleBaseEntry entry = recipe.toGoogleBaseEntry(feedUrl.toString());
    service.update(feedUrl, entry);
}

8. RecipeSearch#runQuery()

Project: gdata-java-client
Source File: RecipeSearch.java
View license
/** Runs the query and fills the result. */
public void runQuery() throws IOException, ServiceException {
    GoogleBaseQuery query = createQuery();
    System.out.println("Searching: " + query.getUrl());
    GoogleBaseFeed feed = service.query(query);
    List<Recipe> result = new ArrayList<Recipe>(maxResults);
    for (GoogleBaseEntry entry : feed.getEntries()) {
        result.add(new Recipe(entry));
    }
    this.recipes = result;
    total = feed.getTotalResults();
}