idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
21,800 | private boolean isSingleMultiDay ( ) { long duration = getEnd ( ) . getTime ( ) - getStart ( ) . getTime ( ) ; if ( duration > I_CmsSerialDateValue . DAY_IN_MILLIS ) { return true ; } if ( isWholeDay ( ) && ( duration <= I_CmsSerialDateValue . DAY_IN_MILLIS ) ) { return false ; } Calendar start = new GregorianCalendar ( ) ; start . setTime ( getStart ( ) ) ; Calendar end = new GregorianCalendar ( ) ; end . setTime ( getEnd ( ) ) ; if ( start . get ( Calendar . DAY_OF_MONTH ) == end . get ( Calendar . DAY_OF_MONTH ) ) { return false ; } return true ; } | Returns a flag indicating if the current event is a multi - day event . The method is only called if the single event has an explicitely set end date or an explicitely changed whole day option . |
21,801 | public static void checkCreateUpload ( CmsObject cms , CmsUgcConfiguration config , String name , long size ) throws CmsUgcException { if ( ! config . getUploadParentFolder ( ) . isPresent ( ) ) { String message = Messages . get ( ) . container ( Messages . ERR_NO_UPLOADS_ALLOWED_0 ) . key ( cms . getRequestContext ( ) . getLocale ( ) ) ; throw new CmsUgcException ( CmsUgcConstants . ErrorCode . errNoUploadAllowed , message ) ; } if ( config . getMaxUploadSize ( ) . isPresent ( ) ) { if ( config . getMaxUploadSize ( ) . get ( ) . longValue ( ) < size ) { String message = Messages . get ( ) . container ( Messages . ERR_UPLOAD_TOO_BIG_1 , name ) . key ( cms . getRequestContext ( ) . getLocale ( ) ) ; throw new CmsUgcException ( CmsUgcConstants . ErrorCode . errMaxUploadSizeExceeded , message ) ; } } if ( config . getValidExtensions ( ) . isPresent ( ) ) { List < String > validExtensions = config . getValidExtensions ( ) . get ( ) ; boolean foundExtension = false ; for ( String extension : validExtensions ) { if ( name . toLowerCase ( ) . endsWith ( extension . toLowerCase ( ) ) ) { foundExtension = true ; break ; } } if ( ! foundExtension ) { String message = Messages . get ( ) . container ( Messages . ERR_UPLOAD_FILE_EXTENSION_NOT_ALLOWED_1 , name ) . key ( cms . getRequestContext ( ) . getLocale ( ) ) ; throw new CmsUgcException ( CmsUgcConstants . ErrorCode . errInvalidExtension , message ) ; } } } | Checks whether an uploaded file can be created in the VFS and throws an exception otherwise . |
21,802 | protected void addFacetPart ( CmsSolrQuery query ) { StringBuffer value = new StringBuffer ( ) ; value . append ( "{!key=" ) . append ( m_config . getName ( ) ) ; addFacetOptions ( value ) ; if ( m_config . getIgnoreAllFacetFilters ( ) || ( ! m_state . getCheckedEntries ( ) . isEmpty ( ) && ! m_config . getIsAndFacet ( ) ) ) { value . append ( " ex=" ) . append ( m_config . getIgnoreTags ( ) ) ; } value . append ( "}" ) ; value . append ( m_config . getRange ( ) ) ; query . add ( "facet.range" , value . toString ( ) ) ; } | Generate query part for the facet without filters . |
21,803 | private void setFittingWeekDay ( Calendar date ) { date . set ( Calendar . DAY_OF_MONTH , 1 ) ; int weekDayFirst = date . get ( Calendar . DAY_OF_WEEK ) ; int firstFittingWeekDay = ( ( ( m_weekDay . toInt ( ) + I_CmsSerialDateValue . NUM_OF_WEEKDAYS ) - weekDayFirst ) % I_CmsSerialDateValue . NUM_OF_WEEKDAYS ) + 1 ; int fittingWeekDay = firstFittingWeekDay + ( I_CmsSerialDateValue . NUM_OF_WEEKDAYS * m_weekOfMonth . ordinal ( ) ) ; if ( fittingWeekDay > date . getActualMaximum ( Calendar . DAY_OF_MONTH ) ) { fittingWeekDay -= I_CmsSerialDateValue . NUM_OF_WEEKDAYS ; } date . set ( Calendar . DAY_OF_MONTH , fittingWeekDay ) ; } | Adjusts the day in the provided month that it fits the specified week day . If there s no match for that provided month the next possible month is checked . |
21,804 | public VerticalLayout getEmptyLayout ( ) { m_emptyLayout = CmsVaadinUtils . getInfoLayout ( CmsOuTreeType . USER . getEmptyMessageKey ( ) ) ; setVisible ( size ( ) > 0 ) ; m_emptyLayout . setVisible ( size ( ) == 0 ) ; return m_emptyLayout ; } | Layout which gets displayed if table is empty . |
21,805 | public List < CmsUser > getVisibleUser ( ) { if ( ! m_fullyLoaded ) { return m_users ; } if ( size ( ) == m_users . size ( ) ) { return m_users ; } List < CmsUser > directs = new ArrayList < CmsUser > ( ) ; for ( CmsUser user : m_users ) { if ( ! m_indirects . contains ( user ) ) { directs . add ( user ) ; } } return directs ; } | Gets currently visible user . |
21,806 | String getStatus ( CmsUser user , boolean disabled , boolean newUser ) { if ( disabled ) { return CmsVaadinUtils . getMessageText ( Messages . GUI_USERMANAGEMENT_USER_DISABLED_0 ) ; } if ( newUser ) { return CmsVaadinUtils . getMessageText ( Messages . GUI_USERMANAGEMENT_USER_INACTIVE_0 ) ; } if ( OpenCms . getLoginManager ( ) . isUserTempDisabled ( user . getName ( ) ) ) { return CmsVaadinUtils . getMessageText ( Messages . GUI_USERMANAGEMENT_UNLOCK_USER_STATUS_0 ) ; } if ( isUserPasswordReset ( user ) ) { return CmsVaadinUtils . getMessageText ( Messages . GUI_USERMANAGEMENT_USER_PASSWORT_RESET_0 ) ; } return CmsVaadinUtils . getMessageText ( Messages . GUI_USERMANAGEMENT_USER_ACTIVE_0 ) ; } | Returns status message . |
21,807 | String getStatusHelp ( CmsUser user , boolean disabled , boolean newUser ) { if ( disabled ) { return CmsVaadinUtils . getMessageText ( Messages . GUI_USERMANAGEMENT_USER_DISABLED_HELP_0 ) ; } if ( newUser ) { return CmsVaadinUtils . getMessageText ( Messages . GUI_USERMANAGEMENT_USER_INACTIVE_HELP_0 ) ; } if ( isUserPasswordReset ( user ) ) { return CmsVaadinUtils . getMessageText ( Messages . GUI_USERMANAGEMENT_USER_PASSWORT_RESET_HELP_0 ) ; } long lastLogin = user . getLastlogin ( ) ; return CmsVaadinUtils . getMessageText ( Messages . GUI_USERMANAGEMENT_USER_ACTIVE_HELP_1 , CmsDateUtil . getDateTime ( new Date ( lastLogin ) , DateFormat . SHORT , A_CmsUI . get ( ) . getLocale ( ) ) ) ; } | Returns status help message . |
21,808 | boolean isUserPasswordReset ( CmsUser user ) { if ( USER_PASSWORD_STATUS . containsKey ( user . getId ( ) ) ) { if ( ! USER_PASSWORD_STATUS . get ( user . getId ( ) ) . booleanValue ( ) ) { return false ; } if ( m_checkedUserPasswordReset . contains ( user . getId ( ) ) ) { return true ; } } CmsUser currentUser = user ; if ( user . getAdditionalInfo ( ) . size ( ) < 3 ) { try { currentUser = m_cms . readUser ( user . getId ( ) ) ; } catch ( CmsException e ) { LOG . error ( "Can not read user" , e ) ; } } if ( currentUser . getAdditionalInfo ( CmsUserSettings . ADDITIONAL_INFO_PASSWORD_RESET ) != null ) { USER_PASSWORD_STATUS . put ( currentUser . getId ( ) , new Boolean ( true ) ) ; m_checkedUserPasswordReset . add ( currentUser . getId ( ) ) ; return true ; } USER_PASSWORD_STATUS . put ( currentUser . getId ( ) , new Boolean ( false ) ) ; return false ; } | Is the user password reset? |
21,809 | public CmsSolrQuery getQuery ( CmsObject cms ) { final CmsSolrQuery query = new CmsSolrQuery ( ) ; query . setCategories ( m_categories ) ; if ( null != m_containerTypes ) { query . addFilterQuery ( CmsSearchField . FIELD_CONTAINER_TYPES , m_containerTypes , false , false ) ; } query . addFilterQuery ( CmsSearchUtil . getDateCreatedTimeRangeFilterQuery ( CmsSearchField . FIELD_DATE_CREATED , getDateCreatedRange ( ) . m_startTime , getDateCreatedRange ( ) . m_endTime ) ) ; query . addFilterQuery ( CmsSearchUtil . getDateCreatedTimeRangeFilterQuery ( CmsSearchField . FIELD_DATE_LASTMODIFIED , getDateLastModifiedRange ( ) . m_startTime , getDateLastModifiedRange ( ) . m_endTime ) ) ; m_foldersToSearchIn = new ArrayList < String > ( ) ; addFoldersToSearchIn ( m_folders ) ; addFoldersToSearchIn ( m_galleries ) ; setSearchFolders ( cms ) ; query . addFilterQuery ( CmsSearchField . FIELD_PARENT_FOLDERS , new ArrayList < String > ( m_foldersToSearchIn ) , false , true ) ; if ( ! m_ignoreSearchExclude ) { query . addFilterQuery ( "-" + CmsSearchField . FIELD_SEARCH_EXCLUDE , Arrays . asList ( new String [ ] { A_CmsSearchIndex . PROPERTY_SEARCH_EXCLUDE_VALUE_ALL , A_CmsSearchIndex . PROPERTY_SEARCH_EXCLUDE_VALUE_GALLERY } ) , false , true ) ; } query . setRows ( new Integer ( m_matchesPerPage ) ) ; if ( null != m_resourceTypes ) { List < String > resourceTypes = new ArrayList < > ( m_resourceTypes ) ; if ( m_resourceTypes . contains ( CmsResourceTypeFunctionConfig . TYPE_NAME ) && ! m_resourceTypes . contains ( CmsXmlDynamicFunctionHandler . TYPE_FUNCTION ) ) { resourceTypes . add ( CmsXmlDynamicFunctionHandler . TYPE_FUNCTION ) ; } query . setResourceTypes ( resourceTypes ) ; } query . setStart ( new Integer ( ( m_resultPage - 1 ) * m_matchesPerPage ) ) ; if ( null != m_locale ) { query . setLocales ( CmsLocaleManager . getLocale ( m_locale ) ) ; } if ( null != m_words ) { query . setQuery ( m_words ) ; } query . setSort ( getSort ( ) . getFirst ( ) , getSort ( ) . getSecond ( ) ) ; query . addFilterQuery ( "{!collapse field=id}" ) ; query . setFields ( CmsGallerySearchResult . getRequiredSolrFields ( ) ) ; if ( ( m_allowedFunctions != null ) && ! m_allowedFunctions . isEmpty ( ) ) { String functionFilter = "((-type:(" + CmsXmlDynamicFunctionHandler . TYPE_FUNCTION + " OR " + CmsResourceTypeFunctionConfig . TYPE_NAME + ")) OR (id:(" ; Iterator < CmsUUID > it = m_allowedFunctions . iterator ( ) ; while ( it . hasNext ( ) ) { CmsUUID id = it . next ( ) ; functionFilter += id . toString ( ) ; if ( it . hasNext ( ) ) { functionFilter += " OR " ; } } functionFilter += ")))" ; query . addFilterQuery ( functionFilter ) ; } return query ; } | Returns a CmsSolrQuery representation of this class . |
21,810 | private void addFoldersToSearchIn ( final List < String > folders ) { if ( null == folders ) { return ; } for ( String folder : folders ) { if ( ! CmsResource . isFolder ( folder ) ) { folder += "/" ; } m_foldersToSearchIn . add ( folder ) ; } } | Adds folders to perform the search in . |
21,811 | private void setSearchScopeFilter ( CmsObject cms ) { final List < String > searchRoots = CmsSearchUtil . computeScopeFolders ( cms , this ) ; if ( ( null != getResourceTypes ( ) ) && containsFunctionType ( getResourceTypes ( ) ) ) { searchRoots . add ( "/system/modules/" ) ; } addFoldersToSearchIn ( searchRoots ) ; } | Sets the search scope . |
21,812 | private String dbProp ( String name ) { String dbType = m_setupBean . getDatabase ( ) ; Object prop = m_setupBean . getDatabaseProperties ( ) . get ( dbType ) . get ( dbType + "." + name ) ; if ( prop == null ) { return "" ; } return prop . toString ( ) ; } | Accesses a property from the DB configuration for the selected DB . |
21,813 | protected void add ( Widget child , Element container ) { child . removeFromParent ( ) ; getChildren ( ) . add ( child ) ; DOM . appendChild ( container , child . getElement ( ) ) ; adopt ( child ) ; } | Adds a new child widget to the panel attaching its Element to the specified container Element . |
21,814 | protected int adjustIndex ( Widget child , int beforeIndex ) { checkIndexBoundsForInsertion ( beforeIndex ) ; if ( child . getParent ( ) == this ) { int idx = getWidgetIndex ( child ) ; if ( idx < beforeIndex ) { beforeIndex -- ; } } return beforeIndex ; } | Adjusts beforeIndex to account for the possibility that the given widget is already a child of this panel . |
21,815 | protected void beginDragging ( MouseDownEvent event ) { m_dragging = true ; m_windowWidth = Window . getClientWidth ( ) ; m_clientLeft = Document . get ( ) . getBodyOffsetLeft ( ) ; m_clientTop = Document . get ( ) . getBodyOffsetTop ( ) ; DOM . setCapture ( getElement ( ) ) ; m_dragStartX = event . getX ( ) ; m_dragStartY = event . getY ( ) ; addStyleName ( I_CmsLayoutBundle . INSTANCE . dialogCss ( ) . dragging ( ) ) ; } | Called on mouse down in the caption area begins the dragging loop by turning on event capture . |
21,816 | protected void endDragging ( MouseUpEvent event ) { m_dragging = false ; DOM . releaseCapture ( getElement ( ) ) ; removeStyleName ( I_CmsLayoutBundle . INSTANCE . dialogCss ( ) . dragging ( ) ) ; } | Called on mouse up in the caption area ends dragging by ending event capture . |
21,817 | public Map < String , String > getParams ( ) { Map < String , String > params = new HashMap < > ( 1 ) ; params . put ( PARAM_COLLAPSED , Boolean . TRUE . toString ( ) ) ; return params ; } | Add the option specifying if the categories should be displayed collapsed when the dialog opens . |
21,818 | public static boolean updatingIndexNecessesary ( CmsObject cms ) { setCmsOfflineProject ( cms ) ; if ( isSolrSpellcheckIndexDirectoryEmpty ( ) ) { return true ; } long dateMostRecentDictionary = getMostRecentDate ( cms ) ; long dateOldestIndexWrite = getOldestIndexDate ( cms ) ; return dateMostRecentDictionary > dateOldestIndexWrite ; } | Checks whether a built of the indices is necessary . |
21,819 | private static String getSolrSpellcheckRfsPath ( ) { String sPath = OpenCms . getSystemInfo ( ) . getWebInfRfsPath ( ) ; if ( ! OpenCms . getSystemInfo ( ) . getWebInfRfsPath ( ) . endsWith ( File . separator ) ) { sPath += File . separator ; } return sPath + "solr" + File . separator + "spellcheck" + File . separator + "data" ; } | Returns the path in the RFS where the Solr spellcheck files reside . |
21,820 | private static void readAndAddDocumentsFromStream ( final SolrClient client , final String lang , final InputStream is , final List < SolrInputDocument > documents , final boolean closeStream ) { final BufferedReader br = new BufferedReader ( new InputStreamReader ( is ) ) ; try { String line = br . readLine ( ) ; while ( null != line ) { final SolrInputDocument document = new SolrInputDocument ( ) ; document . addField ( "entry_" + lang , line ) ; documents . add ( document ) ; if ( documents . size ( ) >= MAX_LIST_SIZE ) { addDocuments ( client , documents , false ) ; documents . clear ( ) ; } line = br . readLine ( ) ; } } catch ( IOException e ) { LOG . error ( "Could not read spellcheck dictionary from input stream." ) ; } catch ( SolrServerException e ) { LOG . error ( "Error while adding documents to Solr server. " ) ; } finally { try { if ( closeStream ) { br . close ( ) ; } } catch ( Exception e ) { } } } | Parses the dictionary from an InputStream . |
21,821 | private static void setCmsOfflineProject ( CmsObject cms ) { if ( null == cms ) { return ; } final CmsRequestContext cmsContext = cms . getRequestContext ( ) ; final CmsProject cmsProject = cmsContext . getCurrentProject ( ) ; if ( cmsProject . isOnlineProject ( ) ) { CmsProject cmsOfflineProject ; try { cmsOfflineProject = cms . readProject ( "Offline" ) ; cmsContext . setCurrentProject ( cmsOfflineProject ) ; } catch ( CmsException e ) { LOG . warn ( "Could not set the current project to \"Offline\". " ) ; } } } | Sets the appropriate OpenCms context . |
21,822 | private String toPath ( String name , IconSize size ) { return CmsStringUtil . joinPaths ( CmsWorkplace . getSkinUri ( ) , ICON_FOLDER , "" + name . hashCode ( ) ) + size . getSuffix ( ) ; } | Transforms user name and icon size into the image path . |
21,823 | private String toRfsName ( String name , IconSize size ) { return CmsStringUtil . joinPaths ( m_cache . getRepositoryPath ( ) , "" + name . hashCode ( ) ) + size . getSuffix ( ) ; } | Transforms user name and icon size into the rfs image path . |
21,824 | private I_CmsSearchIndex getIndex ( ) { I_CmsSearchIndex index = null ; if ( isInitialCall ( ) ) { index = OpenCms . getSearchManager ( ) . getIndex ( getSettings ( ) . getUserSettings ( ) . getWorkplaceSearchIndexName ( ) ) ; } else { index = OpenCms . getSearchManager ( ) . getIndex ( getJsp ( ) . getRequest ( ) . getParameter ( "indexName.0" ) ) ; } return index ; } | Gets the index to use in the search . |
21,825 | public void transform ( String name , String transform ) throws Exception { File configFile = new File ( m_configDir , name ) ; File transformFile = new File ( m_xsltDir , transform ) ; try ( InputStream stream = new FileInputStream ( transformFile ) ) { StreamSource source = new StreamSource ( stream ) ; transform ( configFile , source ) ; } } | Transforms a config file with an XSLT transform . |
21,826 | public void transformConfig ( ) throws Exception { List < TransformEntry > entries = readTransformEntries ( new File ( m_xsltDir , "transforms.xml" ) ) ; for ( TransformEntry entry : entries ) { transform ( entry . getConfigFile ( ) , entry . getXslt ( ) ) ; } m_isDone = true ; } | Transforms the configuration . |
21,827 | public String validationErrors ( ) { List < String > errors = new ArrayList < > ( ) ; for ( File config : getConfigFiles ( ) ) { String filename = config . getName ( ) ; try ( FileInputStream stream = new FileInputStream ( config ) ) { CmsXmlUtils . unmarshalHelper ( CmsFileUtil . readFully ( stream , false ) , new CmsXmlEntityResolver ( null ) , true ) ; } catch ( CmsXmlException e ) { errors . add ( filename + ":" + e . getCause ( ) . getMessage ( ) ) ; } catch ( Exception e ) { errors . add ( filename + ":" + e . getMessage ( ) ) ; } } if ( errors . size ( ) == 0 ) { return null ; } String errString = CmsStringUtil . listAsString ( errors , "\n" ) ; JSONObject obj = new JSONObject ( ) ; try { obj . put ( "err" , errString ) ; } catch ( JSONException e ) { } return obj . toString ( ) ; } | Gets validation errors either as a JSON string or null if there are no validation errors . |
21,828 | private List < File > getConfigFiles ( ) { String [ ] filenames = { "opencms-modules.xml" , "opencms-system.xml" , "opencms-vfs.xml" , "opencms-importexport.xml" , "opencms-sites.xml" , "opencms-variables.xml" , "opencms-scheduler.xml" , "opencms-workplace.xml" , "opencms-search.xml" } ; List < File > result = new ArrayList < > ( ) ; for ( String fn : filenames ) { File file = new File ( m_configDir , fn ) ; if ( file . exists ( ) ) { result . add ( file ) ; } } return result ; } | Gets existing config files . |
21,829 | private List < TransformEntry > readTransformEntries ( File file ) throws Exception { List < TransformEntry > result = new ArrayList < > ( ) ; try ( FileInputStream fis = new FileInputStream ( file ) ) { byte [ ] data = CmsFileUtil . readFully ( fis , false ) ; Document doc = CmsXmlUtils . unmarshalHelper ( data , null , false ) ; for ( Node node : doc . selectNodes ( "//transform" ) ) { Element elem = ( ( Element ) node ) ; String xslt = elem . attributeValue ( "xslt" ) ; String conf = elem . attributeValue ( "config" ) ; TransformEntry entry = new TransformEntry ( conf , xslt ) ; result . add ( entry ) ; } } return result ; } | Reads entries from transforms . xml . |
21,830 | private void transform ( File file , Source transformSource ) throws TransformerConfigurationException , IOException , SAXException , TransformerException , ParserConfigurationException { Transformer transformer = m_transformerFactory . newTransformer ( transformSource ) ; transformer . setOutputProperty ( OutputKeys . ENCODING , "us-ascii" ) ; transformer . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; transformer . setOutputProperty ( "{http://xml.apache.org/xslt}indent-amount" , "4" ) ; String configDirPath = m_configDir . getAbsolutePath ( ) ; configDirPath = configDirPath . replaceFirst ( "[/\\\\]$" , "" ) ; transformer . setParameter ( "configDir" , configDirPath ) ; XMLReader reader = m_parserFactory . newSAXParser ( ) . getXMLReader ( ) ; reader . setEntityResolver ( NO_ENTITY_RESOLVER ) ; Source source ; if ( file . exists ( ) ) { source = new SAXSource ( reader , new InputSource ( file . getCanonicalPath ( ) ) ) ; } else { source = new SAXSource ( reader , new InputSource ( new ByteArrayInputStream ( DEFAULT_XML . getBytes ( "UTF-8" ) ) ) ) ; } ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; Result target = new StreamResult ( baos ) ; transformer . transform ( source , target ) ; byte [ ] transformedConfig = baos . toByteArray ( ) ; try ( FileOutputStream output = new FileOutputStream ( file ) ) { output . write ( transformedConfig ) ; } } | Transforms a single configuration file using the given transformation source . |
21,831 | public List < CmsJspNavElement > getSubNavigation ( ) { if ( m_subNavigation == null ) { if ( m_resource . isFile ( ) ) { m_subNavigation = Collections . emptyList ( ) ; } else if ( m_navContext == null ) { try { throw new Exception ( "Can not get subnavigation because navigation context is not set." ) ; } catch ( Exception e ) { LOG . warn ( e . getLocalizedMessage ( ) , e ) ; m_subNavigation = Collections . emptyList ( ) ; } } else { CmsJspNavBuilder navBuilder = m_navContext . getNavBuilder ( ) ; m_subNavigation = navBuilder . getNavigationForFolder ( navBuilder . getCmsObject ( ) . getSitePath ( m_resource ) , m_navContext . getVisibility ( ) , m_navContext . getFilter ( ) ) ; } } return m_subNavigation ; } | Gets the sub - entries of the navigation entry . |
21,832 | private Map < String , String > getLocaleProperties ( ) { if ( m_localeProperties == null ) { m_localeProperties = CmsCollectionsGenericWrapper . createLazyMap ( new CmsProperty . CmsPropertyLocaleTransformer ( m_properties , m_locale ) ) ; } return m_localeProperties ; } | Helper to get locale specific properties . |
21,833 | public void setEveryWorkingDay ( final boolean isEveryWorkingDay ) { if ( m_model . isEveryWorkingDay ( ) != isEveryWorkingDay ) { removeExceptionsOnChange ( new Command ( ) { public void execute ( ) { m_model . setEveryWorkingDay ( Boolean . valueOf ( isEveryWorkingDay ) ) ; m_model . setInterval ( getPatternDefaultValues ( ) . getInterval ( ) ) ; onValueChange ( ) ; } } ) ; } } | Set the everyWorkingDay flag . |
21,834 | private void removeListener ( CmsUUID listenerId ) { getRequest ( ) . getSession ( ) . removeAttribute ( SESSION_ATTRIBUTE_LISTENER_ID ) ; m_listeners . remove ( listenerId ) ; } | Remove the listener active in this session . |
21,835 | private Map < String , String > parseAttributes ( I_CmsXmlContentLocation formatterLoc ) { Map < String , String > result = new LinkedHashMap < > ( ) ; for ( I_CmsXmlContentValueLocation mappingLoc : formatterLoc . getSubValues ( N_ATTRIBUTE ) ) { String key = CmsConfigurationReader . getString ( m_cms , mappingLoc . getSubValue ( N_KEY ) ) ; String value = CmsConfigurationReader . getString ( m_cms , mappingLoc . getSubValue ( N_VALUE ) ) ; result . put ( key , value ) ; } return Collections . unmodifiableMap ( result ) ; } | Parses formatter attributes . |
21,836 | public Set < String > getConfiguredWorkplaceBundles ( ) { CmsADEConfigData configData = internalLookupConfiguration ( null , null ) ; return configData . getConfiguredWorkplaceBundles ( ) ; } | Returns the names of the bundles configured as workplace bundles in any module configuration . |
21,837 | public static String removeOpenCmsContext ( final String path ) { String context = OpenCms . getSystemInfo ( ) . getOpenCmsContext ( ) ; if ( path . startsWith ( context + "/" ) ) { return path . substring ( context . length ( ) ) ; } String renderPrefix = OpenCms . getStaticExportManager ( ) . getVfsPrefix ( ) ; if ( path . startsWith ( renderPrefix + "/" ) ) { return path . substring ( renderPrefix . length ( ) ) ; } return path ; } | Given a path to a VFS resource the method removes the OpenCms context in case the path is prefixed by that context . |
21,838 | public String getPermalink ( CmsObject cms , String resourceName , CmsUUID detailContentId ) { String permalink = "" ; try { permalink = substituteLink ( cms , CmsPermalinkResourceHandler . PERMALINK_HANDLER ) ; String id = cms . readResource ( resourceName , CmsResourceFilter . ALL ) . getStructureId ( ) . toString ( ) ; permalink += id ; if ( detailContentId != null ) { permalink += ":" + detailContentId ; } String ext = CmsFileUtil . getExtension ( resourceName ) ; if ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( ext ) ) { permalink += ext ; } CmsSite currentSite = OpenCms . getSiteManager ( ) . getCurrentSite ( cms ) ; String serverPrefix = null ; if ( currentSite == OpenCms . getSiteManager ( ) . getDefaultSite ( ) ) { Optional < CmsSite > siteForDefaultUri = OpenCms . getSiteManager ( ) . getSiteForDefaultUri ( ) ; if ( siteForDefaultUri . isPresent ( ) ) { serverPrefix = siteForDefaultUri . get ( ) . getServerPrefix ( cms , resourceName ) ; } else { serverPrefix = OpenCms . getSiteManager ( ) . getWorkplaceServer ( ) ; } } else { serverPrefix = currentSite . getServerPrefix ( cms , resourceName ) ; } if ( ! permalink . startsWith ( serverPrefix ) ) { permalink = serverPrefix + permalink ; } } catch ( CmsException e ) { permalink = e . getLocalizedMessage ( ) ; if ( LOG . isErrorEnabled ( ) ) { LOG . error ( e . getLocalizedMessage ( ) , e ) ; } } return permalink ; } | Returns the perma link for the given resource and optional detail content . <p< |
21,839 | public String getPermalinkForCurrentPage ( CmsObject cms ) { return getPermalink ( cms , cms . getRequestContext ( ) . getUri ( ) , cms . getRequestContext ( ) . getDetailContentId ( ) ) ; } | Returns the perma link for the current page based on the URI and detail content id stored in the CmsObject passed as a parameter . <p< |
21,840 | public String getWorkplaceLink ( CmsObject cms , String resourceName , boolean forceSecure ) { String result = substituteLinkForUnknownTarget ( cms , resourceName , forceSecure ) ; return appendServerPrefix ( cms , result , resourceName , true ) ; } | Returns the link for the given workplace resource . |
21,841 | private Table buildTable ( CmsSqlConsoleResults results ) { IndexedContainer container = new IndexedContainer ( ) ; int numCols = results . getColumns ( ) . size ( ) ; for ( int c = 0 ; c < numCols ; c ++ ) { container . addContainerProperty ( Integer . valueOf ( c ) , results . getColumnType ( c ) , null ) ; } int r = 0 ; for ( List < Object > row : results . getData ( ) ) { Item item = container . addItem ( Integer . valueOf ( r ) ) ; for ( int c = 0 ; c < numCols ; c ++ ) { item . getItemProperty ( Integer . valueOf ( c ) ) . setValue ( row . get ( c ) ) ; } r += 1 ; } Table table = new Table ( ) ; table . setContainerDataSource ( container ) ; for ( int c = 0 ; c < numCols ; c ++ ) { String col = ( results . getColumns ( ) . get ( c ) ) ; table . setColumnHeader ( Integer . valueOf ( c ) , col ) ; } table . setWidth ( "100%" ) ; table . setHeight ( "100%" ) ; table . setColumnCollapsingAllowed ( true ) ; return table ; } | Builds the table for the database results . |
21,842 | private void updateImageInfo ( ) { String crop = getCrop ( ) ; String point = getPoint ( ) ; m_imageInfoDisplay . fillContent ( m_info , crop , point ) ; } | Updates the image information . |
21,843 | public static CmsShell getTopShell ( ) { ArrayList < CmsShell > shells = SHELL_STACK . get ( ) ; if ( shells . isEmpty ( ) ) { return null ; } return shells . get ( shells . size ( ) - 1 ) ; } | Gets the top of thread - local shell stack or null if it is empty . |
21,844 | public static void popShell ( ) { ArrayList < CmsShell > shells = SHELL_STACK . get ( ) ; if ( shells . size ( ) > 0 ) { shells . remove ( shells . size ( ) - 1 ) ; } } | Removes top of thread - local shell stack . |
21,845 | public static CmsSearchConfigurationSorting create ( final String sortParam , final List < I_CmsSearchConfigurationSortOption > options , final I_CmsSearchConfigurationSortOption defaultOption ) { return ( null != sortParam ) || ( ( null != options ) && ! options . isEmpty ( ) ) || ( null != defaultOption ) ? new CmsSearchConfigurationSorting ( sortParam , options , defaultOption ) : null ; } | Creates a sort configuration iff at least one of the parameters is not null and the options list is not empty . |
21,846 | public static CmsResourceTypeStatResultList init ( CmsResourceTypeStatResultList resList ) { if ( resList == null ) { return new CmsResourceTypeStatResultList ( ) ; } resList . deleteOld ( ) ; return resList ; } | Method to initialize the list . |
21,847 | protected boolean exportWithMinimalMetaData ( String path ) { String checkPath = path . startsWith ( "/" ) ? path + "/" : "/" + path + "/" ; for ( String p : m_parameters . getResourcesToExportWithMetaData ( ) ) { if ( checkPath . startsWith ( p ) ) { return false ; } } return true ; } | Check if the resource should be exported with minimal meta - data . This holds for resources that are not part of the export but must be exported as super - folders . |
21,848 | public void setDraggable ( Element elem , String draggable ) { super . setDraggable ( elem , draggable ) ; if ( "true" . equals ( draggable ) ) { elem . getStyle ( ) . setProperty ( "webkitUserDrag" , "element" ) ; } else { elem . getStyle ( ) . clearProperty ( "webkitUserDrag" ) ; } } | Webkit based browsers require that we set the webkit - user - drag style attribute to make an element draggable . |
21,849 | protected void createParentXmlElements ( CmsXmlContent xmlContent , String xmlPath , Locale l ) { if ( CmsXmlUtils . isDeepXpath ( xmlPath ) ) { String parentPath = CmsXmlUtils . removeLastXpathElement ( xmlPath ) ; if ( null == xmlContent . getValue ( parentPath , l ) ) { createParentXmlElements ( xmlContent , parentPath , l ) ; xmlContent . addValue ( m_cms , parentPath , l , CmsXmlUtils . getXpathIndexInt ( parentPath ) - 1 ) ; } } } | Creates the parents of nested XML elements if necessary . |
21,850 | public byte [ ] join ( Map < Integer , byte [ ] > parts ) { checkArgument ( parts . size ( ) > 0 , "No parts provided" ) ; final int [ ] lengths = parts . values ( ) . stream ( ) . mapToInt ( v -> v . length ) . distinct ( ) . toArray ( ) ; checkArgument ( lengths . length == 1 , "Varying lengths of part values" ) ; final byte [ ] secret = new byte [ lengths [ 0 ] ] ; for ( int i = 0 ; i < secret . length ; i ++ ) { final byte [ ] [ ] points = new byte [ parts . size ( ) ] [ 2 ] ; int j = 0 ; for ( Map . Entry < Integer , byte [ ] > part : parts . entrySet ( ) ) { points [ j ] [ 0 ] = part . getKey ( ) . byteValue ( ) ; points [ j ] [ 1 ] = part . getValue ( ) [ i ] ; j ++ ; } secret [ i ] = GF256 . interpolate ( points ) ; } return secret ; } | Joins the given parts to recover the original secret . |
21,851 | public static Processor < DataSinkTask > sink ( DataSink dataSink , int parallelism , String description , UserConfig taskConf , ActorSystem system ) { io . gearpump . streaming . Processor < DataSinkTask > p = DataSinkProcessor . apply ( dataSink , parallelism , description , taskConf , system ) ; return new Processor ( p ) ; } | Creates a Sink Processor |
21,852 | public static Processor < DataSourceTask > source ( DataSource source , int parallelism , String description , UserConfig taskConf , ActorSystem system ) { io . gearpump . streaming . Processor < DataSourceTask < Object , Object > > p = DataSourceProcessor . apply ( source , parallelism , description , taskConf , system ) ; return new Processor ( p ) ; } | Creates a Source Processor |
21,853 | public Token recoverInline ( Parser recognizer ) throws RecognitionException { Token matchedSymbol = singleTokenDeletion ( recognizer ) ; if ( matchedSymbol != null ) { recognizer . consume ( ) ; return matchedSymbol ; } if ( singleTokenInsertion ( recognizer ) ) { return getMissingSymbol ( recognizer ) ; } throw new InputMismatchException ( recognizer ) ; } | Make sure we don t attempt to recover inline ; if the parser successfully recovers it won t throw an exception . |
21,854 | protected DirectiveStatement parseDirectiveStatement ( DirectiveStContext node ) { DirectiveStContext stContext = ( DirectiveStContext ) node ; DirectiveExpContext direExp = stContext . directiveExp ( ) ; Token token = direExp . Identifier ( ) . getSymbol ( ) ; String directive = token . getText ( ) . toLowerCase ( ) . intern ( ) ; TerminalNode value = direExp . StringLiteral ( ) ; List < TerminalNode > idNodeList = null ; DirectiveExpIDListContext directExpidLisCtx = direExp . directiveExpIDList ( ) ; if ( directExpidLisCtx != null ) { idNodeList = directExpidLisCtx . Identifier ( ) ; } Set < String > idList = null ; DirectiveStatement ds = null ; if ( value != null ) { String idListValue = this . getStringValue ( value . getText ( ) ) ; idList = new HashSet ( Arrays . asList ( idListValue . split ( "," ) ) ) ; ds = new DirectiveStatement ( directive , idList , this . getBTToken ( token ) ) ; } else if ( idNodeList != null ) { idList = new HashSet < String > ( ) ; for ( TerminalNode t : idNodeList ) { idList . add ( t . getText ( ) ) ; } ds = new DirectiveStatement ( directive , idList , this . getBTToken ( token ) ) ; } else { ds = new DirectiveStatement ( directive , Collections . EMPTY_SET , this . getBTToken ( token ) ) ; } if ( directive . equals ( "dynamic" ) ) { if ( ds . getIdList ( ) . size ( ) == 0 ) { data . allDynamic = true ; } else { data . dynamicObjectSet = ds . getIdList ( ) ; } ds = new DirectiveStatement ( directive , Collections . EMPTY_SET , this . getBTToken ( token ) ) ; return ds ; } else if ( directive . equalsIgnoreCase ( "safe_output_open" . intern ( ) ) ) { this . pbCtx . isSafeOutput = true ; return ds ; } else if ( directive . equalsIgnoreCase ( "safe_output_close" . intern ( ) ) ) { this . pbCtx . isSafeOutput = false ; return ds ; } else { return ds ; } } | directive dynamic xxx yy |
21,855 | public static NamingConvention determineNamingConvention ( TypeElement type , Iterable < ExecutableElement > methods , Messager messager , Types types ) { ExecutableElement beanMethod = null ; ExecutableElement prefixlessMethod = null ; for ( ExecutableElement method : methods ) { switch ( methodNameConvention ( method ) ) { case BEAN : beanMethod = firstNonNull ( beanMethod , method ) ; break ; case PREFIXLESS : prefixlessMethod = firstNonNull ( prefixlessMethod , method ) ; break ; default : break ; } } if ( prefixlessMethod != null ) { if ( beanMethod != null ) { messager . printMessage ( ERROR , "Type contains an illegal mix of get-prefixed and unprefixed getter methods, e.g. '" + beanMethod . getSimpleName ( ) + "' and '" + prefixlessMethod . getSimpleName ( ) + "'" , type ) ; } return new PrefixlessConvention ( messager , types ) ; } else { return new BeanConvention ( messager , types ) ; } } | Determine whether the user has followed bean - like naming convention or not . |
21,856 | public SourceBuilder add ( String fmt , Object ... args ) { TemplateApplier . withParams ( args ) . onText ( source :: append ) . onParam ( this :: add ) . parse ( fmt ) ; return this ; } | Appends formatted text to the source . |
21,857 | public SourceBuilder addLine ( String fmt , Object ... args ) { add ( fmt , args ) ; source . append ( LINE_SEPARATOR ) ; return this ; } | Appends a formatted line of code to the source . |
21,858 | private Map < StandardMethod , UnderrideLevel > findUnderriddenMethods ( Iterable < ExecutableElement > methods ) { Map < StandardMethod , ExecutableElement > standardMethods = new LinkedHashMap < > ( ) ; for ( ExecutableElement method : methods ) { Optional < StandardMethod > standardMethod = maybeStandardMethod ( method ) ; if ( standardMethod . isPresent ( ) && isUnderride ( method ) ) { standardMethods . put ( standardMethod . get ( ) , method ) ; } } if ( standardMethods . containsKey ( StandardMethod . EQUALS ) != standardMethods . containsKey ( StandardMethod . HASH_CODE ) ) { ExecutableElement underriddenMethod = standardMethods . containsKey ( StandardMethod . EQUALS ) ? standardMethods . get ( StandardMethod . EQUALS ) : standardMethods . get ( StandardMethod . HASH_CODE ) ; messager . printMessage ( ERROR , "hashCode and equals must be implemented together on FreeBuilder types" , underriddenMethod ) ; } ImmutableMap . Builder < StandardMethod , UnderrideLevel > result = ImmutableMap . builder ( ) ; for ( StandardMethod standardMethod : standardMethods . keySet ( ) ) { if ( standardMethods . get ( standardMethod ) . getModifiers ( ) . contains ( Modifier . FINAL ) ) { result . put ( standardMethod , UnderrideLevel . FINAL ) ; } else { result . put ( standardMethod , UnderrideLevel . OVERRIDEABLE ) ; } } return result . build ( ) ; } | Find any standard methods the user has underridden in their type . |
21,859 | private boolean hasToBuilderMethod ( DeclaredType builder , boolean isExtensible , Iterable < ExecutableElement > methods ) { for ( ExecutableElement method : methods ) { if ( isToBuilderMethod ( builder , method ) ) { if ( ! isExtensible ) { messager . printMessage ( ERROR , "No accessible no-args Builder constructor available to implement toBuilder" , method ) ; } return true ; } } return false ; } | Find a toBuilder method if the user has provided one . |
21,860 | private String generatedBuilderSimpleName ( TypeElement type ) { String packageName = elements . getPackageOf ( type ) . getQualifiedName ( ) . toString ( ) ; String originalName = type . getQualifiedName ( ) . toString ( ) ; checkState ( originalName . startsWith ( packageName + "." ) ) ; String nameWithoutPackage = originalName . substring ( packageName . length ( ) + 1 ) ; return String . format ( BUILDER_SIMPLE_NAME_TEMPLATE , nameWithoutPackage . replaceAll ( "\\." , "_" ) ) ; } | Returns the simple name of the builder class that should be generated for the given type . |
21,861 | public static void addToString ( SourceBuilder code , Datatype datatype , Map < Property , PropertyCodeGenerator > generatorsByProperty , boolean forPartial ) { String typename = ( forPartial ? "partial " : "" ) + datatype . getType ( ) . getSimpleName ( ) ; Predicate < PropertyCodeGenerator > isOptional = generator -> { Initially initially = generator . initialState ( ) ; return ( initially == Initially . OPTIONAL || ( initially == Initially . REQUIRED && forPartial ) ) ; } ; boolean anyOptional = generatorsByProperty . values ( ) . stream ( ) . anyMatch ( isOptional ) ; boolean allOptional = generatorsByProperty . values ( ) . stream ( ) . allMatch ( isOptional ) && ! generatorsByProperty . isEmpty ( ) ; code . addLine ( "" ) . addLine ( "@%s" , Override . class ) . addLine ( "public %s toString() {" , String . class ) ; if ( allOptional ) { bodyWithBuilderAndSeparator ( code , datatype , generatorsByProperty , typename ) ; } else if ( anyOptional ) { bodyWithBuilder ( code , datatype , generatorsByProperty , typename , isOptional ) ; } else { bodyWithConcatenation ( code , generatorsByProperty , typename ) ; } code . addLine ( "}" ) ; } | Generates a toString method using concatenation or a StringBuilder . |
21,862 | private static void bodyWithConcatenation ( SourceBuilder code , Map < Property , PropertyCodeGenerator > generatorsByProperty , String typename ) { code . add ( " return \"%s{" , typename ) ; String prefix = "" ; for ( Property property : generatorsByProperty . keySet ( ) ) { PropertyCodeGenerator generator = generatorsByProperty . get ( property ) ; code . add ( "%s%s=\" + %s + \"" , prefix , property . getName ( ) , ( Excerpt ) generator :: addToStringValue ) ; prefix = ", " ; } code . add ( "}\";%n" ) ; } | Generate the body of a toString method that uses plain concatenation . |
21,863 | private static void bodyWithBuilder ( SourceBuilder code , Datatype datatype , Map < Property , PropertyCodeGenerator > generatorsByProperty , String typename , Predicate < PropertyCodeGenerator > isOptional ) { Variable result = new Variable ( "result" ) ; code . add ( " %1$s %2$s = new %1$s(\"%3$s{" , StringBuilder . class , result , typename ) ; boolean midStringLiteral = true ; boolean midAppends = true ; boolean prependCommas = false ; PropertyCodeGenerator lastOptionalGenerator = generatorsByProperty . values ( ) . stream ( ) . filter ( isOptional ) . reduce ( ( first , second ) -> second ) . get ( ) ; for ( Property property : generatorsByProperty . keySet ( ) ) { PropertyCodeGenerator generator = generatorsByProperty . get ( property ) ; if ( isOptional . test ( generator ) ) { if ( midStringLiteral ) { code . add ( "\")" ) ; } if ( midAppends ) { code . add ( ";%n " ) ; } code . add ( "if (" ) ; if ( generator . initialState ( ) == Initially . OPTIONAL ) { generator . addToStringCondition ( code ) ; } else { code . add ( "!%s.contains(%s.%s)" , UNSET_PROPERTIES , datatype . getPropertyEnum ( ) , property . getAllCapsName ( ) ) ; } code . add ( ") {%n %s.append(\"" , result ) ; if ( prependCommas ) { code . add ( ", " ) ; } code . add ( "%s=\").append(%s)" , property . getName ( ) , property . getField ( ) ) ; if ( ! prependCommas ) { code . add ( ".append(\", \")" ) ; } code . add ( ";%n }%n " ) ; if ( generator . equals ( lastOptionalGenerator ) ) { code . add ( "return %s.append(\"" , result ) ; midStringLiteral = true ; midAppends = true ; } else { midStringLiteral = false ; midAppends = false ; } } else { if ( ! midAppends ) { code . add ( "%s" , result ) ; } if ( ! midStringLiteral ) { code . add ( ".append(\"" ) ; } if ( prependCommas ) { code . add ( ", " ) ; } code . add ( "%s=\").append(%s)" , property . getName ( ) , ( Excerpt ) generator :: addToStringValue ) ; midStringLiteral = false ; midAppends = true ; prependCommas = true ; } } checkState ( prependCommas , "Unexpected state at end of toString method" ) ; checkState ( midAppends , "Unexpected state at end of toString method" ) ; if ( ! midStringLiteral ) { code . add ( ".append(\"" ) ; } code . add ( "}\").toString();%n" , result ) ; } | Generates the body of a toString method that uses a StringBuilder . |
21,864 | private static void bodyWithBuilderAndSeparator ( SourceBuilder code , Datatype datatype , Map < Property , PropertyCodeGenerator > generatorsByProperty , String typename ) { Variable result = new Variable ( "result" ) ; Variable separator = new Variable ( "separator" ) ; code . addLine ( " %1$s %2$s = new %1$s(\"%3$s{\");" , StringBuilder . class , result , typename ) ; if ( generatorsByProperty . size ( ) > 1 ) { code . addLine ( " %s %s = \"\";" , String . class , separator ) ; } Property first = generatorsByProperty . keySet ( ) . iterator ( ) . next ( ) ; Property last = getLast ( generatorsByProperty . keySet ( ) ) ; for ( Property property : generatorsByProperty . keySet ( ) ) { PropertyCodeGenerator generator = generatorsByProperty . get ( property ) ; switch ( generator . initialState ( ) ) { case HAS_DEFAULT : throw new RuntimeException ( "Internal error: unexpected default field" ) ; case OPTIONAL : code . addLine ( " if (%s) {" , ( Excerpt ) generator :: addToStringCondition ) ; break ; case REQUIRED : code . addLine ( " if (!%s.contains(%s.%s)) {" , UNSET_PROPERTIES , datatype . getPropertyEnum ( ) , property . getAllCapsName ( ) ) ; break ; } code . add ( " " ) . add ( result ) ; if ( property != first ) { code . add ( ".append(%s)" , separator ) ; } code . add ( ".append(\"%s=\").append(%s)" , property . getName ( ) , ( Excerpt ) generator :: addToStringValue ) ; if ( property != last ) { code . add ( ";%n %s = \", \"" , separator ) ; } code . add ( ";%n }%n" ) ; } code . addLine ( " return %s.append(\"}\").toString();" , result ) ; } | Generates the body of a toString method that uses a StringBuilder and a separator variable . |
21,865 | public static void addLazyDefinitions ( SourceBuilder code ) { Set < Declaration > defined = new HashSet < > ( ) ; List < Declaration > declarations = code . scope ( ) . keysOfType ( Declaration . class ) . stream ( ) . sorted ( ) . collect ( toList ( ) ) ; while ( ! defined . containsAll ( declarations ) ) { for ( Declaration declaration : declarations ) { if ( defined . add ( declaration ) ) { code . add ( code . scope ( ) . get ( declaration ) . definition ) ; } } declarations = code . scope ( ) . keysOfType ( Declaration . class ) . stream ( ) . sorted ( ) . collect ( toList ( ) ) ; } } | Finds all lazily - declared classes and methods and adds their definitions to the source . |
21,866 | public void addPartialFieldAssignment ( SourceBuilder code , Excerpt finalField , String builder ) { addFinalFieldAssignment ( code , finalField , builder ) ; } | Add the final assignment of the property to the partial value object s source code . |
21,867 | public static void addActionsTo ( SourceBuilder code , Set < MergeAction > mergeActions , boolean forBuilder ) { SetMultimap < String , String > nounsByVerb = TreeMultimap . create ( ) ; mergeActions . forEach ( mergeAction -> { if ( forBuilder || ! mergeAction . builderOnly ) { nounsByVerb . put ( mergeAction . verb , mergeAction . noun ) ; } } ) ; List < String > verbs = ImmutableList . copyOf ( nounsByVerb . keySet ( ) ) ; String lastVerb = getLast ( verbs , null ) ; for ( String verb : nounsByVerb . keySet ( ) ) { code . add ( ", %s%s" , ( verbs . size ( ) > 1 && verb . equals ( lastVerb ) ) ? "and " : "" , verb ) ; List < String > nouns = ImmutableList . copyOf ( nounsByVerb . get ( verb ) ) ; for ( int i = 0 ; i < nouns . size ( ) ; ++ i ) { String separator = ( i == 0 ) ? "" : ( i == nouns . size ( ) - 1 ) ? " and" : "," ; code . add ( "%s %s" , separator , nouns . get ( i ) ) ; } } } | Emits a sentence fragment combining all the merge actions . |
21,868 | public static Variable upcastToGeneratedBuilder ( SourceBuilder code , Datatype datatype , String builder ) { return code . scope ( ) . computeIfAbsent ( Declaration . UPCAST , ( ) -> { Variable base = new Variable ( "base" ) ; code . addLine ( UPCAST_COMMENT ) . addLine ( "%s %s = %s;" , datatype . getGeneratedBuilder ( ) , base , builder ) ; return base ; } ) ; } | Upcasts a Builder instance to the generated superclass to allow access to private fields . |
21,869 | public static Optional < Variable > freshBuilder ( SourceBuilder code , Datatype datatype ) { if ( ! datatype . getBuilderFactory ( ) . isPresent ( ) ) { return Optional . empty ( ) ; } return Optional . of ( code . scope ( ) . computeIfAbsent ( Declaration . FRESH_BUILDER , ( ) -> { Variable defaults = new Variable ( "defaults" ) ; code . addLine ( "%s %s = %s;" , datatype . getGeneratedBuilder ( ) , defaults , datatype . getBuilderFactory ( ) . get ( ) . newBuilder ( datatype . getBuilder ( ) , TypeInference . INFERRED_TYPES ) ) ; return defaults ; } ) ) ; } | Declares a fresh Builder to copy default property values from . |
21,870 | public JavadocLink javadocMethodLink ( String memberName , Type ... types ) { return new JavadocLink ( "%s#%s(%s)" , getQualifiedName ( ) , memberName , ( Excerpt ) code -> { String separator = "" ; for ( Type type : types ) { code . add ( "%s%s" , separator , type . getQualifiedName ( ) ) ; separator = ", " ; } } ) ; } | Returns a source excerpt of a JavaDoc link to a method on this type . |
21,871 | public Excerpt typeParameters ( ) { if ( getTypeParameters ( ) . isEmpty ( ) ) { return Excerpts . EMPTY ; } else { return Excerpts . add ( "<%s>" , Excerpts . join ( ", " , getTypeParameters ( ) ) ) ; } } | Returns a source excerpt of the type parameters of this type including angle brackets . Always an empty string if the type class is not generic . |
21,872 | protected Violation createViolation ( Integer lineNumber , String sourceLine , String message ) { Violation violation = new Violation ( ) ; violation . setRule ( this ) ; violation . setSourceLine ( sourceLine ) ; violation . setLineNumber ( lineNumber ) ; violation . setMessage ( message ) ; return violation ; } | Create and return a new Violation for this rule and the specified values |
21,873 | protected Violation createViolation ( SourceCode sourceCode , ASTNode node , String message ) { String sourceLine = sourceCode . line ( node . getLineNumber ( ) - 1 ) ; return createViolation ( node . getLineNumber ( ) , sourceLine , message ) ; } | Create a new Violation for the AST node . |
21,874 | protected Violation createViolationForImport ( SourceCode sourceCode , ImportNode importNode , String message ) { Map importInfo = ImportUtil . sourceLineAndNumberForImport ( sourceCode , importNode ) ; Violation violation = new Violation ( ) ; violation . setRule ( this ) ; violation . setSourceLine ( ( String ) importInfo . get ( "sourceLine" ) ) ; violation . setLineNumber ( ( Integer ) importInfo . get ( "lineNumber" ) ) ; violation . setMessage ( message ) ; return violation ; } | Create and return a new Violation for this rule and the specified import |
21,875 | protected Violation createViolationForImport ( SourceCode sourceCode , String className , String alias , String violationMessage ) { Map importInfo = ImportUtil . sourceLineAndNumberForImport ( sourceCode , className , alias ) ; Violation violation = new Violation ( ) ; violation . setRule ( this ) ; violation . setSourceLine ( ( String ) importInfo . get ( "sourceLine" ) ) ; violation . setLineNumber ( ( Integer ) importInfo . get ( "lineNumber" ) ) ; violation . setMessage ( violationMessage ) ; return violation ; } | Create and return a new Violation for this rule and the specified import className and alias |
21,876 | protected boolean shouldApplyThisRuleTo ( ClassNode classNode ) { boolean shouldApply = true ; String applyTo = getApplyToClassNames ( ) ; String doNotApplyTo = getDoNotApplyToClassNames ( ) ; if ( applyTo != null && applyTo . length ( ) > 0 ) { WildcardPattern pattern = new WildcardPattern ( applyTo , true ) ; shouldApply = pattern . matches ( classNode . getNameWithoutPackage ( ) ) || pattern . matches ( classNode . getName ( ) ) ; } if ( shouldApply && doNotApplyTo != null && doNotApplyTo . length ( ) > 0 ) { WildcardPattern pattern = new WildcardPattern ( doNotApplyTo , true ) ; shouldApply = ! pattern . matches ( classNode . getNameWithoutPackage ( ) ) && ! pattern . matches ( classNode . getName ( ) ) ; } return shouldApply ; } | Return true if this rule should be applied for the specified ClassNode based on the configuration of this rule . |
21,877 | public Results analyze ( RuleSet ruleSet ) { long startTime = System . currentTimeMillis ( ) ; DirectoryResults reportResults = new DirectoryResults ( ) ; int numThreads = Runtime . getRuntime ( ) . availableProcessors ( ) - 1 ; numThreads = numThreads > 0 ? numThreads : 1 ; ExecutorService pool = Executors . newFixedThreadPool ( numThreads ) ; for ( FileSet fileSet : fileSets ) { processFileSet ( fileSet , ruleSet , pool ) ; } pool . shutdown ( ) ; try { boolean completed = pool . awaitTermination ( POOL_TIMEOUT_SECONDS , TimeUnit . SECONDS ) ; if ( ! completed ) { throw new IllegalStateException ( "Thread Pool terminated before comp<FileResults>letion" ) ; } } catch ( InterruptedException e ) { throw new IllegalStateException ( "Thread Pool interrupted before completion" ) ; } addDirectoryResults ( reportResults ) ; LOG . info ( "Analysis time=" + ( System . currentTimeMillis ( ) - startTime ) + "ms" ) ; return reportResults ; } | Analyze all source code using the specified RuleSet and return the report results . |
21,878 | private static boolean isPredefinedConstant ( Expression expression ) { if ( expression instanceof PropertyExpression ) { Expression object = ( ( PropertyExpression ) expression ) . getObjectExpression ( ) ; Expression property = ( ( PropertyExpression ) expression ) . getProperty ( ) ; if ( object instanceof VariableExpression ) { List < String > predefinedConstantNames = PREDEFINED_CONSTANTS . get ( ( ( VariableExpression ) object ) . getName ( ) ) ; if ( predefinedConstantNames != null && predefinedConstantNames . contains ( property . getText ( ) ) ) { return true ; } } } return false ; } | Tells you if the expression is a predefined constant like TRUE or FALSE . |
21,879 | public static boolean isMapLiteralWithOnlyConstantValues ( Expression expression ) { if ( expression instanceof MapExpression ) { List < MapEntryExpression > entries = ( ( MapExpression ) expression ) . getMapEntryExpressions ( ) ; for ( MapEntryExpression entry : entries ) { if ( ! isConstantOrConstantLiteral ( entry . getKeyExpression ( ) ) || ! isConstantOrConstantLiteral ( entry . getValueExpression ( ) ) ) { return false ; } } return true ; } return false ; } | Returns true if a Map literal that contains only entries where both key and value are constants . |
21,880 | public static boolean isListLiteralWithOnlyConstantValues ( Expression expression ) { if ( expression instanceof ListExpression ) { List < Expression > expressions = ( ( ListExpression ) expression ) . getExpressions ( ) ; for ( Expression e : expressions ) { if ( ! isConstantOrConstantLiteral ( e ) ) { return false ; } } return true ; } return false ; } | Returns true if a List literal that contains only entries that are constants . |
21,881 | public static boolean isConstant ( Expression expression , Object expected ) { return expression instanceof ConstantExpression && expected . equals ( ( ( ConstantExpression ) expression ) . getValue ( ) ) ; } | Tells you if an expression is the expected constant . |
21,882 | public static List < ? extends Expression > getMethodArguments ( ASTNode methodCall ) { if ( methodCall instanceof ConstructorCallExpression ) { return extractExpressions ( ( ( ConstructorCallExpression ) methodCall ) . getArguments ( ) ) ; } else if ( methodCall instanceof MethodCallExpression ) { return extractExpressions ( ( ( MethodCallExpression ) methodCall ) . getArguments ( ) ) ; } else if ( methodCall instanceof StaticMethodCallExpression ) { return extractExpressions ( ( ( StaticMethodCallExpression ) methodCall ) . getArguments ( ) ) ; } else if ( respondsTo ( methodCall , "getArguments" ) ) { throw new RuntimeException ( ) ; } return new ArrayList < Expression > ( ) ; } | Return the List of Arguments for the specified MethodCallExpression or a ConstructorCallExpression . The returned List contains either ConstantExpression or MapEntryExpression objects . |
21,883 | public static boolean isMethodNamed ( MethodCallExpression methodCall , String methodNamePattern , Integer numArguments ) { Expression method = methodCall . getMethod ( ) ; boolean IS_NAME_MATCH = false ; if ( method instanceof ConstantExpression ) { if ( ( ( ConstantExpression ) method ) . getValue ( ) instanceof String ) { IS_NAME_MATCH = ( ( String ) ( ( ConstantExpression ) method ) . getValue ( ) ) . matches ( methodNamePattern ) ; } } if ( IS_NAME_MATCH && numArguments != null ) { return AstUtil . getMethodArguments ( methodCall ) . size ( ) == numArguments ; } return IS_NAME_MATCH ; } | Return true only if the MethodCallExpression represents a method call for the specified method name |
21,884 | public static boolean isConstructorCall ( Expression expression , List < String > classNames ) { return expression instanceof ConstructorCallExpression && classNames . contains ( expression . getType ( ) . getName ( ) ) ; } | Return true if the expression is a constructor call on any of the named classes with any number of parameters . |
21,885 | public static boolean isConstructorCall ( Expression expression , String classNamePattern ) { return expression instanceof ConstructorCallExpression && expression . getType ( ) . getName ( ) . matches ( classNamePattern ) ; } | Return true if the expression is a constructor call on a class that matches the supplied . |
21,886 | public static AnnotationNode getAnnotation ( AnnotatedNode node , String name ) { List < AnnotationNode > annotations = node . getAnnotations ( ) ; for ( AnnotationNode annot : annotations ) { if ( annot . getClassNode ( ) . getName ( ) . equals ( name ) ) { return annot ; } } return null ; } | Return the AnnotationNode for the named annotation or else null . Supports Groovy 1 . 5 and Groovy 1 . 6 . |
21,887 | public static boolean hasAnnotation ( AnnotatedNode node , String name ) { return AstUtil . getAnnotation ( node , name ) != null ; } | Return true only if the node has the named annotation |
21,888 | public static boolean hasAnyAnnotation ( AnnotatedNode node , String ... names ) { for ( String name : names ) { if ( hasAnnotation ( node , name ) ) { return true ; } } return false ; } | Return true only if the node has any of the named annotations |
21,889 | public static List < Expression > getVariableExpressions ( DeclarationExpression declarationExpression ) { Expression leftExpression = declarationExpression . getLeftExpression ( ) ; if ( leftExpression instanceof ArrayExpression ) { List < Expression > expressions = ( ( ArrayExpression ) leftExpression ) . getExpressions ( ) ; return expressions . isEmpty ( ) ? Arrays . asList ( leftExpression ) : expressions ; } else if ( leftExpression instanceof ListExpression ) { List < Expression > expressions = ( ( ListExpression ) leftExpression ) . getExpressions ( ) ; return expressions . isEmpty ( ) ? Arrays . asList ( leftExpression ) : expressions ; } else if ( leftExpression instanceof TupleExpression ) { List < Expression > expressions = ( ( TupleExpression ) leftExpression ) . getExpressions ( ) ; return expressions . isEmpty ( ) ? Arrays . asList ( leftExpression ) : expressions ; } else if ( leftExpression instanceof VariableExpression ) { return Arrays . asList ( leftExpression ) ; } return Collections . emptyList ( ) ; } | Return the List of VariableExpression objects referenced by the specified DeclarationExpression . |
21,890 | public static boolean isFinalVariable ( DeclarationExpression declarationExpression , SourceCode sourceCode ) { if ( isFromGeneratedSourceCode ( declarationExpression ) ) { return false ; } List < Expression > variableExpressions = getVariableExpressions ( declarationExpression ) ; if ( ! variableExpressions . isEmpty ( ) ) { Expression variableExpression = variableExpressions . get ( 0 ) ; int startOfDeclaration = declarationExpression . getColumnNumber ( ) ; int startOfVariableName = variableExpression . getColumnNumber ( ) ; int sourceLineNumber = findFirstNonAnnotationLine ( declarationExpression , sourceCode ) ; String sourceLine = sourceCode . getLines ( ) . get ( sourceLineNumber - 1 ) ; String modifiers = ( startOfDeclaration >= 0 && startOfVariableName >= 0 && sourceLine . length ( ) >= startOfVariableName ) ? sourceLine . substring ( startOfDeclaration - 1 , startOfVariableName - 1 ) : "" ; return modifiers . contains ( "final" ) ; } return false ; } | Return true if the DeclarationExpression represents a final variable declaration . |
21,891 | public static boolean isTrue ( Expression expression ) { if ( expression == null ) { return false ; } if ( expression instanceof PropertyExpression && classNodeImplementsType ( ( ( PropertyExpression ) expression ) . getObjectExpression ( ) . getType ( ) , Boolean . class ) ) { if ( ( ( PropertyExpression ) expression ) . getProperty ( ) instanceof ConstantExpression && "TRUE" . equals ( ( ( ConstantExpression ) ( ( PropertyExpression ) expression ) . getProperty ( ) ) . getValue ( ) ) ) { return true ; } } return ( ( expression instanceof ConstantExpression ) && ( ( ConstantExpression ) expression ) . isTrueExpression ( ) ) || "Boolean.TRUE" . equals ( expression . getText ( ) ) ; } | Tells you if the expression is true which can be true or Boolean . TRUE . |
21,892 | public static boolean isFalse ( Expression expression ) { if ( expression == null ) { return false ; } if ( expression instanceof PropertyExpression && classNodeImplementsType ( ( ( PropertyExpression ) expression ) . getObjectExpression ( ) . getType ( ) , Boolean . class ) ) { if ( ( ( PropertyExpression ) expression ) . getProperty ( ) instanceof ConstantExpression && "FALSE" . equals ( ( ( ConstantExpression ) ( ( PropertyExpression ) expression ) . getProperty ( ) ) . getValue ( ) ) ) { return true ; } } return ( ( expression instanceof ConstantExpression ) && ( ( ConstantExpression ) expression ) . isFalseExpression ( ) ) || "Boolean.FALSE" . equals ( expression . getText ( ) ) ; } | Tells you if the expression is the false expression either literal or constant . |
21,893 | public static boolean respondsTo ( Object object , String methodName ) { MetaClass metaClass = DefaultGroovyMethods . getMetaClass ( object ) ; if ( ! metaClass . respondsTo ( object , methodName ) . isEmpty ( ) ) { return true ; } Map properties = DefaultGroovyMethods . getProperties ( object ) ; return properties . containsKey ( methodName ) ; } | Return true only if the specified object responds to the named method |
21,894 | public static boolean classNodeImplementsType ( ClassNode node , Class target ) { ClassNode targetNode = ClassHelper . make ( target ) ; if ( node . implementsInterface ( targetNode ) ) { return true ; } if ( node . isDerivedFrom ( targetNode ) ) { return true ; } if ( node . getName ( ) . equals ( target . getName ( ) ) ) { return true ; } if ( node . getName ( ) . equals ( target . getSimpleName ( ) ) ) { return true ; } if ( node . getSuperClass ( ) != null && node . getSuperClass ( ) . getName ( ) . equals ( target . getName ( ) ) ) { return true ; } if ( node . getSuperClass ( ) != null && node . getSuperClass ( ) . getName ( ) . equals ( target . getSimpleName ( ) ) ) { return true ; } if ( node . getInterfaces ( ) != null ) { for ( ClassNode declaredInterface : node . getInterfaces ( ) ) { if ( classNodeImplementsType ( declaredInterface , target ) ) { return true ; } } } return false ; } | This method tells you if a ClassNode implements or extends a certain class . |
21,895 | public static boolean isClosureDeclaration ( ASTNode expression ) { if ( expression instanceof DeclarationExpression ) { if ( ( ( DeclarationExpression ) expression ) . getRightExpression ( ) instanceof ClosureExpression ) { return true ; } } if ( expression instanceof FieldNode ) { ClassNode type = ( ( FieldNode ) expression ) . getType ( ) ; if ( AstUtil . classNodeImplementsType ( type , Closure . class ) ) { return true ; } else if ( ( ( FieldNode ) expression ) . getInitialValueExpression ( ) instanceof ClosureExpression ) { return true ; } } return false ; } | Returns true if the ASTNode is a declaration of a closure either as a declaration or a field . |
21,896 | public static List < String > getParameterNames ( MethodNode node ) { ArrayList < String > result = new ArrayList < String > ( ) ; if ( node . getParameters ( ) != null ) { for ( Parameter parameter : node . getParameters ( ) ) { result . add ( parameter . getName ( ) ) ; } } return result ; } | Gets the parameter names of a method node . |
21,897 | public static List < String > getArgumentNames ( MethodCallExpression methodCall ) { ArrayList < String > result = new ArrayList < String > ( ) ; Expression arguments = methodCall . getArguments ( ) ; List < Expression > argExpressions = null ; if ( arguments instanceof ArrayExpression ) { argExpressions = ( ( ArrayExpression ) arguments ) . getExpressions ( ) ; } else if ( arguments instanceof ListExpression ) { argExpressions = ( ( ListExpression ) arguments ) . getExpressions ( ) ; } else if ( arguments instanceof TupleExpression ) { argExpressions = ( ( TupleExpression ) arguments ) . getExpressions ( ) ; } else { LOG . warn ( "getArgumentNames arguments is not an expected type" ) ; } if ( argExpressions != null ) { for ( Expression exp : argExpressions ) { if ( exp instanceof VariableExpression ) { result . add ( ( ( VariableExpression ) exp ) . getName ( ) ) ; } } } return result ; } | Gets the argument names of a method call . If the arguments are not VariableExpressions then a null will be returned . |
21,898 | public static boolean isSafe ( Expression expression ) { if ( expression instanceof MethodCallExpression ) { return ( ( MethodCallExpression ) expression ) . isSafe ( ) ; } if ( expression instanceof PropertyExpression ) { return ( ( PropertyExpression ) expression ) . isSafe ( ) ; } return false ; } | Tells you if the expression is a null safe dereference . |
21,899 | public static boolean isSpreadSafe ( Expression expression ) { if ( expression instanceof MethodCallExpression ) { return ( ( MethodCallExpression ) expression ) . isSpreadSafe ( ) ; } if ( expression instanceof PropertyExpression ) { return ( ( PropertyExpression ) expression ) . isSpreadSafe ( ) ; } return false ; } | Tells you if the expression is a spread operator call |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.