001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.language.LanguageUtil;
020    import com.liferay.portal.kernel.servlet.HttpHeaders;
021    import com.liferay.portal.kernel.util.Constants;
022    import com.liferay.portal.kernel.util.LocaleUtil;
023    import com.liferay.portal.kernel.util.Validator;
024    import com.liferay.portal.kernel.workflow.WorkflowConstants;
025    import com.liferay.portal.model.PortletPreferencesIds;
026    
027    import java.io.Serializable;
028    
029    import java.util.Date;
030    import java.util.LinkedHashMap;
031    import java.util.Locale;
032    import java.util.Map;
033    
034    /**
035     * Contains context information about a given API call.
036     *
037     * <p>
038     * The <code>ServiceContext</code> object simplifies method signatures and
039     * provides a way to consolidate many different methods with different sets of
040     * optional parameters into a single, easier to use method. It also aggregates
041     * information necessary for transversal features such as permissioning,
042     * tagging, categorization, etc.
043     * </p>
044     *
045     * @author Raymond Augé
046     * @author Brian Wing Shun Chan
047     * @author Jorge Ferrer
048     */
049    public class ServiceContext implements Cloneable, Serializable {
050    
051            /**
052             * Creates a new service context object with an attributes map and an
053             * expando bridge attributes map. The attributes map contains standard
054             * service context parameters and the expando bridge attributes map contains
055             * optional service context parameters.
056             */
057            public ServiceContext() {
058                    _attributes = new LinkedHashMap<String, Serializable>();
059                    _expandoBridgeAttributes = new LinkedHashMap<String, Serializable>();
060            }
061    
062            /**
063             * Returns a new service context object identical to this service context
064             * object.
065             *
066             * @return a new service context object
067             */
068            @Override
069            public Object clone() {
070                    ServiceContext serviceContext = new ServiceContext();
071    
072                    serviceContext.setAddGroupPermissions(getAddGroupPermissions());
073                    serviceContext.setAddGuestPermissions(getAddGuestPermissions());
074                    serviceContext.setAssetCategoryIds(getAssetCategoryIds());
075                    serviceContext.setAssetEntryVisible(isAssetEntryVisible());
076                    serviceContext.setAssetLinkEntryIds(getAssetLinkEntryIds());
077                    serviceContext.setAssetTagNames(getAssetTagNames());
078                    serviceContext.setAttributes(getAttributes());
079                    serviceContext.setCommand(getCommand());
080                    serviceContext.setCompanyId(getCompanyId());
081                    serviceContext.setCreateDate(getCreateDate());
082                    serviceContext.setCurrentURL(getCurrentURL());
083                    serviceContext.setExpandoBridgeAttributes(getExpandoBridgeAttributes());
084                    serviceContext.setGroupPermissions(getGroupPermissions());
085                    serviceContext.setGuestPermissions(getGuestPermissions());
086                    serviceContext.setHeaders(getHeaders());
087                    serviceContext.setIndexingEnabled(isIndexingEnabled());
088                    serviceContext.setLanguageId(getLanguageId());
089                    serviceContext.setLayoutFullURL(getLayoutFullURL());
090                    serviceContext.setLayoutURL(getLayoutURL());
091                    serviceContext.setModifiedDate(getModifiedDate());
092                    serviceContext.setPathMain(getPathMain());
093                    serviceContext.setPlid(getPlid());
094                    serviceContext.setPortalURL(getPortalURL());
095                    serviceContext.setPortletPreferencesIds(getPortletPreferencesIds());
096                    serviceContext.setRemoteAddr(getRemoteAddr());
097                    serviceContext.setRemoteHost(getRemoteHost());
098                    serviceContext.setScopeGroupId(getScopeGroupId());
099                    serviceContext.setSignedIn(isSignedIn());
100                    serviceContext.setUserDisplayURL(getUserDisplayURL());
101                    serviceContext.setUserId(getUserId());
102                    serviceContext.setUuid(getUuid());
103                    serviceContext.setWorkflowAction(getWorkflowAction());
104    
105                    return serviceContext;
106            }
107    
108            /**
109             * Returns <code>true</code> if this service context is being passed as a
110             * parameter to a method which manipulates a resource to which default group
111             * permissions apply.
112             *
113             * @return     <code>true</code> if this service context is being passed as
114             *             a parameter to a method which manipulates a resource to which
115             *             default community permissions apply; <code>false</code>
116             *             otherwise
117             * @deprecated As of 6.1, renamed to {@link #getAddGroupPermissions()}
118             */
119            public boolean getAddCommunityPermissions() {
120                    return getAddGroupPermissions();
121            }
122    
123            /**
124             * Returns <code>true</code> if this service context is being passed as a
125             * parameter to a method which manipulates a resource to which default guest
126             * permissions apply.
127             *
128             * @return <code>true</code> if this service context is being passed as a
129             *         parameter to a method which manipulates a resource to which
130             *         default guest permissions apply; <code>false</code> otherwise
131             */
132            public boolean getAddGuestPermissions() {
133                    return _addGuestPermissions;
134            }
135    
136            /**
137             * Returns <code>true</code> if this service context is being passed as a
138             * parameter to a method which manipulates a resource to which default group
139             * permissions apply.
140             *
141             * @return <code>true</code> if this service context is being passed as a
142             *         parameter to a method which manipulates a resource to which
143             *         default group permissions apply; <code>false</code> otherwise
144             */
145            public boolean getAddGroupPermissions() {
146                    return _addGroupPermissions;
147            }
148    
149            /**
150             * Returns the asset category IDs to be applied to an asset entry if the
151             * service context is being passed as a parameter to a method which
152             * manipulates the asset entry.
153             *
154             * @return the asset category IDs
155             */
156            public long[] getAssetCategoryIds() {
157                    return _assetCategoryIds;
158            }
159    
160            /**
161             * Returns the primary keys of the asset entries linked to an asset entry if
162             * the service context is being passed as a parameter to a method which
163             * manipulates the asset entry.
164             *
165             * @return the primary keys of the asset entries
166             */
167            public long[] getAssetLinkEntryIds() {
168                    return _assetLinkEntryIds;
169            }
170    
171            /**
172             * Returns the asset tag names to be applied to an asset entry if the
173             * service context is being passed as a parameter to a method which
174             * manipulates the asset entry.
175             *
176             * @return the asset tag names
177             */
178            public String[] getAssetTagNames() {
179                    return _assetTagNames;
180            }
181    
182            /**
183             * Returns the serializable object associated with the name of the standard
184             * parameter of this service context.
185             *
186             * @param  name the name of the standard parameter
187             * @return the serializable object associated with the name
188             */
189            public Serializable getAttribute(String name) {
190                    return _attributes.get(name);
191            }
192    
193            /**
194             * Returns the map of name/value pairs that are the standard parameters of
195             * this service context. Each value is serializable.
196             *
197             * @return the map of name/value pairs
198             */
199            public Map<String, Serializable> getAttributes() {
200                    return _attributes;
201            }
202    
203            /**
204             * Returns the value of the {@link
205             * com.liferay.portal.kernel.util.Constants#CMD} parameter used in most
206             * Liferay forms for internal portlets.
207             *
208             * @return the value of the command parameter
209             */
210            public String getCommand() {
211                    return _command;
212            }
213    
214            /**
215             * Returns the specific community permissions for a resource if the service
216             * context is being passed as a parameter to a method which manipulates the
217             * resource.
218             *
219             * @return     the community permissions
220             * @deprecated As of 6.1, renamed to {@link #getGroupPermissions()}
221             */
222            public String[] getCommunityPermissions() {
223                    return getGroupPermissions();
224            }
225    
226            /**
227             * Returns the company ID of this service context's current portal instance.
228             *
229             * @return the company ID
230             */
231            public long getCompanyId() {
232                    return _companyId;
233            }
234    
235            /**
236             * Returns the date when an entity was created if this service context is
237             * being passed as a parameter to a method which creates an entity.
238             *
239             * @return the creation date
240             */
241            public Date getCreateDate() {
242                    return _createDate;
243            }
244    
245            /**
246             * Returns the date when an entity was created (or a default date) if this
247             * service context is being passed as a parameter to a method which creates
248             * an entity.
249             *
250             * @param  defaultCreateDate an optional default create date to use if the
251             *         service context does not have a create date
252             * @return the creation date if available; the default date otherwise
253             */
254            public Date getCreateDate(Date defaultCreateDate) {
255                    if (_createDate != null) {
256                            return _createDate;
257                    }
258                    else if (defaultCreateDate != null) {
259                            return defaultCreateDate;
260                    }
261                    else {
262                            return new Date();
263                    }
264            }
265    
266            /**
267             * Returns the current URL of this service context
268             *
269             * @return the current URL
270             */
271            public String getCurrentURL() {
272                    return _currentURL;
273            }
274    
275            /**
276             * Returns an arbitrary number of attributes of an entity to be persisted.
277             *
278             * <p>
279             * These attributes only include fields that this service context does not
280             * possess by default.
281             * </p>
282             *
283             * @return the expando bridge attributes
284             */
285            public Map<String, Serializable> getExpandoBridgeAttributes() {
286                    return _expandoBridgeAttributes;
287            }
288    
289            /**
290             * Returns the specific group permissions for a resource if this service
291             * context is being passed as a parameter to a method which manipulates the
292             * resource.
293             *
294             * @return the specific group permissions
295             */
296            public String[] getGroupPermissions() {
297                    return _groupPermissions;
298            }
299    
300            /**
301             * Returns this service context's user ID or guest ID if no user ID is
302             * available.
303             *
304             * @return the user ID, or guest ID if there is no user in this service
305             *         context, or <code>0</code> if there is no company in this service
306             *         context
307             * @throws PortalException if a default user for the company could not be
308             *         found
309             * @throws SystemException if a system exception occurred
310             */
311            public long getGuestOrUserId() throws PortalException, SystemException {
312                    long userId = getUserId();
313    
314                    if (userId > 0) {
315                            return userId;
316                    }
317    
318                    long companyId = getCompanyId();
319    
320                    if (companyId > 0) {
321                            return UserLocalServiceUtil.getDefaultUserId(getCompanyId());
322                    }
323    
324                    return 0;
325            }
326    
327            /**
328             * Returns the specific guest permissions for a resource if this service
329             * context is being passed as a parameter to a method which manipulates the
330             * resource.
331             *
332             * @return the specific guest permissions
333             */
334            public String[] getGuestPermissions() {
335                    return _guestPermissions;
336            }
337    
338            /**
339             * Returns the the map of request header name/value pairs of this service
340             * context.
341             *
342             * @return the the map of request header name/value pairs
343             * @see    com.liferay.portal.kernel.servlet.HttpHeaders
344             */
345            public Map<String, String> getHeaders() {
346                    return _headers;
347            }
348    
349            /**
350             * Returns the language ID of the locale of this service context's current
351             * user.
352             *
353             * @return the language ID
354             */
355            public String getLanguageId() {
356                    return _languageId;
357            }
358    
359            /**
360             * Returns the complete URL of the current page if a page context can be
361             * determined for this service context.
362             *
363             * @return the complete URL of the current page
364             */
365            public String getLayoutFullURL() {
366                    return _layoutFullURL;
367            }
368    
369            /**
370             * Returns the relative URL of the current page if a page context can be
371             * determined for this service context.
372             *
373             * @return the relative URL of the current page
374             */
375            public String getLayoutURL() {
376                    return _layoutURL;
377            }
378    
379            public Locale getLocale() {
380                    return LocaleUtil.fromLanguageId(_languageId);
381            }
382    
383            /**
384             * Returns the date when an entity was modified if this service context is
385             * being passed as a parameter to a method which updates an entity.
386             *
387             * @return the date when an entity was modified if this service context is
388             *         being passed as a parameter to a method which updates an entity
389             */
390            public Date getModifiedDate() {
391                    return _modifiedDate;
392            }
393    
394            /**
395             * Returns the date when an entity was modified if this service context is
396             * being passed as a parameter to a method which modifies an entity.
397             *
398             * @param  defaultModifiedDate an optional default modified date to use if
399             *         this service context does not have a modified date
400             * @return the modified date if available; the default date otherwise
401             */
402            public Date getModifiedDate(Date defaultModifiedDate) {
403                    if (_modifiedDate != null) {
404                            return _modifiedDate;
405                    }
406                    else if (defaultModifiedDate != null) {
407                            return defaultModifiedDate;
408                    }
409                    else {
410                            return new Date();
411                    }
412            }
413    
414            /**
415             * Returns the main context path of the portal, concatenated with
416             * <code>/c</code>.
417             *
418             * @return the main context path of the portal
419             */
420            public String getPathMain() {
421                    return _pathMain;
422            }
423    
424            /**
425             * Returns the portal layout ID of the current page of this service context.
426             *
427             * @return the portal layout ID of the current page
428             */
429            public long getPlid() {
430                    return _plid;
431            }
432    
433            /**
434             * Returns the URL of this service context's portal, including the protocol,
435             * domain, and non-default port relative to the company instance and any
436             * virtual host.
437             *
438             * <p>
439             * The URL returned does not include the port if a default port is used.
440             * </p>
441             *
442             * @return the URL of this service context's portal, including the protocol,
443             *         domain, and non-default port relative to company instance and any
444             *         virtual host
445             */
446            public String getPortalURL() {
447                    return _portalURL;
448            }
449    
450            /**
451             * Returns the ID of the current portlet if this service context is being
452             * passed as a parameter to a portlet.
453             *
454             * @return the ID of the current portlet
455             * @see    com.liferay.portal.model.PortletPreferencesIds
456             */
457            public String getPortletId() {
458                    if (_portletPreferencesIds != null) {
459                            return _portletPreferencesIds.getPortletId();
460                    }
461                    else {
462                            return null;
463                    }
464            }
465    
466            /**
467             * Returns the portlet preferences IDs of the current portlet if the service
468             * context is being passed as a parameter to a portlet.
469             *
470             * <p>
471             * The {@link com.liferay.portal.model.PortletPreferencesIds} can be used to
472             * look up portlet preferences of the current portlet.
473             * </p>
474             *
475             * @return the portlet preferences IDs of the current portlet
476             * @see    com.liferay.portal.model.PortletPreferencesIds
477             */
478            public PortletPreferencesIds getPortletPreferencesIds() {
479                    return _portletPreferencesIds;
480            }
481    
482            /**
483             * Returns the remote address of the user making the request in this service
484             * context.
485             *
486             * @return the remote address of the user making the request
487             */
488            public String getRemoteAddr() {
489                    return _remoteAddr;
490            }
491    
492            /**
493             * Returns the remote host name of the user making the request in this
494             * service context.
495             *
496             * @return the remote host name of the user making the request
497             */
498            public String getRemoteHost() {
499                    return _remoteHost;
500            }
501    
502            /**
503             * Returns the ID of the group corresponding to the current data scope of
504             * this service context.
505             *
506             * @return the ID of the group corresponding to the current data scope
507             * @see    com.liferay.portal.model.Group
508             */
509            public long getScopeGroupId() {
510                    return _scopeGroupId;
511            }
512    
513            /**
514             * Returns the user-agent request header of this service context.
515             *
516             * @return the user-agent request header
517             * @see    com.liferay.portal.kernel.servlet.HttpHeaders
518             */
519            public String getUserAgent() {
520                    if (_headers == null) {
521                            return null;
522                    }
523    
524                    return _headers.get(HttpHeaders.USER_AGENT);
525            }
526    
527            /**
528             * Returns the complete URL of this service context's current user's profile
529             * page.
530             *
531             * @return the complete URL of this service context's current user's profile
532             *         page
533             */
534            public String getUserDisplayURL() {
535                    return _userDisplayURL;
536            }
537    
538            /**
539             * Returns the ID of this service context's current user.
540             *
541             * @return the ID of this service context's current user
542             */
543            public long getUserId() {
544                    return _userId;
545            }
546    
547            /**
548             * Returns the UUID (universally unique identifier) of this service
549             * context's current entity.
550             *
551             * @return the UUID (universally unique identifier) of this service
552             *         context's current entity
553             */
554            public String getUuid() {
555                    String uuid = _uuid;
556    
557                    _uuid = null;
558    
559                    return uuid;
560            }
561    
562            /**
563             * Returns the workflow action to take if this service context is being
564             * passed as a parameter to a method that processes a workflow action.
565             *
566             * @return the workflow action to take
567             */
568            public int getWorkflowAction() {
569                    return _workflowAction;
570            }
571    
572            public boolean isAssetEntryVisible() {
573                    return _assetEntryVisible;
574            }
575    
576            /**
577             * Returns <code>true</code> if this service context contains an add command
578             * (i.e. has command value {@link
579             * com.liferay.portal.kernel.util.Constants#ADD})
580             *
581             * @return <code>true</code> if this service context contains an add
582             *         command; <code>false</code> otherwise
583             */
584            public boolean isCommandAdd() {
585                    if (Validator.equals(_command, Constants.ADD)) {
586                            return true;
587                    }
588                    else {
589                            return false;
590                    }
591            }
592    
593            /**
594             * Returns <code>true</code> if this service context contains an update
595             * command (i.e. has command value {@link
596             * com.liferay.portal.kernel.util.Constants#UPDATE})
597             *
598             * @return <code>true</code> if this service context contains an update
599             *         command; <code>false</code> otherwise
600             */
601            public boolean isCommandUpdate() {
602                    if (Validator.equals(_command, Constants.UPDATE)) {
603                            return true;
604                    }
605                    else {
606                            return false;
607                    }
608            }
609    
610            /**
611             * Returns whether the primary entity of this service context is to be
612             * indexed/re-indexed.
613             *
614             * @return <code>true</code> the primary entity of this service context is
615             *         to be indexed/re-indexed; <code>false</code> otherwise
616             */
617            public boolean isIndexingEnabled() {
618                    return _indexingEnabled;
619            }
620    
621            /**
622             * Returns <code>true</code> if the sender of this service context's request
623             * is signed in.
624             *
625             * @return <code>true</code> if the sender of this service context's request
626             *         is signed in; <code>false</code> otherwise
627             */
628            public boolean isSignedIn() {
629                    return _signedIn;
630            }
631    
632            /**
633             * Removes the mapping of the serializable object to the name of the
634             * standard parameter of this service context.
635             *
636             * @param  name the name of the standard parameter
637             * @return the serializable object associated to the name
638             */
639            public Serializable removeAttribute(String name) {
640                    return _attributes.remove(name);
641            }
642    
643            /**
644             * Sets whether or not default community permissions should apply to a
645             * resource being manipulated by a method to which this service context is
646             * passed as a parameter.
647             *
648             * @param      addCommunityPermissions indicates whether or not to apply
649             *             default community permissions
650             * @deprecated As of 6.1, renamed to {@link
651             *             #setAddGroupPermissions(boolean)}
652             */
653            public void setAddCommunityPermissions(boolean addCommunityPermissions) {
654                    setAddGroupPermissions(addCommunityPermissions);
655            }
656    
657            /**
658             * Sets whether or not default group permissions should apply to a resource
659             * being manipulated by a method to which this service context is passed as
660             * a parameter.
661             *
662             * @param addGroupPermissions indicates whether or not to apply default
663             *        group permissions
664             */
665            public void setAddGroupPermissions(boolean addGroupPermissions) {
666                    _addGroupPermissions = addGroupPermissions;
667            }
668    
669            /**
670             * Sets whether or not default guest permissions should apply to a resource
671             * being manipulated by a method to which this service context is passed as
672             * a parameter.
673             *
674             * @param addGuestPermissions indicates whether or not to apply default
675             *        guest permissions
676             */
677            public void setAddGuestPermissions(boolean addGuestPermissions) {
678                    _addGuestPermissions = addGuestPermissions;
679            }
680    
681            /**
682             * Sets an array of asset category IDs to be applied to an asset entry if
683             * this service context is being passed as a parameter to a method which
684             * manipulates the asset entry.
685             *
686             * @param assetCategoryIds the primary keys of the asset categories
687             */
688            public void setAssetCategoryIds(long[] assetCategoryIds) {
689                    _assetCategoryIds = assetCategoryIds;
690            }
691    
692            public void setAssetEntryVisible(boolean assetEntryVisible) {
693                    _assetEntryVisible = assetEntryVisible;
694            }
695    
696            /**
697             * Sets an array of the primary keys of asset entries to be linked to an
698             * asset entry if this service context is being passed as a parameter to a
699             * method which manipulates the asset entry.
700             *
701             * @param assetLinkEntryIds the primary keys of the asset entries to be
702             *        linked to an asset entry
703             */
704            public void setAssetLinkEntryIds(long[] assetLinkEntryIds) {
705                    _assetLinkEntryIds = assetLinkEntryIds;
706            }
707    
708            /**
709             * Sets an array of asset tag names to be applied to an asset entry if this
710             * service context is being passed as a parameter to a method which
711             * manipulates the asset entry.
712             *
713             * @param assetTagNames the tag names to be applied to an asset entry
714             */
715            public void setAssetTagNames(String[] assetTagNames) {
716                    _assetTagNames = assetTagNames;
717            }
718    
719            /**
720             * Sets a mapping of a standard parameter's name to its serializable object.
721             *
722             * @param name the standard parameter name to associate with the value
723             * @param value the serializable object to be associated with the name
724             */
725            public void setAttribute(String name, Serializable value) {
726                    _attributes.put(name, value);
727            }
728    
729            /**
730             * Sets the map of the name/value pairs that are the standard parameters of
731             * this service context. Each value must be serializable.
732             *
733             * @param attributes the map of the name/value pairs that are the standard
734             *        parameters of this service context
735             */
736            public void setAttributes(Map<String, Serializable> attributes) {
737                    _attributes = attributes;
738            }
739    
740            /**
741             * Sets the value of the {@link
742             * com.liferay.portal.kernel.util.Constants#CMD} parameter used in most
743             * Liferay forms for internal portlets.
744             *
745             * @param command the value of the {@link
746             *        com.liferay.portal.kernel.util.Constants#CMD} parameter
747             */
748            public void setCommand(String command) {
749                    _command = command;
750            }
751    
752            /**
753             * Sets an array containing specific community permissions for a resource if
754             * this service context is being passed as a parameter to a method which
755             * manipulates the resource.
756             *
757             * @param      communityPermissions the community permissions (optionally
758             *             <code>null</code>)
759             * @deprecated As of 6.1, renamed to {@link #setGroupPermissions(String[])}
760             */
761            public void setCommunityPermissions(String[] communityPermissions) {
762                    setGroupPermissions(communityPermissions);
763            }
764    
765            /**
766             * Sets the company ID of this service context's current portal instance.
767             *
768             * @param companyId the primary key of this service context's current portal
769             *        instance
770             */
771            public void setCompanyId(long companyId) {
772                    _companyId = companyId;
773            }
774    
775            /**
776             * Sets the date when an entity was created if this service context is being
777             * passed as a parameter to a method which creates an entity.
778             *
779             * @param createDate the date the entity was created
780             */
781            public void setCreateDate(Date createDate) {
782                    _createDate = createDate;
783            }
784    
785            /**
786             * Sets the current URL of this service context
787             *
788             * @param currentURL the current URL of this service context
789             */
790            public void setCurrentURL(String currentURL) {
791                    _currentURL = currentURL;
792            }
793    
794            /**
795             * Sets an arbitrary number of attributes of an entity to be persisted.
796             *
797             * <p>
798             * These attributes should only include fields that {@link
799             * com.liferay.portal.service.ServiceContext} does not possess by default.
800             * </p>
801             *
802             * @param expandoBridgeAttributes the expando bridge attributes (optionally
803             *        <code>null</code>)
804             */
805            public void setExpandoBridgeAttributes(
806                    Map<String, Serializable> expandoBridgeAttributes) {
807    
808                    _expandoBridgeAttributes = expandoBridgeAttributes;
809            }
810    
811            /**
812             * Sets an array containing specific group permissions for a resource if
813             * this service context is being passed as a parameter to a method which
814             * manipulates the resource.
815             *
816             * @param groupPermissions the permissions (optionally <code>null</code>)
817             */
818            public void setGroupPermissions(String[] groupPermissions) {
819                    _groupPermissions = groupPermissions;
820            }
821    
822            /**
823             * Sets an array containing specific guest permissions for a resource if
824             * this service context is being passed as a parameter to a method which
825             * manipulates the resource.
826             *
827             * @param guestPermissions the guest permissions (optionally
828             *        <code>null</code>)
829             */
830            public void setGuestPermissions(String[] guestPermissions) {
831                    _guestPermissions = guestPermissions;
832            }
833    
834            /**
835             * Sets the map of request header name/value pairs of this service context.
836             *
837             * @param headers map of request header name/value pairs of this service
838             *        context
839             * @see   com.liferay.portal.kernel.servlet.HttpHeaders
840             */
841            public void setHeaders(Map<String, String> headers) {
842                    _headers = headers;
843            }
844    
845            /**
846             * Sets whether the primary entity of this service context is to be
847             * indexed/re-indexed.
848             *
849             * <p>
850             * The entity is only indexed/re-indexed if the method receiving this
851             * service context as a parameter does indexing.
852             * </p>
853             *
854             * @param indexingEnabled whether the primary entity of this service context
855             *        is to be indexed/re-indexed (default is <code>true</code>)
856             */
857            public void setIndexingEnabled(boolean indexingEnabled) {
858                    _indexingEnabled = indexingEnabled;
859            }
860    
861            /**
862             * Sets the language ID of the locale of this service context.
863             *
864             * @param languageId the language ID of the locale of this service context's
865             *        current user
866             */
867            public void setLanguageId(String languageId) {
868                    _languageId = languageId;
869            }
870    
871            /**
872             * Sets the complete URL of the current page for this service context.
873             *
874             * @param layoutFullURL the complete URL of the current page if a page
875             *        context can be determined for this service context
876             */
877            public void setLayoutFullURL(String layoutFullURL) {
878                    _layoutFullURL = layoutFullURL;
879            }
880    
881            /**
882             * Sets the relative URL of the current page for this service context.
883             *
884             * @param layoutURL the relative URL of the current page if a page context
885             *        can be determined for this service context
886             */
887            public void setLayoutURL(String layoutURL) {
888                    _layoutURL = layoutURL;
889            }
890    
891            /**
892             * Sets the date when an entity was modified in this service context.
893             *
894             * @param modifiedDate the date when an entity was modified in this service
895             *        context
896             */
897            public void setModifiedDate(Date modifiedDate) {
898                    _modifiedDate = modifiedDate;
899            }
900    
901            /**
902             * Sets the main context path of the portal, concatenated with
903             * <code>/c</code>.
904             *
905             * @param pathMain the main context path of the portal
906             */
907            public void setPathMain(String pathMain) {
908                    _pathMain = pathMain;
909            }
910    
911            /**
912             * Sets the portal layout ID of the current page in this service context.
913             *
914             * @param plid the portal layout ID of the current page
915             */
916            public void setPlid(long plid) {
917                    _plid = plid;
918            }
919    
920            /**
921             * Sets the URL of this service context's portal, including the protocol,
922             * domain, and non-default port relative to the company instance and any
923             * virtual host.
924             *
925             * <p>
926             * The URL should not include the port if a default port is used.
927             * </p>
928             *
929             * @param portalURL the portal URL
930             */
931            public void setPortalURL(String portalURL) {
932                    _portalURL = portalURL;
933            }
934    
935            /**
936             * Sets the portlet preferences IDs of the current portlet if this service
937             * context is being passed as a parameter to a portlet.
938             *
939             * <p>
940             * The {@link com.liferay.portal.model.PortletPreferencesIds} can be used to
941             * look up portlet preferences of the current portlet.
942             * </p>
943             *
944             * @param portletPreferencesIds the portlet preferences
945             * @see   com.liferay.portal.model.PortletPreferencesIds
946             */
947            public void setPortletPreferencesIds(
948                    PortletPreferencesIds portletPreferencesIds) {
949    
950                    _portletPreferencesIds = portletPreferencesIds;
951            }
952    
953            /**
954             * Sets the remote address of the user making the request in this service
955             * context.
956             *
957             * @param remoteAddr the remote address of the user making the request in
958             *        this service context
959             */
960            public void setRemoteAddr(String remoteAddr) {
961                    _remoteAddr = remoteAddr;
962            }
963    
964            /**
965             * Sets the remote host name of the user making the request in this service
966             * context.
967             *
968             * @param remoteHost the remote host name of the user making the request in
969             *        this service context
970             */
971            public void setRemoteHost(String remoteHost) {
972                    _remoteHost = remoteHost;
973            }
974    
975            /**
976             * Sets the ID of the group corresponding to the current data scope of this
977             * service context.
978             *
979             * @param scopeGroupId the ID of the group corresponding to the current data
980             *        scope of this service context
981             * @see   com.liferay.portal.model.Group
982             */
983            public void setScopeGroupId(long scopeGroupId) {
984                    _scopeGroupId = scopeGroupId;
985            }
986    
987            /**
988             * Sets whether the sender of this service context's request is signed in.
989             *
990             * @param signedIn whether the sender of this service context's request is
991             *        signed in
992             */
993            public void setSignedIn(boolean signedIn) {
994                    _signedIn = signedIn;
995            }
996    
997            /**
998             * Sets the complete URL of this service context's current user's profile
999             * page.
1000             *
1001             * @param userDisplayURL the complete URL of the current user's profile page
1002             */
1003            public void setUserDisplayURL(String userDisplayURL) {
1004                    _userDisplayURL = userDisplayURL;
1005            }
1006    
1007            /**
1008             * Sets the ID of this service context's current user.
1009             *
1010             * @param userId the ID of the current user
1011             */
1012            public void setUserId(long userId) {
1013                    _userId = userId;
1014            }
1015    
1016            /**
1017             * Sets the UUID (universally unique identifier) of this service context's
1018             * current entity.
1019             *
1020             * @param uuid the UUID (universally unique identifier) of the current
1021             *        entity
1022             */
1023            public void setUuid(String uuid) {
1024                    _uuid = uuid;
1025            }
1026    
1027            /**
1028             * Sets the workflow action to take if this service context is being passed
1029             * as parameter to a method that processes a workflow action.
1030             *
1031             * @param workflowAction workflow action to take (default is {@link
1032             *        com.liferay.portal.kernel.workflow.WorkflowConstants.ACTION_PUBLISH})
1033             */
1034            public void setWorkflowAction(int workflowAction) {
1035                    _workflowAction = workflowAction;
1036            }
1037    
1038            public String translate(String pattern, Object... arguments) {
1039                    Locale locale = getLocale();
1040    
1041                    return LanguageUtil.format(locale, pattern, arguments);
1042            }
1043    
1044            private boolean _addGroupPermissions;
1045            private boolean _addGuestPermissions;
1046            private long[] _assetCategoryIds;
1047            private boolean _assetEntryVisible = true;
1048            private long[] _assetLinkEntryIds;
1049            private String[] _assetTagNames;
1050            private Map<String, Serializable> _attributes;
1051            private String _command;
1052            private long _companyId;
1053            private Date _createDate;
1054            private String _currentURL;
1055            private Map<String, Serializable> _expandoBridgeAttributes;
1056            private String[] _groupPermissions;
1057            private String[] _guestPermissions;
1058            private Map<String, String> _headers;
1059            private boolean _indexingEnabled = true;
1060            private String _languageId;
1061            private String _layoutFullURL;
1062            private String _layoutURL;
1063            private Date _modifiedDate;
1064            private String _pathMain;
1065            private String _portalURL;
1066            private PortletPreferencesIds _portletPreferencesIds;
1067            private String _remoteAddr;
1068            private String _remoteHost;
1069            private long _scopeGroupId;
1070            private boolean _signedIn;
1071            private String _userDisplayURL;
1072            private long _plid;
1073            private int _workflowAction = WorkflowConstants.ACTION_PUBLISH;
1074            private long _userId;
1075            private String _uuid;
1076    
1077    }