idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
32,500 | public String getRootCauseMessage ( ) { String rcmessage = null ; if ( getRootCause ( ) != null ) { if ( getRootCause ( ) . getCause ( ) != null ) { rcmessage = getRootCause ( ) . getCause ( ) . getMessage ( ) ; } rcmessage = rcmessage == null ? getRootCause ( ) . getMessage ( ) : rcmessage ; rcmessage = rcmessage == null ? super . getMessage ( ) : rcmessage ; rcmessage = rcmessage == null ? "NONE" : rcmessage ; } return rcmessage ; } | Get root cause message . | 136 | 5 |
32,501 | public String getHrefResolved ( ) { if ( Atom10Parser . isAbsoluteURI ( href ) ) { return href ; } else if ( baseURI != null && categoriesElement != null ) { return Atom10Parser . resolveURI ( baseURI , categoriesElement , href ) ; } return null ; } | Get unresolved URI of the collection or null if impossible to determine | 65 | 12 |
32,502 | public static < T > List < T > createWhenNull ( final List < T > list ) { if ( list == null ) { return new ArrayList < T > ( ) ; } else { return list ; } } | Returns the list when it is not null . Returns a new list otherwise . | 46 | 15 |
32,503 | public static < T > List < T > create ( final T item ) { final List < T > list = new ArrayList < T > ( ) ; list . add ( item ) ; return list ; } | Creates a new List with the given item as the first entry . | 43 | 14 |
32,504 | public static < T > T firstEntry ( final List < T > list ) { if ( list != null && ! list . isEmpty ( ) ) { return list . get ( 0 ) ; } else { return null ; } } | Extracts the first entry of the list when it is not null and contains values . | 48 | 18 |
32,505 | public static boolean sizeIs ( final List < ? > list , final int size ) { if ( size == 0 ) { return list == null || list . isEmpty ( ) ; } else { return list != null && list . size ( ) == size ; } } | Checks whether the list has the given size . A null list is treated like a list without entries . | 55 | 21 |
32,506 | public static < T > List < T > emptyToNull ( final List < T > list ) { if ( isEmpty ( list ) ) { return null ; } else { return list ; } } | Returns null when the given list is empty or null | 41 | 10 |
32,507 | public static Long parseLong ( final String str ) { if ( null != str ) { try { return new Long ( Long . parseLong ( str . trim ( ) ) ) ; } catch ( final Exception e ) { // :IGNORE: } } return null ; } | Parses a Long out of a string . | 56 | 10 |
32,508 | public static Float parseFloat ( final String str ) { if ( null != str ) { try { return new Float ( Float . parseFloat ( str . trim ( ) ) ) ; } catch ( final Exception e ) { // :IGNORE: } } return null ; } | Parse a Float from a String without exceptions . If the String is not a Float then null is returned | 56 | 21 |
32,509 | public static float parseFloat ( final String str , final float def ) { final Float result = parseFloat ( str ) ; if ( result == null ) { return def ; } else { return result . floatValue ( ) ; } } | Parse a float from a String with a default value | 48 | 11 |
32,510 | public static long parseLong ( final String str , final long def ) { final Long ret = parseLong ( str ) ; if ( ret == null ) { return def ; } else { return ret . longValue ( ) ; } } | Parses a long out of a string . | 48 | 10 |
32,511 | public static PropertiesLoader getPropertiesLoader ( ) { synchronized ( PropertiesLoader . class ) { final ClassLoader classLoader = ConfigurableClassLoader . INSTANCE . getClassLoader ( ) ; PropertiesLoader loader = clMap . get ( classLoader ) ; if ( loader == null ) { try { loader = new PropertiesLoader ( MASTER_PLUGIN_FILE , EXTRA_PLUGIN_FILE ) ; clMap . put ( classLoader , loader ) ; } catch ( final IOException ex ) { throw new RuntimeException ( ex ) ; } } return loader ; } } | Returns the PropertiesLoader singleton used by ROME to load plugin components . | 121 | 15 |
32,512 | public static void serializeEntry ( final Entry entry , final Writer writer ) throws IllegalArgumentException , FeedException , IOException { // Build a feed containing only the entry final List < Entry > entries = new ArrayList < Entry > ( ) ; entries . add ( entry ) ; final Feed feed1 = new Feed ( ) ; feed1 . setFeedType ( "atom_1.0" ) ; feed1 . setEntries ( entries ) ; // Get Rome to output feed as a JDOM document final WireFeedOutput wireFeedOutput = new WireFeedOutput ( ) ; final Document feedDoc = wireFeedOutput . outputJDom ( feed1 ) ; // Grab entry element from feed and get JDOM to serialize it final Element entryElement = feedDoc . getRootElement ( ) . getChildren ( ) . get ( 0 ) ; final XMLOutputter outputter = new XMLOutputter ( ) ; outputter . output ( entryElement , writer ) ; } | Utility method to serialize an entry to writer . | 201 | 11 |
32,513 | @ Override public SyndFeed retrieveFeed ( final String userAgent , final URL feedUrl ) throws IllegalArgumentException , IOException , FeedException , FetcherException { if ( feedUrl == null ) { throw new IllegalArgumentException ( "null is not a valid URL" ) ; } final URLConnection connection = feedUrl . openConnection ( ) ; if ( ! ( connection instanceof HttpURLConnection ) ) { throw new IllegalArgumentException ( feedUrl . toExternalForm ( ) + " is not a valid HTTP Url" ) ; } final HttpURLConnection httpConnection = ( HttpURLConnection ) connection ; if ( connectTimeout >= 0 ) { httpConnection . setConnectTimeout ( connectTimeout ) ; } // httpConnection.setInstanceFollowRedirects(true); // this is true by default, but can be // changed on a claswide basis final FeedFetcherCache cache = getFeedInfoCache ( ) ; if ( cache != null ) { SyndFeedInfo syndFeedInfo = cache . getFeedInfo ( feedUrl ) ; setRequestHeaders ( connection , syndFeedInfo , userAgent ) ; httpConnection . connect ( ) ; try { fireEvent ( FetcherEvent . EVENT_TYPE_FEED_POLLED , connection ) ; if ( syndFeedInfo == null ) { // this is a feed that hasn't been retrieved syndFeedInfo = new SyndFeedInfo ( ) ; retrieveAndCacheFeed ( feedUrl , syndFeedInfo , httpConnection ) ; } else { // check the response code final int responseCode = httpConnection . getResponseCode ( ) ; if ( responseCode != HttpURLConnection . HTTP_NOT_MODIFIED ) { // the response code is not 304 NOT MODIFIED // This is either because the feed server // does not support condition gets // or because the feed hasn't changed retrieveAndCacheFeed ( feedUrl , syndFeedInfo , httpConnection ) ; } else { // the feed does not need retrieving fireEvent ( FetcherEvent . EVENT_TYPE_FEED_UNCHANGED , connection ) ; } } return syndFeedInfo . getSyndFeed ( ) ; } finally { httpConnection . disconnect ( ) ; } } else { fireEvent ( FetcherEvent . EVENT_TYPE_FEED_POLLED , connection ) ; InputStream inputStream = null ; setRequestHeaders ( connection , null , userAgent ) ; httpConnection . connect ( ) ; try { inputStream = httpConnection . getInputStream ( ) ; return getSyndFeedFromStream ( inputStream , connection ) ; } catch ( final java . io . IOException e ) { handleErrorCodes ( ( ( HttpURLConnection ) connection ) . getResponseCode ( ) ) ; } finally { IO . close ( inputStream ) ; httpConnection . disconnect ( ) ; } // we will never actually get to this line return null ; } } | Retrieve a feed over HTTP | 604 | 6 |
32,514 | private static Object newInstance ( final String className , ClassLoader cl , final boolean doFallback ) throws ConfigurationError { try { Class < ? > providerClass ; if ( cl == null ) { // If classloader is null Use the bootstrap ClassLoader. // Thus Class.forName(String) will use the current // ClassLoader which will be the bootstrap ClassLoader. providerClass = Class . forName ( className ) ; } else { try { providerClass = cl . loadClass ( className ) ; } catch ( final ClassNotFoundException x ) { if ( doFallback ) { // Fall back to current classloader cl = FactoryFinder . class . getClassLoader ( ) ; providerClass = cl . loadClass ( className ) ; } else { throw x ; } } } final Object instance = providerClass . newInstance ( ) ; dPrint ( "created new instance of " + providerClass + " using ClassLoader: " + cl ) ; return instance ; } catch ( final ClassNotFoundException x ) { throw new ConfigurationError ( "Provider " + className + " not found" , x ) ; } catch ( final Exception x ) { throw new ConfigurationError ( "Provider " + className + " could not be instantiated: " + x , x ) ; } } | Create an instance of a class using the specified ClassLoader and optionally fall back to the current ClassLoader if not found . | 273 | 24 |
32,515 | static Object find ( final String factoryId , final String fallbackClassName ) throws ConfigurationError { // Figure out which ClassLoader to use for loading the provider // class. If there is a Context ClassLoader then use it. ClassLoader classLoader = ss . getContextClassLoader ( ) ; if ( classLoader == null ) { // if we have no Context ClassLoader // so use the current ClassLoader classLoader = FactoryFinder . class . getClassLoader ( ) ; } dPrint ( "find factoryId =" + factoryId ) ; // Use the system property first try { final String systemProp = ss . getSystemProperty ( factoryId ) ; if ( systemProp != null ) { dPrint ( "found system property, value=" + systemProp ) ; return newInstance ( systemProp , classLoader , true ) ; } } catch ( final SecurityException se ) { // if first option fails due to any reason we should try next option in the // look up algorithm. } // try to read from /propono.properties try { final String configFile = "/propono.properties" ; String factoryClassName = null ; if ( firstTime ) { synchronized ( cacheProps ) { if ( firstTime ) { try { final InputStream is = FactoryFinder . class . getResourceAsStream ( configFile ) ; firstTime = false ; if ( is != null ) { dPrint ( "Read properties file: " + configFile ) ; cacheProps . load ( is ) ; } } catch ( final Exception intentionallyIgnored ) { } } } } factoryClassName = cacheProps . getProperty ( factoryId ) ; if ( factoryClassName != null ) { dPrint ( "found in $java.home/propono.properties, value=" + factoryClassName ) ; return newInstance ( factoryClassName , classLoader , true ) ; } } catch ( final Exception ex ) { if ( debug ) { ex . printStackTrace ( ) ; } } // Try Jar Service Provider Mechanism final Object provider = findJarServiceProvider ( factoryId ) ; if ( provider != null ) { return provider ; } if ( fallbackClassName == null ) { throw new ConfigurationError ( "Provider for " + factoryId + " cannot be found" , null ) ; } dPrint ( "loaded from fallback value: " + fallbackClassName ) ; return newInstance ( fallbackClassName , classLoader , true ) ; } | Finds the implementation Class object in the specified order . Main entry point . | 511 | 15 |
32,516 | public static Double parse ( final String s ) { Double parsed = null ; try { if ( s != null ) { parsed = Double . parseDouble ( s ) ; } } catch ( final NumberFormatException e ) { } return parsed ; } | Converts a String into an Double . | 50 | 8 |
32,517 | public static PriceTypeEnumeration findByValue ( final String value ) { if ( value . equalsIgnoreCase ( "negotiable" ) ) { return PriceTypeEnumeration . NEGOTIABLE ; } else { return PriceTypeEnumeration . STARTING ; } } | Returns a PriceTypeEnumeration based on the String value or null . | 61 | 15 |
32,518 | protected void populateChannel ( final Channel channel , final Element eChannel ) { final String title = channel . getTitle ( ) ; if ( title != null ) { eChannel . addContent ( generateSimpleElement ( "title" , title ) ) ; } final String link = channel . getLink ( ) ; if ( link != null ) { eChannel . addContent ( generateSimpleElement ( "link" , link ) ) ; } final String description = channel . getDescription ( ) ; if ( description != null ) { eChannel . addContent ( generateSimpleElement ( "description" , description ) ) ; } } | Populates the given channel with parsed data from the ROME element that holds the channel data . | 127 | 19 |
32,519 | @ Override protected SyndEntry createSyndEntry ( final Item item , final boolean preserveWireItem ) { final SyndEntry syndEntry = super . createSyndEntry ( item , preserveWireItem ) ; final Description desc = item . getDescription ( ) ; if ( desc != null ) { final SyndContent descContent = new SyndContentImpl ( ) ; descContent . setType ( desc . getType ( ) ) ; descContent . setValue ( desc . getValue ( ) ) ; syndEntry . setDescription ( descContent ) ; } final Content cont = item . getContent ( ) ; if ( cont != null ) { final SyndContent contContent = new SyndContentImpl ( ) ; contContent . setType ( cont . getType ( ) ) ; contContent . setValue ( cont . getValue ( ) ) ; final List < SyndContent > contents = new ArrayList < SyndContent > ( ) ; contents . add ( contContent ) ; syndEntry . setContents ( contents ) ; } return syndEntry ; } | rss . description - > synd . description | 212 | 8 |
32,520 | @ Override protected void doDelete ( final HttpServletRequest req , final HttpServletResponse res ) throws ServletException , IOException { LOG . debug ( "Entering" ) ; final AtomHandler handler = createAtomRequestHandler ( req , res ) ; final String userName = handler . getAuthenticatedUsername ( ) ; if ( userName != null ) { final AtomRequest areq = new AtomRequestImpl ( req ) ; try { if ( handler . isEntryURI ( areq ) ) { handler . deleteEntry ( areq ) ; res . setStatus ( HttpServletResponse . SC_OK ) ; } else { res . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; } } catch ( final AtomException ae ) { res . sendError ( ae . getStatus ( ) , ae . getMessage ( ) ) ; LOG . debug ( "An error occured while processing DELETE" , ae ) ; } catch ( final Exception e ) { res . sendError ( HttpServletResponse . SC_INTERNAL_SERVER_ERROR , e . getMessage ( ) ) ; LOG . debug ( "An error occured while processing DELETE" , e ) ; } } else { res . setHeader ( "WWW-Authenticate" , "BASIC realm=\"AtomPub\"" ) ; // Wanted to use sendError() here but Tomcat sends 403 forbidden // when I do that, so sticking with setStatus() for time being. res . setStatus ( HttpServletResponse . SC_UNAUTHORIZED ) ; } LOG . debug ( "Exiting" ) ; } | Handle Atom DELETE by calling appropriate handler . | 360 | 10 |
32,521 | public String getAttributeValue ( final String name ) { final List < Attribute > attributes = Collections . synchronizedList ( getAttributes ( ) ) ; for ( int i = 0 ; i < attributes . size ( ) ; i ++ ) { final Attribute a = attributes . get ( i ) ; if ( a . getName ( ) != null && a . getName ( ) . equals ( name ) ) { return a . getValue ( ) ; } } return null ; } | Returns the value of an attribute on the outline or null . | 99 | 12 |
32,522 | public void sendUpdateNotification ( final String hub , final String topic ) throws NotificationException { try { final StringBuilder sb = new StringBuilder ( "hub.mode=publish&hub.url=" ) . append ( URLEncoder . encode ( topic , "UTF-8" ) ) ; final URL hubUrl = new URL ( hub ) ; final HttpURLConnection connection = ( HttpURLConnection ) hubUrl . openConnection ( ) ; // connection.setRequestProperty("Host", hubUrl.getHost()); connection . setRequestProperty ( "User-Agent" , "ROME-Certiorem" ) ; connection . setRequestProperty ( "ContentType" , "application/x-www-form-urlencoded" ) ; connection . setDoOutput ( true ) ; connection . connect ( ) ; final OutputStream os = connection . getOutputStream ( ) ; os . write ( sb . toString ( ) . getBytes ( "UTF-8" ) ) ; os . close ( ) ; final int rc = connection . getResponseCode ( ) ; connection . disconnect ( ) ; if ( rc != 204 ) { throw new NotificationException ( "Server returned an unexcepted response code: " + rc + " " + connection . getResponseMessage ( ) ) ; } } catch ( final UnsupportedEncodingException ex ) { LOG . error ( "Could not encode URL" , ex ) ; throw new NotificationException ( "Could not encode URL" , ex ) ; } catch ( final IOException ex ) { LOG . error ( "Communication error" , ex ) ; throw new NotificationException ( "Unable to communicate with " + hub , ex ) ; } } | Sends the HUB url a notification of a change in topic | 356 | 13 |
32,523 | public void sendUpdateNotification ( final String topic , final SyndFeed feed ) throws NotificationException { for ( final SyndLink link : feed . getLinks ( ) ) { if ( "hub" . equals ( link . getRel ( ) ) ) { sendUpdateNotification ( link . getRel ( ) , topic ) ; return ; } } throw new NotificationException ( "Hub link not found." ) ; } | Sends a notification for a feed located at topic . The feed MUST contain rel = hub . | 85 | 19 |
32,524 | public void sendUpdateNotification ( final SyndFeed feed ) throws NotificationException { SyndLink hub = null ; SyndLink self = null ; for ( final SyndLink link : feed . getLinks ( ) ) { if ( "hub" . equals ( link . getRel ( ) ) ) { hub = link ; } if ( "self" . equals ( link . getRel ( ) ) ) { self = link ; } if ( hub != null && self != null ) { break ; } } if ( hub == null ) { throw new NotificationException ( "A link rel='hub' was not found in the feed." ) ; } if ( self == null ) { throw new NotificationException ( "A link rel='self' was not found in the feed." ) ; } sendUpdateNotification ( hub . getRel ( ) , self . getHref ( ) ) ; } | Sends a notification for a feed . The feed MUST contain rel = hub and rel = self links . | 182 | 21 |
32,525 | public void sendUpdateNotificationAsyncronously ( final String hub , final String topic , final AsyncNotificationCallback callback ) { final Runnable r = new Runnable ( ) { @ Override public void run ( ) { try { sendUpdateNotification ( hub , topic ) ; callback . onSuccess ( ) ; } catch ( final Throwable t ) { callback . onFailure ( t ) ; } } } ; if ( executor != null ) { executor . execute ( r ) ; } else { new Thread ( r ) . start ( ) ; } } | Sends the HUB url a notification of a change in topic asynchronously | 120 | 16 |
32,526 | @ Override public Categories getCategories ( final AtomRequest areq ) throws AtomException { LOG . debug ( "getCollection" ) ; final String [ ] pathInfo = StringUtils . split ( areq . getPathInfo ( ) , "/" ) ; final String handle = pathInfo [ 0 ] ; final String collection = pathInfo [ 1 ] ; final FileBasedCollection col = service . findCollectionByHandle ( handle , collection ) ; return col . getCategories ( true ) . get ( 0 ) ; } | Returns null because we use in - line categories . | 109 | 10 |
32,527 | @ Override public Feed getCollection ( final AtomRequest areq ) throws AtomException { LOG . debug ( "getCollection" ) ; final String [ ] pathInfo = StringUtils . split ( areq . getPathInfo ( ) , "/" ) ; final String handle = pathInfo [ 0 ] ; final String collection = pathInfo [ 1 ] ; final FileBasedCollection col = service . findCollectionByHandle ( handle , collection ) ; return col . getFeedDocument ( ) ; } | Get collection specified by pathinfo . | 102 | 7 |
32,528 | @ Override public Entry postEntry ( final AtomRequest areq , final Entry entry ) throws AtomException { LOG . debug ( "postEntry" ) ; final String [ ] pathInfo = StringUtils . split ( areq . getPathInfo ( ) , "/" ) ; final String handle = pathInfo [ 0 ] ; final String collection = pathInfo [ 1 ] ; final FileBasedCollection col = service . findCollectionByHandle ( handle , collection ) ; try { return col . addEntry ( entry ) ; } catch ( final Exception fe ) { fe . printStackTrace ( ) ; throw new AtomException ( fe ) ; } } | Create a new entry specified by pathInfo and posted entry . We save the submitted Atom entry verbatim but we do set the id and reset the update time . | 134 | 33 |
32,529 | @ Override public void putEntry ( final AtomRequest areq , final Entry entry ) throws AtomException { LOG . debug ( "putEntry" ) ; final String [ ] pathInfo = StringUtils . split ( areq . getPathInfo ( ) , "/" ) ; final String handle = pathInfo [ 0 ] ; final String collection = pathInfo [ 1 ] ; final String fileName = pathInfo [ 2 ] ; final FileBasedCollection col = service . findCollectionByHandle ( handle , collection ) ; try { col . updateEntry ( entry , fileName ) ; } catch ( final Exception fe ) { throw new AtomException ( fe ) ; } } | Update entry specified by pathInfo and posted entry . | 138 | 10 |
32,530 | @ Override public void deleteEntry ( final AtomRequest areq ) throws AtomException { LOG . debug ( "deleteEntry" ) ; final String [ ] pathInfo = StringUtils . split ( areq . getPathInfo ( ) , "/" ) ; final String handle = pathInfo [ 0 ] ; final String collection = pathInfo [ 1 ] ; final String fileName = pathInfo [ 2 ] ; final FileBasedCollection col = service . findCollectionByHandle ( handle , collection ) ; try { col . deleteEntry ( fileName ) ; } catch ( final Exception e ) { final String msg = "ERROR in atom.deleteResource" ; LOG . error ( msg , e ) ; throw new AtomException ( msg ) ; } } | Delete entry specified by pathInfo . | 154 | 7 |
32,531 | @ Override public Entry postMedia ( final AtomRequest areq , final Entry entry ) throws AtomException { // get incoming slug from HTTP header final String slug = areq . getHeader ( "Slug" ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "postMedia - title: " + entry . getTitle ( ) + " slug:" + slug ) ; } try { final File tempFile = null ; final String [ ] pathInfo = StringUtils . split ( areq . getPathInfo ( ) , "/" ) ; final String handle = pathInfo [ 0 ] ; final String collection = pathInfo [ 1 ] ; final FileBasedCollection col = service . findCollectionByHandle ( handle , collection ) ; try { col . addMediaEntry ( entry , slug , areq . getInputStream ( ) ) ; } catch ( final Exception e ) { e . printStackTrace ( ) ; final String msg = "ERROR reading posted file" ; LOG . error ( msg , e ) ; throw new AtomException ( msg , e ) ; } finally { if ( tempFile != null ) { tempFile . delete ( ) ; } } } catch ( final Exception re ) { throw new AtomException ( "ERROR: posting media" ) ; } return entry ; } | Store media data in collection specified by pathInfo create an Atom media - link entry to store metadata for the new media file and return that entry to the caller . | 271 | 32 |
32,532 | @ Override public void putMedia ( final AtomRequest areq ) throws AtomException { LOG . debug ( "putMedia" ) ; final String [ ] pathInfo = StringUtils . split ( areq . getPathInfo ( ) , "/" ) ; final String handle = pathInfo [ 0 ] ; final String collection = pathInfo [ 1 ] ; final String fileName = pathInfo [ 3 ] ; final FileBasedCollection col = service . findCollectionByHandle ( handle , collection ) ; try { col . updateMediaEntry ( fileName , areq . getContentType ( ) , areq . getInputStream ( ) ) ; } catch ( final Exception re ) { throw new AtomException ( "ERROR: posting media" ) ; } } | Update the media file part of a media - link entry . | 156 | 12 |
32,533 | @ Override public boolean isAtomServiceURI ( final AtomRequest areq ) { final String [ ] pathInfo = StringUtils . split ( areq . getPathInfo ( ) , "/" ) ; if ( pathInfo . length == 0 ) { return true ; } return false ; } | Return true if specified pathinfo represents URI of service doc . | 62 | 12 |
32,534 | @ Override public boolean isCategoriesURI ( final AtomRequest areq ) { LOG . debug ( "isCategoriesDocumentURI" ) ; final String [ ] pathInfo = StringUtils . split ( areq . getPathInfo ( ) , "/" ) ; if ( pathInfo . length == 3 && "categories" . equals ( pathInfo [ 2 ] ) ) { return true ; } return false ; } | Return true if specified pathinfo represents URI of category doc . | 88 | 12 |
32,535 | @ Override public boolean isCollectionURI ( final AtomRequest areq ) { LOG . debug ( "isCollectionURI" ) ; // workspace/collection-plural // if length is 2 and points to a valid collection then YES final String [ ] pathInfo = StringUtils . split ( areq . getPathInfo ( ) , "/" ) ; if ( pathInfo . length == 2 ) { final String handle = pathInfo [ 0 ] ; final String collection = pathInfo [ 1 ] ; if ( service . findCollectionByHandle ( handle , collection ) != null ) { return true ; } } return false ; } | Return true if specified pathinfo represents URI of a collection . | 129 | 12 |
32,536 | public String authenticateBASIC ( final HttpServletRequest request ) { LOG . debug ( "authenticateBASIC" ) ; boolean valid = false ; String userID = null ; String password = null ; try { final String authHeader = request . getHeader ( "Authorization" ) ; if ( authHeader != null ) { final StringTokenizer st = new StringTokenizer ( authHeader ) ; if ( st . hasMoreTokens ( ) ) { final String basic = st . nextToken ( ) ; if ( basic . equalsIgnoreCase ( "Basic" ) ) { final String credentials = st . nextToken ( ) ; final String userPass = new String ( Base64 . decodeBase64 ( credentials . getBytes ( ) ) ) ; final int p = userPass . indexOf ( ":" ) ; if ( p != - 1 ) { userID = userPass . substring ( 0 , p ) ; password = userPass . substring ( p + 1 ) ; // Validate the User. valid = validateUser ( userID , password ) ; } } } } } catch ( final Exception e ) { LOG . debug ( "An error occured while processing Basic authentication" , e ) ; } if ( valid ) { // For now assume userID as userName return userID ; } return null ; } | BASIC authentication . | 279 | 5 |
32,537 | public boolean isMediaEntry ( ) { boolean mediaEntry = false ; final List < Link > links = getOtherLinks ( ) ; for ( final Link link : links ) { if ( "edit-media" . equals ( link . getRel ( ) ) ) { mediaEntry = true ; break ; } } return mediaEntry ; } | Returns true if entry is a media entry i . e . has rel = edit - media . | 69 | 19 |
32,538 | @ Override protected void enqueueNotification ( final Notification not ) { final Runnable r = new Runnable ( ) { @ Override public void run ( ) { not . lastRun = System . currentTimeMillis ( ) ; final SubscriptionSummary summary = postNotification ( not . subscriber , not . mimeType , not . payload ) ; if ( ! summary . isLastPublishSuccessful ( ) ) { not . retryCount ++ ; if ( not . retryCount <= 5 ) { retry ( not ) ; } } not . callback . onSummaryInfo ( summary ) ; } } ; exeuctor . execute ( r ) ; } | Enqueues a notification to run . If the notification fails it will be retried every two minutes until 5 attempts are completed . Notifications to the same callback should be delivered successfully in order . | 141 | 39 |
32,539 | protected void retry ( final Notification not ) { if ( ! pendings . contains ( not . subscriber . getCallback ( ) ) ) { // We don't have a current retry for this callback pending, so we // will schedule the retry pendings . add ( not . subscriber . getCallback ( ) ) ; timer . schedule ( new TimerTask ( ) { @ Override public void run ( ) { pendings . remove ( not . subscriber . getCallback ( ) ) ; enqueueNotification ( not ) ; } } , TWO_MINUTES ) ; } else { // There is a retry in front of this one, so we will just schedule // it to retry again in a bit timer . schedule ( new TimerTask ( ) { @ Override public void run ( ) { retry ( not ) ; } } , TWO_MINUTES ) ; } } | Schedules a notification to retry in two minutes . | 186 | 12 |
32,540 | @ Override protected List < Element > getItems ( final Element rssRoot ) { final Element eChannel = rssRoot . getChild ( "channel" , getRSSNamespace ( ) ) ; if ( eChannel != null ) { return eChannel . getChildren ( "item" , getRSSNamespace ( ) ) ; } else { return Collections . emptyList ( ) ; } } | It looks for the item elements under the channel elemment . | 84 | 13 |
32,541 | @ Override protected Element getImage ( final Element rssRoot ) { final Element eChannel = rssRoot . getChild ( "channel" , getRSSNamespace ( ) ) ; if ( eChannel != null ) { return eChannel . getChild ( "image" , getRSSNamespace ( ) ) ; } else { return null ; } } | It looks for the image elements under the channel elemment . | 76 | 13 |
32,542 | @ Override protected Element getTextInput ( final Element rssRoot ) { final String elementName = getTextInputLabel ( ) ; final Element eChannel = rssRoot . getChild ( "channel" , getRSSNamespace ( ) ) ; if ( eChannel != null ) { return eChannel . getChild ( elementName , getRSSNamespace ( ) ) ; } else { return null ; } } | It looks for the textinput elements under the channel elemment . | 88 | 14 |
32,543 | @ Override public List < Category > getCategories ( ) { return categories == null ? ( categories = new ArrayList < Category > ( ) ) : categories ; } | The parent categories for this feed | 35 | 6 |
32,544 | public static Long parseDecimal ( final String s ) { Long parsed = null ; try { if ( s != null ) { parsed = ( long ) Double . parseDouble ( s ) ; } } catch ( final NumberFormatException e ) { } return parsed ; } | Converts a String into a Long by first parsing it as Double and then casting it to Long . | 55 | 20 |
32,545 | public void add ( final double latitude , final double longitude ) { ensureCapacity ( size + 1 ) ; this . longitude [ size ] = longitude ; this . latitude [ size ] = latitude ; ++ size ; } | Add a position at the end of the list | 47 | 9 |
32,546 | public void insert ( final int pos , final double latitude , final double longitude ) { ensureCapacity ( size + 1 ) ; System . arraycopy ( this . longitude , pos , this . longitude , pos + 1 , size - pos ) ; System . arraycopy ( this . latitude , pos , this . latitude , pos + 1 , size - pos ) ; this . longitude [ pos ] = longitude ; this . latitude [ pos ] = latitude ; ++ size ; } | Add a position at a given index in the list . The rest of the list is shifted one place to the right | 101 | 23 |
32,547 | public void replace ( final int pos , final double latitude , final double longitude ) { this . longitude [ pos ] = longitude ; this . latitude [ pos ] = latitude ; } | Replace the position at the index with new values | 39 | 10 |
32,548 | public void remove ( final int pos ) { System . arraycopy ( longitude , pos + 1 , longitude , pos , size - pos - 1 ) ; System . arraycopy ( latitude , pos + 1 , latitude , pos , size - pos - 1 ) ; -- size ; } | Remove the position at the index the rest of the list is shifted one place to the left | 59 | 18 |
32,549 | private String findBaseURI ( final Element root ) throws MalformedURLException { String ret = null ; if ( findAtomLink ( root , "self" ) != null ) { ret = findAtomLink ( root , "self" ) ; if ( "." . equals ( ret ) || "./" . equals ( ret ) ) { ret = "" ; } if ( ret . indexOf ( "/" ) != - 1 ) { ret = ret . substring ( 0 , ret . lastIndexOf ( "/" ) ) ; } ret = resolveURI ( null , root , ret ) ; } return ret ; } | Find base URI of feed considering relative URIs . | 132 | 10 |
32,550 | private String findAtomLink ( final Element parent , final String rel ) { String ret = null ; final List < Element > linksList = parent . getChildren ( "link" , ATOM_10_NS ) ; if ( linksList != null ) { for ( final Element element : linksList ) { final Element link = element ; final Attribute relAtt = getAttribute ( link , "rel" ) ; final Attribute hrefAtt = getAttribute ( link , "href" ) ; if ( relAtt == null && "alternate" . equals ( rel ) || relAtt != null && relAtt . getValue ( ) . equals ( rel ) ) { ret = hrefAtt . getValue ( ) ; break ; } } } return ret ; } | Return URL string of Atom link element under parent element . Link with no rel attribute is considered to be rel = alternate | 157 | 23 |
32,551 | private static String formURI ( String base , String append ) { base = stripTrailingSlash ( base ) ; append = stripStartingSlash ( append ) ; if ( append . startsWith ( ".." ) ) { final String [ ] parts = append . split ( "/" ) ; for ( final String part : parts ) { if ( ".." . equals ( part ) ) { final int last = base . lastIndexOf ( "/" ) ; if ( last != - 1 ) { base = base . substring ( 0 , last ) ; append = append . substring ( 3 , append . length ( ) ) ; } else { break ; } } } } return base + "/" + append ; } | Form URI by combining base with append portion and giving special consideration to append portions that begin with .. | 150 | 19 |
32,552 | private static String stripStartingSlash ( String s ) { if ( s != null && s . startsWith ( "/" ) ) { s = s . substring ( 1 , s . length ( ) ) ; } return s ; } | Strip starting slash from beginning of string . | 49 | 9 |
32,553 | private static String stripTrailingSlash ( String s ) { if ( s != null && s . endsWith ( "/" ) ) { s = s . substring ( 0 , s . length ( ) - 1 ) ; } return s ; } | Strip trailing slash from end of string . | 52 | 9 |
32,554 | public static Entry parseEntry ( final Reader rd , final String baseURI , final Locale locale ) throws JDOMException , IOException , IllegalArgumentException , FeedException { // Parse entry into JDOM tree final SAXBuilder builder = new SAXBuilder ( ) ; final Document entryDoc = builder . build ( rd ) ; final Element fetchedEntryElement = entryDoc . getRootElement ( ) ; fetchedEntryElement . detach ( ) ; // Put entry into a JDOM document with 'feed' root so that Rome can // handle it final Feed feed = new Feed ( ) ; feed . setFeedType ( "atom_1.0" ) ; final WireFeedOutput wireFeedOutput = new WireFeedOutput ( ) ; final Document feedDoc = wireFeedOutput . outputJDom ( feed ) ; feedDoc . getRootElement ( ) . addContent ( fetchedEntryElement ) ; if ( baseURI != null ) { feedDoc . getRootElement ( ) . setAttribute ( "base" , baseURI , Namespace . XML_NAMESPACE ) ; } final WireFeedInput input = new WireFeedInput ( false , locale ) ; final Feed parsedFeed = ( Feed ) input . build ( feedDoc ) ; return parsedFeed . getEntries ( ) . get ( 0 ) ; } | Parse entry from reader . | 276 | 6 |
32,555 | public Feed getFeedDocument ( ) throws AtomException { InputStream in = null ; synchronized ( FileStore . getFileStore ( ) ) { in = FileStore . getFileStore ( ) . getFileInputStream ( getFeedPath ( ) ) ; if ( in == null ) { in = createDefaultFeedDocument ( contextURI + servletPath + "/" + handle + "/" + collection ) ; } } try { final WireFeedInput input = new WireFeedInput ( ) ; final WireFeed wireFeed = input . build ( new InputStreamReader ( in , "UTF-8" ) ) ; return ( Feed ) wireFeed ; } catch ( final Exception ex ) { throw new AtomException ( ex ) ; } } | Get feed document representing collection . | 151 | 6 |
32,556 | public List < Categories > getCategories ( final boolean inline ) { final Categories cats = new Categories ( ) ; cats . setFixed ( true ) ; cats . setScheme ( contextURI + "/" + handle + "/" + singular ) ; if ( inline ) { for ( final String catName : catNames ) { final Category cat = new Category ( ) ; cat . setTerm ( catName ) ; cats . addCategory ( cat ) ; } } else { cats . setHref ( getCategoriesURI ( ) ) ; } return Collections . singletonList ( cats ) ; } | Get list of one Categories object containing categories allowed by collection . | 123 | 12 |
32,557 | public Entry addEntry ( final Entry entry ) throws Exception { synchronized ( FileStore . getFileStore ( ) ) { final Feed f = getFeedDocument ( ) ; final String fsid = FileStore . getFileStore ( ) . getNextId ( ) ; updateTimestamps ( entry ) ; // Save entry to file final String entryPath = getEntryPath ( fsid ) ; final OutputStream os = FileStore . getFileStore ( ) . getFileOutputStream ( entryPath ) ; updateEntryAppLinks ( entry , fsid , true ) ; Atom10Generator . serializeEntry ( entry , new OutputStreamWriter ( os , "UTF-8" ) ) ; os . flush ( ) ; os . close ( ) ; // Update feed file updateEntryAppLinks ( entry , fsid , false ) ; updateFeedDocumentWithNewEntry ( f , entry ) ; return entry ; } } | Add entry to collection . | 188 | 5 |
32,558 | public Entry getEntry ( String fsid ) throws Exception { if ( fsid . endsWith ( ".media-link" ) ) { fsid = fsid . substring ( 0 , fsid . length ( ) - ".media-link" . length ( ) ) ; } final String entryPath = getEntryPath ( fsid ) ; checkExistence ( entryPath ) ; final InputStream in = FileStore . getFileStore ( ) . getFileInputStream ( entryPath ) ; final Entry entry ; final File resource = new File ( fsid ) ; if ( resource . exists ( ) ) { entry = loadAtomResourceEntry ( in , resource ) ; updateMediaEntryAppLinks ( entry , fsid , true ) ; } else { entry = loadAtomEntry ( in ) ; updateEntryAppLinks ( entry , fsid , true ) ; } return entry ; } | Get an entry from the collection . | 184 | 7 |
32,559 | public AtomMediaResource getMediaResource ( final String fileName ) throws Exception { final String filePath = getEntryMediaPath ( fileName ) ; final File resource = new File ( filePath ) ; return new AtomMediaResource ( resource ) ; } | Get media resource wrapping a file . | 51 | 7 |
32,560 | public void updateEntry ( final Entry entry , String fsid ) throws Exception { synchronized ( FileStore . getFileStore ( ) ) { final Feed f = getFeedDocument ( ) ; if ( fsid . endsWith ( ".media-link" ) ) { fsid = fsid . substring ( 0 , fsid . length ( ) - ".media-link" . length ( ) ) ; } updateTimestamps ( entry ) ; updateEntryAppLinks ( entry , fsid , false ) ; updateFeedDocumentWithExistingEntry ( f , entry ) ; final String entryPath = getEntryPath ( fsid ) ; final OutputStream os = FileStore . getFileStore ( ) . getFileOutputStream ( entryPath ) ; updateEntryAppLinks ( entry , fsid , true ) ; Atom10Generator . serializeEntry ( entry , new OutputStreamWriter ( os , "UTF-8" ) ) ; os . flush ( ) ; os . close ( ) ; } } | Update an entry in the collection . | 207 | 7 |
32,561 | public Entry updateMediaEntry ( final String fileName , final String contentType , final InputStream is ) throws Exception { synchronized ( FileStore . getFileStore ( ) ) { final File tempFile = File . createTempFile ( fileName , "tmp" ) ; final FileOutputStream fos = new FileOutputStream ( tempFile ) ; Utilities . copyInputToOutput ( is , fos ) ; fos . close ( ) ; // Update media file final FileInputStream fis = new FileInputStream ( tempFile ) ; saveMediaFile ( fileName , contentType , tempFile . length ( ) , fis ) ; fis . close ( ) ; final File resourceFile = new File ( getEntryMediaPath ( fileName ) ) ; // Load media-link entry to return final String entryPath = getEntryPath ( fileName ) ; final InputStream in = FileStore . getFileStore ( ) . getFileInputStream ( entryPath ) ; final Entry atomEntry = loadAtomResourceEntry ( in , resourceFile ) ; updateTimestamps ( atomEntry ) ; updateMediaEntryAppLinks ( atomEntry , fileName , false ) ; // Update feed with new entry final Feed f = getFeedDocument ( ) ; updateFeedDocumentWithExistingEntry ( f , atomEntry ) ; // Save updated media-link entry final OutputStream os = FileStore . getFileStore ( ) . getFileOutputStream ( entryPath ) ; updateMediaEntryAppLinks ( atomEntry , fileName , true ) ; Atom10Generator . serializeEntry ( atomEntry , new OutputStreamWriter ( os , "UTF-8" ) ) ; os . flush ( ) ; os . close ( ) ; return atomEntry ; } } | Update media associated with a media - link entry . | 362 | 10 |
32,562 | public void deleteEntry ( final String fsid ) throws Exception { synchronized ( FileStore . getFileStore ( ) ) { // Remove entry from Feed final Feed feed = getFeedDocument ( ) ; updateFeedDocumentRemovingEntry ( feed , fsid ) ; final String entryFilePath = getEntryPath ( fsid ) ; FileStore . getFileStore ( ) . deleteFile ( entryFilePath ) ; final String entryMediaPath = getEntryMediaPath ( fsid ) ; if ( entryMediaPath != null ) { FileStore . getFileStore ( ) . deleteFile ( entryMediaPath ) ; } final String entryDirPath = getEntryDirPath ( fsid ) ; FileStore . getFileStore ( ) . deleteDirectory ( entryDirPath ) ; try { Thread . sleep ( 500L ) ; } catch ( final Exception ignored ) { } } } | Delete an entry and any associated media file . | 179 | 9 |
32,563 | private Entry loadAtomEntry ( final InputStream in ) { try { return Atom10Parser . parseEntry ( new BufferedReader ( new InputStreamReader ( in , "UTF-8" ) ) , null , Locale . US ) ; } catch ( final Exception e ) { e . printStackTrace ( ) ; return null ; } } | Create a Rome Atom entry based on a Roller entry . Content is escaped . Link is stored as rel = alternate link . | 73 | 24 |
32,564 | private void saveMediaFile ( final String name , final String contentType , final long size , final InputStream is ) throws AtomException { final byte [ ] buffer = new byte [ 8192 ] ; int bytesRead = 0 ; final File dirPath = new File ( getEntryMediaPath ( name ) ) ; if ( ! dirPath . getParentFile ( ) . exists ( ) ) { dirPath . getParentFile ( ) . mkdirs ( ) ; } OutputStream bos = null ; try { bos = new FileOutputStream ( dirPath . getAbsolutePath ( ) ) ; while ( ( bytesRead = is . read ( buffer , 0 , 8192 ) ) != - 1 ) { bos . write ( buffer , 0 , bytesRead ) ; } } catch ( final Exception e ) { throw new AtomException ( "ERROR uploading file" , e ) ; } finally { try { bos . flush ( ) ; bos . close ( ) ; } catch ( final Exception ignored ) { } } } | Save file to website s resource directory . | 209 | 8 |
32,565 | private String createFileName ( final String title , final String contentType ) { if ( handle == null ) { throw new IllegalArgumentException ( "weblog handle cannot be null" ) ; } if ( contentType == null ) { throw new IllegalArgumentException ( "contentType cannot be null" ) ; } String fileName = null ; final SimpleDateFormat sdf = new SimpleDateFormat ( ) ; sdf . applyPattern ( "yyyyMMddHHssSSS" ) ; // Determine the extension based on the contentType. This is a hack. // The info we need to map from contentType to file extension is in // JRE/lib/content-type.properties, but Java Activation doesn't provide // a way to do a reverse mapping or to get at the data. final String [ ] typeTokens = contentType . split ( "/" ) ; final String ext = typeTokens [ 1 ] ; if ( title != null && ! title . trim ( ) . equals ( "" ) ) { // We've got a title, so use it to build file name final String base = Utilities . replaceNonAlphanumeric ( title , ' ' ) ; final StringTokenizer toker = new StringTokenizer ( base ) ; String tmp = null ; int count = 0 ; while ( toker . hasMoreTokens ( ) && count < 5 ) { String s = toker . nextToken ( ) ; s = s . toLowerCase ( ) ; tmp = tmp == null ? s : tmp + "_" + s ; count ++ ; } fileName = tmp + "-" + sdf . format ( new Date ( ) ) + "." + ext ; } else { // No title or text, so instead we'll use the item's date // in YYYYMMDD format to form the file name fileName = handle + "-" + sdf . format ( new Date ( ) ) + "." + ext ; } return fileName ; } | Creates a file name for a file based on a weblog handle title string and a content - type . | 412 | 22 |
32,566 | public static < T > T firstNotNull ( final T ... objects ) { for ( final T object : objects ) { if ( object != null ) { return object ; } } return null ; } | Returns the first object that is not null | 41 | 8 |
32,567 | private void loadPlugins ( ) { final List < T > finalPluginsList = new ArrayList < T > ( ) ; pluginsList = new ArrayList < T > ( ) ; pluginsMap = new HashMap < String , T > ( ) ; String className = null ; try { final Class < T > [ ] classes = getClasses ( ) ; for ( final Class < T > clazz : classes ) { className = clazz . getName ( ) ; final T plugin = clazz . newInstance ( ) ; if ( plugin instanceof DelegatingModuleParser ) { ( ( DelegatingModuleParser ) plugin ) . setFeedParser ( parentParser ) ; } if ( plugin instanceof DelegatingModuleGenerator ) { ( ( DelegatingModuleGenerator ) plugin ) . setFeedGenerator ( parentGenerator ) ; } pluginsMap . put ( getKey ( plugin ) , plugin ) ; // to preserve the order of definition in the rome.properties files pluginsList . add ( plugin ) ; } final Collection < T > plugins = pluginsMap . values ( ) ; for ( final T plugin : plugins ) { // to remove overridden plugin impls finalPluginsList . add ( plugin ) ; } final Iterator < T > iterator = pluginsList . iterator ( ) ; while ( iterator . hasNext ( ) ) { final T plugin = iterator . next ( ) ; if ( ! finalPluginsList . contains ( plugin ) ) { iterator . remove ( ) ; } } } catch ( final Exception ex ) { throw new RuntimeException ( "could not instantiate plugin " + className , ex ) ; } catch ( final ExceptionInInitializerError er ) { throw new RuntimeException ( "could not instantiate plugin " + className , er ) ; } } | PRIVATE - LOADER PART | 376 | 8 |
32,568 | public static String toLowerCase ( final String s ) { if ( s == null ) { return null ; } else { return s . toLowerCase ( Locale . ENGLISH ) ; } } | null - safe lower - case conversion of a String . | 42 | 11 |
32,569 | public static String streamToString ( final InputStream is ) throws IOException { final StringBuffer sb = new StringBuffer ( ) ; final BufferedReader in = new BufferedReader ( new InputStreamReader ( is ) ) ; String line ; while ( ( line = in . readLine ( ) ) != null ) { sb . append ( line ) ; sb . append ( LS ) ; } return sb . toString ( ) ; } | Read input from stream and into string . | 94 | 8 |
32,570 | public static void copyInputToOutput ( final InputStream input , final OutputStream output ) throws IOException { final BufferedInputStream in = new BufferedInputStream ( input ) ; final BufferedOutputStream out = new BufferedOutputStream ( output ) ; final byte buffer [ ] = new byte [ 8192 ] ; for ( int count = 0 ; count != - 1 ; ) { count = in . read ( buffer , 0 , 8192 ) ; if ( count != - 1 ) { out . write ( buffer , 0 , count ) ; } } try { in . close ( ) ; out . close ( ) ; } catch ( final IOException ex ) { throw new IOException ( "Closing file streams, " + ex . getMessage ( ) ) ; } } | Copy input stream to output stream using 8K buffer . | 162 | 11 |
32,571 | public static String replaceNonAlphanumeric ( final String str , final char subst ) { final StringBuffer ret = new StringBuffer ( str . length ( ) ) ; final char [ ] testChars = str . toCharArray ( ) ; for ( final char testChar : testChars ) { if ( Character . isLetterOrDigit ( testChar ) ) { ret . append ( testChar ) ; } else { ret . append ( subst ) ; } } return ret . toString ( ) ; } | Replaces occurences of non - alphanumeric characters with a supplied char . | 106 | 17 |
32,572 | public static String [ ] stringToStringArray ( final String instr , final String delim ) throws NoSuchElementException , NumberFormatException { final StringTokenizer toker = new StringTokenizer ( instr , delim ) ; final String stringArray [ ] = new String [ toker . countTokens ( ) ] ; int i = 0 ; while ( toker . hasMoreTokens ( ) ) { stringArray [ i ++ ] = toker . nextToken ( ) ; } return stringArray ; } | Convert string to string array . | 102 | 7 |
32,573 | public static String stringArrayToString ( final String [ ] stringArray , final String delim ) { String ret = "" ; for ( final String element : stringArray ) { if ( ret . length ( ) > 0 ) { ret = ret + delim + element ; } else { ret = element ; } } return ret ; } | Convert string array to string . | 67 | 7 |
32,574 | public static Integer parse ( final String s ) { try { return Integer . parseInt ( s ) ; } catch ( final NumberFormatException e ) { return null ; } } | Converts a String into an Integer . | 36 | 8 |
32,575 | public void addUpdate ( final Update update ) { if ( updates == null ) { updates = new ArrayList < Update > ( ) ; } updates . add ( update ) ; } | Add an update to this history | 37 | 6 |
32,576 | private void generateThumbails ( final Metadata m , final Element e ) { for ( final Thumbnail thumb : m . getThumbnail ( ) ) { final Element t = new Element ( "thumbnail" , NS ) ; addNotNullAttribute ( t , "url" , thumb . getUrl ( ) ) ; addNotNullAttribute ( t , "width" , thumb . getWidth ( ) ) ; addNotNullAttribute ( t , "height" , thumb . getHeight ( ) ) ; addNotNullAttribute ( t , "time" , thumb . getTime ( ) ) ; e . addContent ( t ) ; } } | Generation of thumbnail tags . | 133 | 6 |
32,577 | private void generateComments ( final Metadata m , final Element e ) { final Element commentsElements = new Element ( "comments" , NS ) ; for ( final String comment : m . getComments ( ) ) { addNotNullElement ( commentsElements , "comment" , comment ) ; } if ( ! commentsElements . getChildren ( ) . isEmpty ( ) ) { e . addContent ( commentsElements ) ; } } | Generation of comments tag . | 92 | 6 |
32,578 | private void generateCommunity ( final Metadata m , final Element e ) { if ( m . getCommunity ( ) == null ) { return ; } final Element communityElement = new Element ( "community" , NS ) ; if ( m . getCommunity ( ) . getStarRating ( ) != null ) { final Element starRatingElement = new Element ( "starRating" , NS ) ; addNotNullAttribute ( starRatingElement , "average" , m . getCommunity ( ) . getStarRating ( ) . getAverage ( ) ) ; addNotNullAttribute ( starRatingElement , "count" , m . getCommunity ( ) . getStarRating ( ) . getCount ( ) ) ; addNotNullAttribute ( starRatingElement , "min" , m . getCommunity ( ) . getStarRating ( ) . getMin ( ) ) ; addNotNullAttribute ( starRatingElement , "max" , m . getCommunity ( ) . getStarRating ( ) . getMax ( ) ) ; if ( starRatingElement . hasAttributes ( ) ) { communityElement . addContent ( starRatingElement ) ; } } if ( m . getCommunity ( ) . getStatistics ( ) != null ) { final Element statisticsElement = new Element ( "statistics" , NS ) ; addNotNullAttribute ( statisticsElement , "views" , m . getCommunity ( ) . getStatistics ( ) . getViews ( ) ) ; addNotNullAttribute ( statisticsElement , "favorites" , m . getCommunity ( ) . getStatistics ( ) . getFavorites ( ) ) ; if ( statisticsElement . hasAttributes ( ) ) { communityElement . addContent ( statisticsElement ) ; } } if ( m . getCommunity ( ) . getTags ( ) != null && ! m . getCommunity ( ) . getTags ( ) . isEmpty ( ) ) { final Element tagsElement = new Element ( "tags" , NS ) ; for ( final Tag tag : m . getCommunity ( ) . getTags ( ) ) { if ( ! tagsElement . getTextTrim ( ) . isEmpty ( ) ) { tagsElement . addContent ( ", " ) ; } if ( tag . getWeight ( ) == null ) { tagsElement . addContent ( tag . getName ( ) ) ; } else { tagsElement . addContent ( tag . getName ( ) ) ; tagsElement . addContent ( ":" ) ; tagsElement . addContent ( String . valueOf ( tag . getWeight ( ) ) ) ; } } if ( ! tagsElement . getTextTrim ( ) . isEmpty ( ) ) { communityElement . addContent ( tagsElement ) ; } } if ( ! communityElement . getChildren ( ) . isEmpty ( ) ) { e . addContent ( communityElement ) ; } } | Generation of community tag . | 587 | 6 |
32,579 | private void generateEmbed ( final Metadata m , final Element e ) { if ( m . getEmbed ( ) == null ) { return ; } final Element embedElement = new Element ( "embed" , NS ) ; addNotNullAttribute ( embedElement , "url" , m . getEmbed ( ) . getUrl ( ) ) ; addNotNullAttribute ( embedElement , "width" , m . getEmbed ( ) . getWidth ( ) ) ; addNotNullAttribute ( embedElement , "height" , m . getEmbed ( ) . getHeight ( ) ) ; for ( final Param param : m . getEmbed ( ) . getParams ( ) ) { final Element paramElement = addNotNullElement ( embedElement , "param" , param . getValue ( ) ) ; if ( paramElement != null ) { addNotNullAttribute ( paramElement , "name" , param . getName ( ) ) ; } } if ( embedElement . hasAttributes ( ) || ! embedElement . getChildren ( ) . isEmpty ( ) ) { e . addContent ( embedElement ) ; } } | Generation of embed tag . | 237 | 6 |
32,580 | private void generateScenes ( final Metadata m , final Element e ) { final Element scenesElement = new Element ( "scenes" , NS ) ; for ( final Scene scene : m . getScenes ( ) ) { final Element sceneElement = new Element ( "scene" , NS ) ; addNotNullElement ( sceneElement , "sceneTitle" , scene . getTitle ( ) ) ; addNotNullElement ( sceneElement , "sceneDescription" , scene . getDescription ( ) ) ; addNotNullElement ( sceneElement , "sceneStartTime" , scene . getStartTime ( ) ) ; addNotNullElement ( sceneElement , "sceneEndTime" , scene . getEndTime ( ) ) ; if ( ! sceneElement . getChildren ( ) . isEmpty ( ) ) { scenesElement . addContent ( sceneElement ) ; } } if ( ! scenesElement . getChildren ( ) . isEmpty ( ) ) { e . addContent ( scenesElement ) ; } } | Generation of scenes tag . | 206 | 6 |
32,581 | private void generateLocations ( final Metadata m , final Element e ) { final GMLGenerator geoRssGenerator = new GMLGenerator ( ) ; for ( final Location location : m . getLocations ( ) ) { final Element locationElement = new Element ( "location" , NS ) ; addNotNullAttribute ( locationElement , "description" , location . getDescription ( ) ) ; addNotNullAttribute ( locationElement , "start" , location . getStart ( ) ) ; addNotNullAttribute ( locationElement , "end" , location . getEnd ( ) ) ; if ( location . getGeoRss ( ) != null ) { geoRssGenerator . generate ( location . getGeoRss ( ) , locationElement ) ; } if ( locationElement . hasAttributes ( ) || ! locationElement . getChildren ( ) . isEmpty ( ) ) { e . addContent ( locationElement ) ; } } } | Generation of location tags . | 200 | 6 |
32,582 | private void generatePeerLinks ( final Metadata m , final Element e ) { for ( final PeerLink peerLink : m . getPeerLinks ( ) ) { final Element peerLinkElement = new Element ( "peerLink" , NS ) ; addNotNullAttribute ( peerLinkElement , "type" , peerLink . getType ( ) ) ; addNotNullAttribute ( peerLinkElement , "href" , peerLink . getHref ( ) ) ; if ( peerLinkElement . hasAttributes ( ) ) { e . addContent ( peerLinkElement ) ; } } } | Generation of peerLink tags . | 122 | 7 |
32,583 | private void generateSubTitles ( final Metadata m , final Element e ) { for ( final SubTitle subTitle : m . getSubTitles ( ) ) { final Element subTitleElement = new Element ( "subTitle" , NS ) ; addNotNullAttribute ( subTitleElement , "type" , subTitle . getType ( ) ) ; addNotNullAttribute ( subTitleElement , "lang" , subTitle . getLang ( ) ) ; addNotNullAttribute ( subTitleElement , "href" , subTitle . getHref ( ) ) ; if ( subTitleElement . hasAttributes ( ) ) { e . addContent ( subTitleElement ) ; } } } | Generation of subTitle tags . | 145 | 7 |
32,584 | private void generateLicenses ( final Metadata m , final Element e ) { for ( final License license : m . getLicenses ( ) ) { final Element licenseElement = new Element ( "license" , NS ) ; addNotNullAttribute ( licenseElement , "type" , license . getType ( ) ) ; addNotNullAttribute ( licenseElement , "href" , license . getHref ( ) ) ; if ( license . getValue ( ) != null ) { licenseElement . addContent ( license . getValue ( ) ) ; } if ( licenseElement . hasAttributes ( ) || ! licenseElement . getTextTrim ( ) . isEmpty ( ) ) { e . addContent ( licenseElement ) ; } } } | Generation of license tags . | 153 | 6 |
32,585 | private void generateResponses ( final Metadata m , final Element e ) { if ( m . getResponses ( ) == null || m . getResponses ( ) . length == 0 ) { return ; } final Element responsesElements = new Element ( "responses" , NS ) ; for ( final String response : m . getResponses ( ) ) { addNotNullElement ( responsesElements , "response" , response ) ; } e . addContent ( responsesElements ) ; } | Generation of responses tag . | 108 | 6 |
32,586 | private void generateStatus ( final Metadata m , final Element e ) { if ( m . getStatus ( ) == null ) { return ; } final Element statusElement = new Element ( "status" , NS ) ; if ( m . getStatus ( ) . getState ( ) != null ) { statusElement . setAttribute ( "state" , m . getStatus ( ) . getState ( ) . name ( ) ) ; } addNotNullAttribute ( statusElement , "reason" , m . getStatus ( ) . getReason ( ) ) ; if ( statusElement . hasAttributes ( ) ) { e . addContent ( statusElement ) ; } } | Generation of status tag . | 137 | 6 |
32,587 | @ Override public void copyFrom ( final CopyFrom obj ) { final AppModule m = ( AppModule ) obj ; setDraft ( m . getDraft ( ) ) ; setEdited ( m . getEdited ( ) ) ; } | Copy from other module | 48 | 4 |
32,588 | private static String getContentTypeMime ( final String httpContentType ) { String mime = null ; if ( httpContentType != null ) { final int i = httpContentType . indexOf ( ";" ) ; if ( i == - 1 ) { mime = httpContentType . trim ( ) ; } else { mime = httpContentType . substring ( 0 , i ) . trim ( ) ; } } return mime ; } | returns MIME type or NULL if httpContentType is NULL | 94 | 13 |
32,589 | private static String getContentTypeEncoding ( final String httpContentType ) { String encoding = null ; if ( httpContentType != null ) { final int i = httpContentType . indexOf ( ";" ) ; if ( i > - 1 ) { final String postMime = httpContentType . substring ( i + 1 ) ; final Matcher m = CHARSET_PATTERN . matcher ( postMime ) ; if ( m . find ( ) ) { encoding = m . group ( 1 ) ; } if ( encoding != null ) { encoding = encoding . toUpperCase ( Locale . ENGLISH ) ; } } if ( encoding != null && ( encoding . startsWith ( "\"" ) && encoding . endsWith ( "\"" ) || encoding . startsWith ( "'" ) && encoding . endsWith ( "'" ) ) ) { encoding = encoding . substring ( 1 , encoding . length ( ) - 1 ) ; } } return encoding ; } | httpContentType is NULL | 208 | 5 |
32,590 | private static String getBOMEncoding ( final BufferedInputStream is ) throws IOException { String encoding = null ; final int [ ] bytes = new int [ 3 ] ; is . mark ( 3 ) ; bytes [ 0 ] = is . read ( ) ; bytes [ 1 ] = is . read ( ) ; bytes [ 2 ] = is . read ( ) ; if ( bytes [ 0 ] == 0xFE && bytes [ 1 ] == 0xFF ) { encoding = UTF_16BE ; is . reset ( ) ; is . read ( ) ; is . read ( ) ; } else if ( bytes [ 0 ] == 0xFF && bytes [ 1 ] == 0xFE ) { encoding = UTF_16LE ; is . reset ( ) ; is . read ( ) ; is . read ( ) ; } else if ( bytes [ 0 ] == 0xEF && bytes [ 1 ] == 0xBB && bytes [ 2 ] == 0xBF ) { encoding = UTF_8 ; } else { is . reset ( ) ; } return encoding ; } | if there was BOM the in the stream it is consumed | 223 | 12 |
32,591 | private static boolean isAppXml ( final String mime ) { return mime != null && ( mime . equals ( "application/xml" ) || mime . equals ( "application/xml-dtd" ) || mime . equals ( "application/xml-external-parsed-entity" ) || mime . startsWith ( "application/" ) && mime . endsWith ( "+xml" ) ) ; } | indicates if the MIME type belongs to the APPLICATION XML family | 92 | 14 |
32,592 | private static boolean isTextXml ( final String mime ) { return mime != null && ( mime . equals ( "text/xml" ) || mime . equals ( "text/xml-external-parsed-entity" ) || mime . startsWith ( "text/" ) && mime . endsWith ( "+xml" ) ) ; } | indicates if the MIME type belongs to the TEXT XML family | 77 | 13 |
32,593 | public static < T extends Extendable > List < T > group ( final List < T > values , final Group [ ] groups ) { final SortableList < T > list = getSortableList ( values ) ; final GroupStrategy strategy = new GroupStrategy ( ) ; for ( int i = groups . length - 1 ; i >= 0 ; i -- ) { list . sortOnProperty ( groups [ i ] , true , strategy ) ; } return list ; } | Groups values by the groups from the SLE . | 98 | 11 |
32,594 | public static < T extends Extendable > List < T > sort ( final List < T > values , final Sort sort , final boolean ascending ) { final SortableList < T > list = getSortableList ( values ) ; list . sortOnProperty ( sort , ascending , new SortStrategy ( ) ) ; return list ; } | Sorts a list of values based on a given sort field using a selection sort . | 69 | 17 |
32,595 | public static < T extends Extendable > List < T > sortAndGroup ( final List < T > values , final Group [ ] groups , final Sort sort , final boolean ascending ) { List < T > list = sort ( values , sort , ascending ) ; list = group ( list , groups ) ; return list ; } | Sorts and groups a set of entries . | 66 | 9 |
32,596 | public static ClientAtomService getAtomService ( final String uri , final AuthStrategy authStrategy ) throws ProponoException { return new ClientAtomService ( uri , authStrategy ) ; } | Create AtomService by reading service doc from Atom Server . | 45 | 11 |
32,597 | public static ClientCollection getCollection ( final String uri , final AuthStrategy authStrategy ) throws ProponoException { return new ClientCollection ( uri , authStrategy ) ; } | Create ClientCollection bound to URI . | 39 | 7 |
32,598 | public void setReference ( final Reference reference ) { this . reference = reference ; if ( reference instanceof PlayerReference ) { setPlayer ( ( PlayerReference ) reference ) ; } } | The player or URL reference for the item | 37 | 8 |
32,599 | public static void inject ( final WebDriver driver , final URL scriptUrl , Boolean skipFrames ) { final String script = getContents ( scriptUrl ) ; if ( ! skipFrames ) { final ArrayList < WebElement > parents = new ArrayList < WebElement > ( ) ; injectIntoFrames ( driver , script , parents ) ; } JavascriptExecutor js = ( JavascriptExecutor ) driver ; driver . switchTo ( ) . defaultContent ( ) ; js . executeScript ( script ) ; } | Recursively injects a script to the top level document with the option to skip iframes . | 103 | 21 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.