com.backendless.messaging.PublishOptions Maven / Gradle / Ivy
Show all versions of commons Show documentation
/*
* ********************************************************************************************************************
*
* BACKENDLESS.COM CONFIDENTIAL
*
* ********************************************************************************************************************
*
* Copyright 2012 BACKENDLESS.COM. All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains the property of Backendless.com and its suppliers,
* if any. The intellectual and technical concepts contained herein are proprietary to Backendless.com and its
* suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret
* or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden
* unless prior written permission is obtained from Backendless.com.
*
* ********************************************************************************************************************
*/
package com.backendless.messaging;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
/**
* Instance of PublishOptions class may contain publisher ID (an arbitrary, application-specific string value
* identifying the publisher), subtopic value and/or a collection of headers.
*
* Headers are used for sending push notification for various devices, i.e. message to send as push to Android device
* must include ANDROID_TICKER_TEXT_TAG, ANDROID_CONTENT_TITLE_TAG, ANDROID_CONTENT_TEXT_TAG headers.
*
* @see Publish Push Notifications
*/
public class PublishOptions
{
private String publisherId;
private Map headers = new HashMap<>();
private Map templateValues;
private String subtopic;
public final static String TEMPLATE_NAME = "template_name";
public final static String ANDROID_IMMEDIATE_PUSH = "android_immediate_push";
public final static String IOS_IMMEDIATE_PUSH = "ios_immediate_push";
public final static String INLINE_REPLY = "inline_reply";
public static final String NOTIFICATION_ID = "notificationId";
public static final String MESSAGE_ID = "messageId";
public final static String MESSAGE_TAG = "message";
public final static String IOS_ALERT_TAG = "ios-alert";
public final static String IOS_BADGE_TAG = "ios-badge";
public final static String IOS_SOUND_TAG = "ios-sound";
public final static String IOS_TITLE_TAG = "ios-alert-title";
public final static String IOS_SUBTITLE_TAG = "ios-alert-subtitle";
public final static String IOS_RICH_MEDIA_URL_TAG = "ios-rich-media-url";
public final static String OSX_TITLE_TAG = "osx-alert-title";
public final static String OSX_SUBTITLE_TAG = "osx-alert-subtitle";
public final static String ANDROID_TICKER_TEXT_TAG = "android-ticker-text";
public final static String ANDROID_CONTENT_TITLE_TAG = "android-content-title";
public final static String ANDROID_CONTENT_TEXT_TAG = "android-content-text";
public final static String ANDROID_ACTION_TAG = "android-action";
public final static String ANDROID_BADGE_TAG = "android-badge";
public final static String ANDROID_SUMMARY_SUBTEXT_TAG = "android-summary-subtext";
public final static String ANDROID_CONTENT_SOUND_TAG = "android-content-sound";
public final static String ANDROID_LARGE_ICON_TAG = "android-large-icon";
public final static String ANDROID_ATTACHMENT_URL_TAG = "android-attachment-url";
private final static Set androidHeaders = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( ANDROID_IMMEDIATE_PUSH, ANDROID_TICKER_TEXT_TAG, ANDROID_CONTENT_TITLE_TAG, ANDROID_CONTENT_TEXT_TAG, ANDROID_ACTION_TAG, ANDROID_BADGE_TAG, ANDROID_SUMMARY_SUBTEXT_TAG, ANDROID_CONTENT_SOUND_TAG, ANDROID_LARGE_ICON_TAG, ANDROID_ATTACHMENT_URL_TAG ) ) );
private final static Set iosHeaders = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( IOS_IMMEDIATE_PUSH, IOS_ALERT_TAG, IOS_BADGE_TAG, IOS_SOUND_TAG, IOS_TITLE_TAG, IOS_SUBTITLE_TAG, IOS_RICH_MEDIA_URL_TAG ) ) );
private final static Set osxHeaders = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( OSX_TITLE_TAG, OSX_SUBTITLE_TAG ) ) );
public static Set getAndroidHeaders()
{
return androidHeaders;
}
public static Set getIOSHeaders()
{
return iosHeaders;
}
public static Set getOSXHeaders()
{
return osxHeaders;
}
public PublishOptions()
{
}
public PublishOptions( String publisherId )
{
this.publisherId = publisherId;
}
public PublishOptions( String publisherId, String subtopic )
{
this.publisherId = publisherId;
this.subtopic = subtopic;
}
public PublishOptions( String publisherId, Hashtable headers, String subtopic )
{
this.publisherId = publisherId;
this.headers.putAll( headers );
this.subtopic = subtopic;
}
public PublishOptions( PublishMessageInfo info )
{
this.publisherId = info.getPublisherId();
if( info.getHeaders() != null )
this.headers.putAll( info.getHeaders() );
this.templateValues = info.getTemplateValues();
this.subtopic = info.getSubtopic();
}
public String getPublisherId()
{
return publisherId;
}
public void setPublisherId( String publisherId )
{
this.publisherId = publisherId;
}
public Map getHeaders()
{
if( headers == null )
return headers = new HashMap<>();
return new HashMap<>( headers );
}
public void setHeaders( Map headers )
{
this.headers = headers;
}
public void putHeader( String headerKey, String headerValue )
{
if( headerKey == null || headerKey.isEmpty() || headerValue == null )
return;
if( headers == null )
headers = new HashMap<>();
headers.put( headerKey, headerValue );
}
public Map getTemplateValues()
{
return templateValues;
}
public void setTemplateValues( Map templateValues )
{
this.templateValues = templateValues;
}
public String getSubtopic()
{
return subtopic;
}
public void setSubtopic( String subtopic )
{
this.subtopic = subtopic;
}
}