idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
25,400 | private JsonNode invokeCallbackMethod ( final InvokeRequest req , final String cookie ) { Object obj = this . getObject ( req . getObjref ( ) ) ; Method method = this . findCallbackMethod ( obj . getClass ( ) , cookie ) ; final Class < ? > [ ] argTypes = method . getParameterTypes ( ) ; final Object [ ] args = new Object [ argTypes . length ] ; for ( int i = 0 ; i < argTypes . length ; i ++ ) { args [ i ] = JsiiObjectMapper . treeToValue ( req . getArgs ( ) . get ( i ) , argTypes [ i ] ) ; } return JsiiObjectMapper . valueToTree ( invokeMethod ( obj , method , args ) ) ; } | Invokes an override for a method . |
25,401 | private Object invokeMethod ( final Object obj , final Method method , final Object ... args ) { boolean accessibility = method . isAccessible ( ) ; method . setAccessible ( true ) ; try { try { return method . invoke ( obj , args ) ; } catch ( Exception e ) { this . log ( "Error while invoking %s with %s: %s" , method , Arrays . toString ( args ) , Throwables . getStackTraceAsString ( e ) ) ; throw e ; } } catch ( InvocationTargetException e ) { throw new JsiiException ( e . getTargetException ( ) ) ; } catch ( IllegalAccessException e ) { throw new JsiiException ( e ) ; } finally { method . setAccessible ( accessibility ) ; } } | Invokes a Java method even if the method is protected . |
25,402 | private void processCallback ( final Callback callback ) { try { JsonNode result = handleCallback ( callback ) ; this . getClient ( ) . completeCallback ( callback , null , result ) ; } catch ( JsiiException e ) { this . getClient ( ) . completeCallback ( callback , e . getMessage ( ) , null ) ; } } | Process a single callback by invoking the native method it refers to . |
25,403 | private Method findCallbackMethod ( final Class < ? > klass , final String signature ) { for ( Method method : klass . getMethods ( ) ) { if ( method . toString ( ) . equals ( signature ) ) { return method ; } } throw new JsiiException ( "Unable to find callback method with signature: " + signature ) ; } | Finds the Java method that implements a callback . |
25,404 | private static Collection < JsiiOverride > discoverOverrides ( final Class < ? > classToInspect ) { Map < String , JsiiOverride > overrides = new HashMap < > ( ) ; Class < ? > klass = classToInspect ; while ( klass != null && klass . getDeclaredAnnotationsByType ( Jsii . class ) . length == 0 && klass != Object . class ) { for ( Method method : klass . getDeclaredMethods ( ) ) { if ( Modifier . isPrivate ( method . getModifiers ( ) ) ) { continue ; } String methodName = method . getName ( ) ; if ( isJavaPropertyMethod ( methodName ) ) { String propertyName = javaPropertyToJSProperty ( methodName ) ; if ( overrides . containsKey ( propertyName ) ) { continue ; } JsiiOverride override = new JsiiOverride ( ) ; override . setProperty ( propertyName ) ; overrides . put ( propertyName , override ) ; } else { if ( overrides . containsKey ( methodName ) ) { continue ; } JsiiOverride override = new JsiiOverride ( ) ; override . setMethod ( methodName ) ; override . setCookie ( method . toString ( ) ) ; overrides . put ( methodName , override ) ; } } klass = klass . getSuperclass ( ) ; } return overrides . values ( ) ; } | Prepare a list of methods which are overridden by Java classes . |
25,405 | static Jsii tryGetJsiiAnnotation ( final Class < ? > type , final boolean inherited ) { Jsii [ ] ann ; if ( inherited ) { ann = ( Jsii [ ] ) type . getAnnotationsByType ( Jsii . class ) ; } else { ann = ( Jsii [ ] ) type . getDeclaredAnnotationsByType ( Jsii . class ) ; } if ( ann . length == 0 ) { return null ; } return ann [ 0 ] ; } | Attempts to find the |
25,406 | String loadModuleForClass ( Class < ? > nativeClass ) { final Jsii jsii = tryGetJsiiAnnotation ( nativeClass , true ) ; if ( jsii == null ) { throw new JsiiException ( "Unable to find @Jsii annotation for class" ) ; } this . loadModule ( jsii . module ( ) ) ; return jsii . fqn ( ) ; } | Given a java class that extends a Jsii proxy loads the corresponding jsii module and returns the FQN of the jsii type . |
25,407 | static String readString ( final InputStream is ) { try ( final Scanner s = new Scanner ( is , "UTF-8" ) ) { s . useDelimiter ( "\\A" ) ; if ( s . hasNext ( ) ) { return s . next ( ) ; } else { return "" ; } } } | Reads a string from an input stream . |
25,408 | static String extractResource ( final Class < ? > klass , final String resourceName , final String outputDirectory ) throws IOException { String directory = outputDirectory ; if ( directory == null ) { directory = Files . createTempDirectory ( "jsii-java-runtime-resource" ) . toString ( ) ; } Path target = Paths . get ( directory , resourceName ) ; Files . createDirectories ( target . getParent ( ) ) ; try ( InputStream inputStream = klass . getResourceAsStream ( resourceName ) ) { Files . copy ( inputStream , target ) ; } return target . toAbsolutePath ( ) . toString ( ) ; } | Extracts a resource file from the . jar and saves it into an output directory . |
25,409 | protected final < T > T jsiiCall ( final String method , final Class < T > returnType , final Object ... args ) { return JsiiObjectMapper . treeToValue ( JsiiObject . engine . getClient ( ) . callMethod ( this . objRef , method , JsiiObjectMapper . valueToTree ( args ) ) , returnType ) ; } | Calls a JavaScript method on the object . |
25,410 | protected static < T > T jsiiStaticCall ( final Class < ? > nativeClass , final String method , final Class < T > returnType , final Object ... args ) { String fqn = engine . loadModuleForClass ( nativeClass ) ; return JsiiObjectMapper . treeToValue ( engine . getClient ( ) . callStaticMethod ( fqn , method , JsiiObjectMapper . valueToTree ( args ) ) , returnType ) ; } | Calls a static method . |
25,411 | protected final < T > T jsiiAsyncCall ( final String method , final Class < T > returnType , final Object ... args ) { JsiiClient client = engine . getClient ( ) ; JsiiPromise promise = client . beginAsyncMethod ( this . objRef , method , JsiiObjectMapper . valueToTree ( args ) ) ; engine . processAllPendingCallbacks ( ) ; return JsiiObjectMapper . treeToValue ( client . endAsyncMethod ( promise ) , returnType ) ; } | Calls an async method on the object . |
25,412 | protected final < T > T jsiiGet ( final String property , final Class < T > type ) { return JsiiObjectMapper . treeToValue ( engine . getClient ( ) . getPropertyValue ( this . objRef , property ) , type ) ; } | Gets a property value from the object . |
25,413 | protected static < T > T jsiiStaticGet ( final Class < ? > nativeClass , final String property , final Class < T > type ) { String fqn = engine . loadModuleForClass ( nativeClass ) ; return JsiiObjectMapper . treeToValue ( engine . getClient ( ) . getStaticPropertyValue ( fqn , property ) , type ) ; } | Returns the value of a static property . |
25,414 | protected final void jsiiSet ( final String property , final Object value ) { engine . getClient ( ) . setPropertyValue ( this . objRef , property , JsiiObjectMapper . valueToTree ( value ) ) ; } | Sets a property value of an object . |
25,415 | protected static void jsiiStaticSet ( final Class < ? > nativeClass , final String property , final Object value ) { String fqn = engine . loadModuleForClass ( nativeClass ) ; engine . getClient ( ) . setStaticPropertyValue ( fqn , property , JsiiObjectMapper . valueToTree ( value ) ) ; } | Sets a value for a static property . |
25,416 | @ RequiresPermission ( Manifest . permission . BLUETOOTH ) static void checkAdapterStateOn ( final BluetoothAdapter adapter ) { if ( adapter == null || adapter . getState ( ) != BluetoothAdapter . STATE_ON ) { throw new IllegalStateException ( "BT Adapter is not turned ON" ) ; } } | Ensure Bluetooth is turned on . |
25,417 | private static boolean matchesServiceUuid ( final UUID uuid , final UUID mask , final UUID data ) { if ( mask == null ) { return uuid . equals ( data ) ; } if ( ( uuid . getLeastSignificantBits ( ) & mask . getLeastSignificantBits ( ) ) != ( data . getLeastSignificantBits ( ) & mask . getLeastSignificantBits ( ) ) ) { return false ; } return ( ( uuid . getMostSignificantBits ( ) & mask . getMostSignificantBits ( ) ) == ( data . getMostSignificantBits ( ) & mask . getMostSignificantBits ( ) ) ) ; } | Check if the uuid pattern matches the particular service uuid . |
25,418 | @ SuppressWarnings ( "BooleanMethodIsAlwaysInverted" ) private boolean matchesPartialData ( final byte [ ] data , final byte [ ] dataMask , final byte [ ] parsedData ) { if ( data == null ) { return parsedData != null ; } if ( parsedData == null || parsedData . length < data . length ) { return false ; } if ( dataMask == null ) { for ( int i = 0 ; i < data . length ; ++ i ) { if ( parsedData [ i ] != data [ i ] ) { return false ; } } return true ; } for ( int i = 0 ; i < data . length ; ++ i ) { if ( ( dataMask [ i ] & parsedData [ i ] ) != ( dataMask [ i ] & data [ i ] ) ) { return false ; } } return true ; } | Check whether the data pattern matches the parsed data . |
25,419 | public synchronized static BluetoothLeScannerCompat getScanner ( ) { if ( instance != null ) return instance ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . O ) return instance = new BluetoothLeScannerImplOreo ( ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . M ) return instance = new BluetoothLeScannerImplMarshmallow ( ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . LOLLIPOP ) return instance = new BluetoothLeScannerImplLollipop ( ) ; return instance = new BluetoothLeScannerImplJB ( ) ; } | Returns the scanner compat object |
25,420 | private void setPowerSaveSettings ( ) { long minRest = Long . MAX_VALUE , minScan = Long . MAX_VALUE ; synchronized ( wrappers ) { for ( final ScanCallbackWrapper wrapper : wrappers . values ( ) ) { final ScanSettings settings = wrapper . scanSettings ; if ( settings . hasPowerSaveMode ( ) ) { if ( minRest > settings . getPowerSaveRest ( ) ) { minRest = settings . getPowerSaveRest ( ) ; } if ( minScan > settings . getPowerSaveScan ( ) ) { minScan = settings . getPowerSaveScan ( ) ; } } } } if ( minRest < Long . MAX_VALUE && minScan < Long . MAX_VALUE ) { powerSaveRestInterval = minRest ; powerSaveScanInterval = minScan ; if ( powerSaveHandler != null ) { powerSaveHandler . removeCallbacks ( powerSaveScanTask ) ; powerSaveHandler . removeCallbacks ( powerSaveSleepTask ) ; powerSaveHandler . postDelayed ( powerSaveSleepTask , powerSaveScanInterval ) ; } } else { powerSaveRestInterval = powerSaveScanInterval = 0 ; if ( powerSaveHandler != null ) { powerSaveHandler . removeCallbacks ( powerSaveScanTask ) ; powerSaveHandler . removeCallbacks ( powerSaveSleepTask ) ; } } } | This method goes through registered callbacks and sets the power rest and scan intervals to next lowest value . |
25,421 | public void setCode ( ExprCode code ) { mCode = code ; mStartPos = mCode . mStartPos ; mCurIndex = mStartPos ; } | private int mCount ; |
25,422 | public static boolean isRtl ( ) { if ( sEnable && Build . VERSION . SDK_INT >= Build . VERSION_CODES . JELLY_BEAN_MR1 ) { return View . LAYOUT_DIRECTION_RTL == TextUtils . getLayoutDirectionFromLocale ( Locale . getDefault ( ) ) ; } return false ; } | In Rtl env or not . |
25,423 | public static int getRealLeft ( boolean isRtl , int parentLeft , int parentWidth , int left , int width ) { if ( isRtl ) { left -= parentLeft ; left = parentWidth - width - left ; left += parentLeft ; } return left ; } | Convert left to RTL left if need . |
25,424 | public static ViewServer get ( Context context ) { ApplicationInfo info = context . getApplicationInfo ( ) ; if ( BUILD_TYPE_USER . equals ( Build . TYPE ) && ( info . flags & ApplicationInfo . FLAG_DEBUGGABLE ) != 0 ) { if ( sServer == null ) { sServer = new ViewServer ( ViewServer . VIEW_SERVER_DEFAULT_PORT ) ; } if ( ! sServer . isRunning ( ) ) { try { sServer . start ( ) ; } catch ( IOException e ) { Log . d ( LOG_TAG , "Error:" , e ) ; } } } else { sServer = new NoopViewServer ( ) ; } return sServer ; } | Returns a unique instance of the ViewServer . This method should only be called from the main thread of your application . The server will have the same lifetime as your process . |
25,425 | public void removeWindow ( View view ) { mWindowsLock . writeLock ( ) . lock ( ) ; try { mWindows . remove ( view . getRootView ( ) ) ; } finally { mWindowsLock . writeLock ( ) . unlock ( ) ; } fireWindowsChangedEvent ( ) ; } | Invoke this method to unregister a view hierarchy . |
25,426 | public void setFocusedWindow ( View view ) { mFocusLock . writeLock ( ) . lock ( ) ; try { mFocusedWindow = view == null ? null : view . getRootView ( ) ; } finally { mFocusLock . writeLock ( ) . unlock ( ) ; } fireFocusChangedEvent ( ) ; } | Invoke this method to change the currently focused window . |
25,427 | public void run ( ) { try { mServer = new ServerSocket ( mPort , VIEW_SERVER_MAX_CONNECTIONS , InetAddress . getLocalHost ( ) ) ; } catch ( Exception e ) { Log . w ( LOG_TAG , "Starting ServerSocket error: " , e ) ; } while ( mServer != null && Thread . currentThread ( ) == mThread ) { try { Socket client = mServer . accept ( ) ; if ( mThreadPool != null ) { mThreadPool . submit ( new ViewServerWorker ( client ) ) ; } else { try { client . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } catch ( Exception e ) { Log . w ( LOG_TAG , "Connection error: " , e ) ; } } } | Main server loop . |
25,428 | public static String removeQueryParameter ( String url , String key ) { String [ ] urlParts = url . split ( "\\?" ) ; if ( urlParts . length == 2 ) { Map < String , List < String > > paramMap = extractParametersFromQueryString ( urlParts [ 1 ] ) ; if ( paramMap . containsKey ( key ) ) { String queryValue = paramMap . get ( key ) . get ( 0 ) ; String result = url . replace ( key + "=" + queryValue , "" ) ; result = result . replace ( "?&" , "?" ) . replace ( "&&" , "&" ) ; if ( result . endsWith ( "&" ) ) { return result . substring ( 0 , result . length ( ) - 1 ) ; } else { return result ; } } } return url ; } | Remove the given key from the url query string and return the new URL as String . |
25,429 | protected void verifyParameterLegality ( Parameter ... parameters ) { for ( Parameter parameter : parameters ) if ( illegalParamNames . contains ( parameter . name ) ) { throw new IllegalArgumentException ( "Parameter '" + parameter . name + "' is reserved for RestFB use - you cannot specify it yourself." ) ; } } | Verifies that the provided parameter names don t collide with the ones we internally pass along to Facebook . |
25,430 | public < T extends BaseNlpEntity > List < T > getEntities ( Class < T > clazz ) { List < BaseNlpEntity > resultList = new ArrayList < > ( ) ; for ( BaseNlpEntity item : getEntities ( ) ) { if ( item . getClass ( ) . equals ( clazz ) ) { resultList . add ( item ) ; } } return ( List < T > ) resultList ; } | returns a subset of the found entities . |
25,431 | private void fillOrder ( JsonObject summary ) { if ( summary != null ) { order = summary . getString ( "order" , order ) ; } if ( order == null && openGraphCommentOrder != null ) { order = openGraphCommentOrder ; } } | set the order the comments are sorted |
25,432 | private void fillCanComment ( JsonObject summary ) { if ( summary != null && summary . get ( "can_comment" ) != null ) { canComment = summary . get ( "can_comment" ) . asBoolean ( ) ; } if ( canComment == null && openGraphCanComment != null ) { canComment = openGraphCanComment ; } } | set the can_comment |
25,433 | public static byte [ ] decodeBase64 ( String base64 ) { if ( base64 == null ) throw new NullPointerException ( "Parameter 'base64' cannot be null." ) ; String fixedBase64 = padBase64 ( base64 ) ; return Base64 . getDecoder ( ) . decode ( fixedBase64 ) ; } | Decodes a base64 - encoded string padding out if necessary . |
25,434 | public static String encodeAppSecretProof ( String appSecret , String accessToken ) { try { byte [ ] key = appSecret . getBytes ( StandardCharsets . UTF_8 ) ; SecretKeySpec signingKey = new SecretKeySpec ( key , "HmacSHA256" ) ; Mac mac = Mac . getInstance ( "HmacSHA256" ) ; mac . init ( signingKey ) ; byte [ ] raw = mac . doFinal ( accessToken . getBytes ( ) ) ; byte [ ] hex = encodeHex ( raw ) ; return new String ( hex , StandardCharsets . UTF_8 ) ; } catch ( Exception e ) { throw new IllegalStateException ( "Creation of appsecret_proof has failed" , e ) ; } } | Generates an appsecret_proof for facebook . |
25,435 | public JsonObject remove ( String name ) { if ( name == null ) { throw new NullPointerException ( NAME_IS_NULL ) ; } int index = indexOf ( name ) ; if ( index != - 1 ) { table . remove ( index ) ; names . remove ( index ) ; values . remove ( index ) ; } return this ; } | Removes a member with the specified name from this object . If this object contains multiple members with the given name only the last one is removed . If this object does not contain a member with the specified name the object is not modified . |
25,436 | public JsonObject merge ( JsonObject object ) { if ( object == null ) { throw new NullPointerException ( OBJECT_IS_NULL ) ; } for ( Member member : object ) { this . set ( member . name , member . value ) ; } return this ; } | Copies all members of the specified object into this object . When the specified object contains members with names that also exist in this object the existing values in this object will be replaced by the corresponding values in the specified object . |
25,437 | protected String urlDecodeSignedRequestToken ( String signedRequestToken ) { verifyParameterPresence ( "signedRequestToken" , signedRequestToken ) ; return signedRequestToken . replace ( "-" , "+" ) . replace ( "_" , "/" ) . trim ( ) ; } | Decodes a component of a signed request received from Facebook using FB s special URL - encoding strategy . |
25,438 | protected boolean verifySignedRequest ( String appSecret , String algorithm , String encodedPayload , byte [ ] signature ) { verifyParameterPresence ( "appSecret" , appSecret ) ; verifyParameterPresence ( "algorithm" , algorithm ) ; verifyParameterPresence ( "encodedPayload" , encodedPayload ) ; verifyParameterPresence ( "signature" , signature ) ; if ( "HMAC-SHA256" . equalsIgnoreCase ( algorithm ) ) { algorithm = "HMACSHA256" ; } try { Mac mac = Mac . getInstance ( algorithm ) ; mac . init ( new SecretKeySpec ( toBytes ( appSecret ) , algorithm ) ) ; byte [ ] payloadSignature = mac . doFinal ( toBytes ( encodedPayload ) ) ; return Arrays . equals ( signature , payloadSignature ) ; } catch ( Exception e ) { throw new FacebookSignedRequestVerificationException ( "Unable to perform signed request verification" , e ) ; } } | Verifies that the signed request is really from Facebook . |
25,439 | protected String toParameterString ( boolean withJsonParameter , Parameter ... parameters ) { if ( ! isBlank ( accessToken ) ) { parameters = parametersWithAdditionalParameter ( Parameter . with ( ACCESS_TOKEN_PARAM_NAME , accessToken ) , parameters ) ; } if ( ! isBlank ( accessToken ) && ! isBlank ( appSecret ) ) { parameters = parametersWithAdditionalParameter ( Parameter . with ( APP_SECRET_PROOF_PARAM_NAME , obtainAppSecretProof ( accessToken , appSecret ) ) , parameters ) ; } if ( withJsonParameter ) { parameters = parametersWithAdditionalParameter ( Parameter . with ( FORMAT_PARAM_NAME , "json" ) , parameters ) ; } StringBuilder parameterStringBuilder = new StringBuilder ( ) ; boolean first = true ; for ( Parameter parameter : parameters ) { if ( first ) { first = false ; } else { parameterStringBuilder . append ( "&" ) ; } parameterStringBuilder . append ( urlEncode ( parameter . name ) ) ; parameterStringBuilder . append ( "=" ) ; parameterStringBuilder . append ( urlEncodedValueForParameterName ( parameter . name , parameter . value ) ) ; } return parameterStringBuilder . toString ( ) ; } | Generate the parameter string to be included in the Facebook API request . |
25,440 | protected String getFacebookGraphEndpointUrl ( ) { if ( apiVersion . isUrlElementRequired ( ) ) { return getFacebookEndpointUrls ( ) . getGraphEndpoint ( ) + '/' + apiVersion . getUrlElement ( ) ; } else { return getFacebookEndpointUrls ( ) . getGraphEndpoint ( ) ; } } | Returns the base endpoint URL for the Graph API . |
25,441 | protected String getFacebookGraphVideoEndpointUrl ( ) { if ( apiVersion . isUrlElementRequired ( ) ) { return getFacebookEndpointUrls ( ) . getGraphVideoEndpoint ( ) + '/' + apiVersion . getUrlElement ( ) ; } else { return getFacebookEndpointUrls ( ) . getGraphVideoEndpoint ( ) ; } } | Returns the base endpoint URL for the Graph API s video upload functionality . |
25,442 | public Double getDoubleFrom ( JsonValue json ) { if ( json . isNumber ( ) ) { return json . asDouble ( ) ; } else { return Double . valueOf ( json . asString ( ) ) ; } } | convert jsonvalue to a Double |
25,443 | public Integer getIntegerFrom ( JsonValue json ) { if ( json . isNumber ( ) ) { return json . asInt ( ) ; } else { return Integer . valueOf ( json . asString ( ) ) ; } } | convert jsonvalue to a Integer |
25,444 | public String getStringFrom ( JsonValue json ) { if ( json . isString ( ) ) { return json . asString ( ) ; } else { return json . toString ( ) ; } } | convert jsonvalue to a String |
25,445 | public Float getFloatFrom ( JsonValue json ) { if ( json . isNumber ( ) ) { return json . asFloat ( ) ; } else { return new BigDecimal ( json . asString ( ) ) . floatValue ( ) ; } } | convert jsonvalue to a Float |
25,446 | public BigInteger getBigIntegerFrom ( JsonValue json ) { if ( json . isString ( ) ) { return new BigInteger ( json . asString ( ) ) ; } else { return new BigInteger ( json . toString ( ) ) ; } } | convert jsonvalue to a BigInteger |
25,447 | public Long getLongFrom ( JsonValue json ) { if ( json . isNumber ( ) ) { return json . asLong ( ) ; } else { return Long . valueOf ( json . asString ( ) ) ; } } | convert jsonvalue to a Long |
25,448 | public BigDecimal getBigDecimalFrom ( JsonValue json ) { if ( json . isString ( ) ) { return new BigDecimal ( json . asString ( ) ) ; } else { return new BigDecimal ( json . toString ( ) ) ; } } | convert jsonvalue to a BigDecimal |
25,449 | private void fillTotalCount ( JsonObject summary ) { if ( totalCount == 0 && summary != null && summary . get ( "total_count" ) != null ) { totalCount = summary . getLong ( "total_count" , totalCount ) ; } } | add change count value if summary is set and count is empty |
25,450 | protected String createFormFieldName ( BinaryAttachment binaryAttachment ) { if ( binaryAttachment . getFieldName ( ) != null ) { return binaryAttachment . getFieldName ( ) ; } String name = binaryAttachment . getFilename ( ) ; int fileExtensionIndex = name . lastIndexOf ( '.' ) ; return fileExtensionIndex > 0 ? name . substring ( 0 , fileExtensionIndex ) : name ; } | Creates the form field name for the binary attachment filename by stripping off the file extension - for example the filename test . png would return test . |
25,451 | public InnerMessagingItem getItem ( ) { if ( optin != null ) { return optin ; } if ( postback != null ) { return postback ; } if ( delivery != null ) { return delivery ; } if ( read != null ) { return read ; } if ( accountLinking != null ) { return accountLinking ; } if ( message != null ) { return message ; } if ( checkoutUpdate != null ) { return checkoutUpdate ; } if ( payment != null ) { return payment ; } if ( referral != null ) { return referral ; } if ( policyEnforcement != null ) { return policyEnforcement ; } if ( passThreadControl != null ) { return passThreadControl ; } if ( takeThreadControl != null ) { return takeThreadControl ; } if ( requestThreadControl != null ) { return requestThreadControl ; } if ( appRoles != null ) { return appRoles ; } return null ; } | generic access to the inner item . |
25,452 | public List < String > getRoles ( String appId ) { if ( roles . containsKey ( appId ) ) { return Collections . unmodifiableList ( roles . get ( appId ) ) ; } else { return null ; } } | get the roles to the given app id |
25,453 | protected void skipResponseStatusExceptionParsing ( String json ) throws ResponseErrorJsonParsingException { if ( ! json . startsWith ( "{" ) ) { throw new ResponseErrorJsonParsingException ( ) ; } int subStrEnd = Math . min ( 50 , json . length ( ) ) ; if ( ! json . substring ( 0 , subStrEnd ) . contains ( "\"error\"" ) ) { throw new ResponseErrorJsonParsingException ( ) ; } } | checks if a string may be a json and contains a error string somewhere this is used for speedup the error parsing |
25,454 | public InputStream getData ( ) { if ( data != null ) { return new ByteArrayInputStream ( data ) ; } else if ( dataStream != null ) { return dataStream ; } else { throw new IllegalStateException ( "Either the byte[] or the stream mustn't be null at this point." ) ; } } | The attachment s data . |
25,455 | public String getContentType ( ) { if ( contentType != null ) { return contentType ; } if ( dataStream != null ) { try { contentType = URLConnection . guessContentTypeFromStream ( dataStream ) ; } catch ( IOException ioe ) { } } if ( data != null ) { contentType = URLConnection . guessContentTypeFromName ( filename ) ; } if ( contentType == null ) { contentType = "application/octet-stream" ; } return contentType ; } | return the given content type or try to guess from stream or file name . Depending of the available data . |
25,456 | protected void logMultipleMappingFailedForField ( String facebookFieldName , FieldWithAnnotation < Facebook > fieldWithAnnotation , String json ) { if ( ! MAPPER_LOGGER . isTraceEnabled ( ) ) { return ; } Field field = fieldWithAnnotation . getField ( ) ; MAPPER_LOGGER . trace ( "Could not map '{}' to {}. {}, but continuing on because '{}" + "' is mapped to multiple fields in {}. JSON is {}" , facebookFieldName , field . getDeclaringClass ( ) . getSimpleName ( ) , field . getName ( ) , facebookFieldName , field . getDeclaringClass ( ) . getSimpleName ( ) , json ) ; } | Dumps out a log message when one of a multiple - mapped Facebook field name JSON - to - Java mapping operation fails . |
25,457 | protected Set < String > facebookFieldNamesWithMultipleMappings ( List < FieldWithAnnotation < Facebook > > fieldsWithAnnotation ) { Map < String , Integer > facebookFieldsNamesWithOccurrenceCount = new HashMap < > ( ) ; Set < String > facebookFieldNamesWithMultipleMappings = new HashSet < > ( ) ; for ( FieldWithAnnotation < Facebook > fieldWithAnnotation : fieldsWithAnnotation ) { String fieldName = getFacebookFieldName ( fieldWithAnnotation ) ; int occurrenceCount = facebookFieldsNamesWithOccurrenceCount . containsKey ( fieldName ) ? facebookFieldsNamesWithOccurrenceCount . get ( fieldName ) : 0 ; facebookFieldsNamesWithOccurrenceCount . put ( fieldName , occurrenceCount + 1 ) ; } for ( Entry < String , Integer > entry : facebookFieldsNamesWithOccurrenceCount . entrySet ( ) ) { if ( entry . getValue ( ) > 1 ) { facebookFieldNamesWithMultipleMappings . add ( entry . getKey ( ) ) ; } } return unmodifiableSet ( facebookFieldNamesWithMultipleMappings ) ; } | Finds any Facebook JSON fields that are mapped to more than 1 Java field . |
25,458 | public static boolean isEmptyCollectionOrMap ( Object obj ) { if ( obj instanceof Collection ) { return ( ( Collection ) obj ) . isEmpty ( ) ; } return ( obj instanceof Map && ( ( Map ) obj ) . isEmpty ( ) ) ; } | Checks is the object is a empty collection or map . |
25,459 | public static RestFBLogger getLoggerInstance ( String logCategory ) { Object obj ; Class [ ] ctrTypes = new Class [ ] { String . class } ; Object [ ] ctrArgs = new Object [ ] { logCategory } ; try { Constructor loggerClassConstructor = usedLoggerClass . getConstructor ( ctrTypes ) ; obj = loggerClassConstructor . newInstance ( ctrArgs ) ; } catch ( Exception e ) { throw new FacebookLoggerException ( "cannot create logger: " + logCategory ) ; } return ( RestFBLogger ) obj ; } | returns the instance of the logger that belongs to the category . |
25,460 | static int limitedCompare ( CharSequence left , CharSequence right , final boolean caseSensitive , final int threshold ) { if ( left == null || right == null ) { throw new IllegalArgumentException ( "Strings must not be null" ) ; } if ( threshold < 0 ) { throw new IllegalArgumentException ( "Threshold must not be negative" ) ; } int n = left . length ( ) ; int m = right . length ( ) ; if ( n == 0 ) { return m <= threshold ? m : - 1 ; } else if ( m == 0 ) { return n <= threshold ? n : - 1 ; } if ( n > m ) { final CharSequence tmp = left ; left = right ; right = tmp ; n = m ; m = right . length ( ) ; } int [ ] p = new int [ n + 1 ] ; int [ ] d = new int [ n + 1 ] ; int [ ] tempD ; final int boundary = Math . min ( n , threshold ) + 1 ; for ( int i = 0 ; i < boundary ; i ++ ) { p [ i ] = i ; } Arrays . fill ( p , boundary , p . length , Integer . MAX_VALUE ) ; Arrays . fill ( d , Integer . MAX_VALUE ) ; for ( int j = 1 ; j <= m ; j ++ ) { final char rightJ = right . charAt ( j - 1 ) ; d [ 0 ] = j ; final int min = Math . max ( 1 , j - threshold ) ; final int max = j > Integer . MAX_VALUE - threshold ? n : Math . min ( n , j + threshold ) ; if ( min > max ) { return - 1 ; } if ( min > 1 ) { d [ min - 1 ] = Integer . MAX_VALUE ; } for ( int i = min ; i <= max ; i ++ ) { final char leftI = left . charAt ( i - 1 ) ; if ( equals ( leftI , rightJ , caseSensitive ) ) { d [ i ] = p [ i - 1 ] ; } else { d [ i ] = 1 + Math . min ( Math . min ( d [ i - 1 ] , p [ i ] ) , p [ i - 1 ] ) ; } } tempD = p ; p = d ; d = tempD ; } if ( p [ n ] <= threshold ) { return p [ n ] ; } return - 1 ; } | Find the Levenshtein distance between two CharSequences if it s less than or equal to a given threshold . |
25,461 | private void updateList ( final File filename ) { try { final URI reletivePath = toURI ( filename . getAbsolutePath ( ) . substring ( new File ( normalize ( tempDir . toString ( ) ) ) . getPath ( ) . length ( ) + 1 ) ) ; final FileInfo f = job . getOrCreateFileInfo ( reletivePath ) ; if ( hasConref ) { f . hasConref = true ; } if ( hasKeyref ) { f . hasKeyref = true ; } job . write ( ) ; } catch ( final RuntimeException e ) { throw e ; } catch ( final Exception e ) { logger . error ( e . getMessage ( ) , e ) ; } } | Update conref list in job configuration and in conref list file . |
25,462 | public void addPlugins ( final String s ) { final StringTokenizer t = new StringTokenizer ( s , REQUIREMENT_SEPARATOR ) ; while ( t . hasMoreTokens ( ) ) { plugins . add ( t . nextToken ( ) ) ; } } | Add plugins . |
25,463 | private void refineAction ( final Action action , final FilterKey key ) { if ( key . value != null && bindingMap != null && ! bindingMap . isEmpty ( ) ) { final Map < String , Set < Element > > schemeMap = bindingMap . get ( key . attribute ) ; if ( schemeMap != null && ! schemeMap . isEmpty ( ) ) { for ( final Set < Element > submap : schemeMap . values ( ) ) { for ( final Element e : submap ) { final Element subRoot = searchForKey ( e , key . value ) ; if ( subRoot != null ) { insertAction ( subRoot , key . attribute , action ) ; } } } } } } | Refine action key with information from subject schemes . |
25,464 | private void insertAction ( final Element subTree , final QName attName , final Action action ) { if ( subTree == null || action == null ) { return ; } final LinkedList < Element > queue = new LinkedList < > ( ) ; NodeList children = subTree . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { if ( children . item ( i ) . getNodeType ( ) == Node . ELEMENT_NODE ) { queue . offer ( ( Element ) children . item ( i ) ) ; } } while ( ! queue . isEmpty ( ) ) { final Element node = queue . poll ( ) ; children = node . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { if ( children . item ( i ) . getNodeType ( ) == Node . ELEMENT_NODE ) { queue . offer ( ( Element ) children . item ( i ) ) ; } } if ( SUBJECTSCHEME_SUBJECTDEF . matches ( node ) ) { final String key = node . getAttribute ( ATTRIBUTE_NAME_KEYS ) ; if ( key != null && ! key . trim ( ) . isEmpty ( ) ) { final FilterKey k = new FilterKey ( attName , key ) ; if ( ! filterMap . containsKey ( k ) ) { filterMap . put ( k , action ) ; } } } } } | Insert subject scheme based action into filetermap if key not present in the map |
25,465 | private Element searchForKey ( final Element root , final String keyValue ) { if ( root == null || keyValue == null ) { return null ; } final LinkedList < Element > queue = new LinkedList < > ( ) ; queue . add ( root ) ; while ( ! queue . isEmpty ( ) ) { final Element node = queue . removeFirst ( ) ; final NodeList children = node . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { if ( children . item ( i ) . getNodeType ( ) == Node . ELEMENT_NODE ) { queue . add ( ( Element ) children . item ( i ) ) ; } } if ( SUBJECTSCHEME_SUBJECTDEF . matches ( node ) ) { final String key = node . getAttribute ( ATTRIBUTE_NAME_KEYS ) ; if ( keyValue . equals ( key ) ) { return node ; } } } return null ; } | Search subject scheme elements for a given key |
25,466 | private void insertAction ( final Action action , final FilterKey key ) { if ( filterMap . get ( key ) == null ) { filterMap . put ( key , action ) ; } else { logger . info ( MessageUtils . getMessage ( "DOTJ007I" , key . toString ( ) ) . toString ( ) ) ; } } | Insert action into filetermap if key not present in the map |
25,467 | private void outputSubjectScheme ( ) throws DITAOTException { try { final Map < URI , Set < URI > > graph = SubjectSchemeReader . readMapFromXML ( new File ( job . tempDir , FILE_NAME_SUBJECT_RELATION ) ) ; final Queue < URI > queue = new LinkedList < > ( graph . keySet ( ) ) ; final Set < URI > visitedSet = new HashSet < > ( ) ; final DocumentBuilder builder = XMLUtils . getDocumentBuilder ( ) ; builder . setEntityResolver ( CatalogUtils . getCatalogResolver ( ) ) ; while ( ! queue . isEmpty ( ) ) { final URI parent = queue . poll ( ) ; final Set < URI > children = graph . get ( parent ) ; if ( children != null ) { queue . addAll ( children ) ; } if ( ROOT_URI . equals ( parent ) || visitedSet . contains ( parent ) ) { continue ; } visitedSet . add ( parent ) ; final File tmprel = new File ( FileUtils . resolve ( job . tempDir , parent ) + SUBJECT_SCHEME_EXTENSION ) ; final Document parentRoot ; if ( ! tmprel . exists ( ) ) { final URI src = job . getFileInfo ( parent ) . src ; parentRoot = builder . parse ( src . toString ( ) ) ; } else { parentRoot = builder . parse ( tmprel ) ; } if ( children != null ) { for ( final URI childpath : children ) { final Document childRoot = builder . parse ( job . getInputFile ( ) . resolve ( childpath . getPath ( ) ) . toString ( ) ) ; mergeScheme ( parentRoot , childRoot ) ; generateScheme ( new File ( job . tempDir , childpath . getPath ( ) + SUBJECT_SCHEME_EXTENSION ) , childRoot ) ; } } generateScheme ( new File ( job . tempDir , parent . getPath ( ) + SUBJECT_SCHEME_EXTENSION ) , parentRoot ) ; } } catch ( final RuntimeException e ) { throw e ; } catch ( final Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new DITAOTException ( e ) ; } } | Output subject schema file . |
25,468 | private void generateScheme ( final File filename , final Document root ) throws DITAOTException { final File p = filename . getParentFile ( ) ; if ( ! p . exists ( ) && ! p . mkdirs ( ) ) { throw new DITAOTException ( "Failed to make directory " + p . getAbsolutePath ( ) ) ; } Result res = null ; try { res = new StreamResult ( new FileOutputStream ( filename ) ) ; final DOMSource ds = new DOMSource ( root ) ; final TransformerFactory tff = TransformerFactory . newInstance ( ) ; final Transformer tf = tff . newTransformer ( ) ; tf . transform ( ds , res ) ; } catch ( final RuntimeException e ) { throw e ; } catch ( final Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new DITAOTException ( e ) ; } finally { try { close ( res ) ; } catch ( IOException e ) { throw new DITAOTException ( e ) ; } } } | Serialize subject scheme file . |
25,469 | public static File getPathtoProject ( final File filename , final File traceFilename , final File inputMap , final Job job ) { if ( job . getGeneratecopyouter ( ) != Job . Generate . OLDSOLUTION ) { if ( isOutFile ( traceFilename , inputMap ) ) { return toFile ( getRelativePathFromOut ( traceFilename . getAbsoluteFile ( ) , job ) ) ; } else { return getRelativePath ( traceFilename . getAbsoluteFile ( ) , inputMap . getAbsoluteFile ( ) ) . getParentFile ( ) ; } } else { return FileUtils . getRelativePath ( filename ) ; } } | Get path to base directory |
25,470 | private static String getRelativePathFromOut ( final File overflowingFile , final Job job ) { final URI relativePath = URLUtils . getRelativePath ( job . getInputFile ( ) , overflowingFile . toURI ( ) ) ; final File outputDir = job . getOutputDir ( ) . getAbsoluteFile ( ) ; final File outputPathName = new File ( outputDir , "index.html" ) ; final File finalOutFilePathName = resolve ( outputDir , relativePath . getPath ( ) ) ; final File finalRelativePathName = FileUtils . getRelativePath ( finalOutFilePathName , outputPathName ) ; File parentDir = finalRelativePathName . getParentFile ( ) ; if ( parentDir == null || parentDir . getPath ( ) . isEmpty ( ) ) { parentDir = new File ( "." ) ; } return parentDir . getPath ( ) + File . separator ; } | Just for the overflowing files . |
25,471 | public AbstractPipelineOutput execute ( final AbstractPipelineInput input ) throws DITAOTException { final Collection < FileInfo > fis = job . getFileInfo ( fi -> fi . isInput ) ; if ( ! fis . isEmpty ( ) ) { final Map < URI , Map < String , Element > > mapSet = getMapMetadata ( fis ) ; pushMetadata ( mapSet ) ; pullTopicMetadata ( input , fis ) ; } return null ; } | Entry point of MoveMetaModule . |
25,472 | private void pushMetadata ( final Map < URI , Map < String , Element > > mapSet ) { if ( ! mapSet . isEmpty ( ) ) { final DitaMapMetaWriter mapInserter = new DitaMapMetaWriter ( ) ; mapInserter . setLogger ( logger ) ; mapInserter . setJob ( job ) ; for ( final Entry < URI , Map < String , Element > > entry : mapSet . entrySet ( ) ) { final URI key = stripFragment ( entry . getKey ( ) ) ; final FileInfo fi = job . getFileInfo ( key ) ; if ( fi == null ) { logger . error ( "File " + new File ( job . tempDir , key . getPath ( ) ) + " was not found." ) ; continue ; } final URI targetFileName = job . tempDirURI . resolve ( fi . uri ) ; assert targetFileName . isAbsolute ( ) ; if ( fi . format != null && ATTR_FORMAT_VALUE_DITAMAP . equals ( fi . format ) ) { mapInserter . setMetaTable ( entry . getValue ( ) ) ; if ( toFile ( targetFileName ) . exists ( ) ) { logger . info ( "Processing " + targetFileName ) ; mapInserter . read ( toFile ( targetFileName ) ) ; } else { logger . error ( "File " + targetFileName + " does not exist" ) ; } } } final DitaMetaWriter topicInserter = new DitaMetaWriter ( ) ; topicInserter . setLogger ( logger ) ; topicInserter . setJob ( job ) ; for ( final Entry < URI , Map < String , Element > > entry : mapSet . entrySet ( ) ) { final URI key = stripFragment ( entry . getKey ( ) ) ; final FileInfo fi = job . getFileInfo ( key ) ; if ( fi == null ) { logger . error ( "File " + new File ( job . tempDir , key . getPath ( ) ) + " was not found." ) ; continue ; } final URI targetFileName = job . tempDirURI . resolve ( fi . uri ) ; assert targetFileName . isAbsolute ( ) ; if ( fi . format == null || fi . format . equals ( ATTR_FORMAT_VALUE_DITA ) ) { final String topicid = entry . getKey ( ) . getFragment ( ) ; topicInserter . setTopicId ( topicid ) ; topicInserter . setMetaTable ( entry . getValue ( ) ) ; if ( toFile ( targetFileName ) . exists ( ) ) { topicInserter . read ( toFile ( targetFileName ) ) ; } else { logger . error ( "File " + targetFileName + " does not exist" ) ; } } } } } | Push information from topicmeta in the map into the corresponding topics and maps . |
25,473 | private Map < URI , Map < String , Element > > getMapMetadata ( final Collection < FileInfo > fis ) { final MapMetaReader metaReader = new MapMetaReader ( ) ; metaReader . setLogger ( logger ) ; metaReader . setJob ( job ) ; for ( final FileInfo f : fis ) { final File mapFile = new File ( job . tempDir , f . file . getPath ( ) ) ; metaReader . read ( mapFile ) ; } return metaReader . getMapping ( ) ; } | Read metadata from topicmeta elements in maps . |
25,474 | private URI getRelativePath ( final URI href ) { final URI keyValue ; final URI inputMap = job . getFileInfo ( fi -> fi . isInput ) . stream ( ) . map ( fi -> fi . uri ) . findFirst ( ) . orElse ( null ) ; if ( inputMap != null ) { final URI tmpMap = job . tempDirURI . resolve ( inputMap ) ; keyValue = tmpMap . resolve ( stripFragment ( href ) ) ; } else { keyValue = job . tempDirURI . resolve ( stripFragment ( href ) ) ; } return URLUtils . getRelativePath ( currentFile , keyValue ) ; } | Update href URI . |
25,475 | private void setActiveProjectProperty ( final String propertyName , final String propertyValue ) { final Project activeProject = getProject ( ) ; if ( activeProject != null ) { activeProject . setProperty ( propertyName , propertyValue ) ; } } | Sets property in active ant project with name specified inpropertyName and value specified in propertyValue parameter |
25,476 | private String [ ] readParamValues ( ) throws BuildException { final ArrayList < String > prop = new ArrayList < > ( ) ; for ( final ParamElem p : params ) { if ( ! p . isValid ( ) ) { throw new BuildException ( "Incomplete parameter" ) ; } if ( isValid ( getProject ( ) , getLocation ( ) , p . getIf ( ) , p . getUnless ( ) ) ) { final int idx = Integer . parseInt ( p . getName ( ) ) - 1 ; if ( idx >= prop . size ( ) ) { prop . ensureCapacity ( idx + 1 ) ; while ( prop . size ( ) < idx + 1 ) { prop . add ( null ) ; } } prop . set ( idx , p . getValue ( ) ) ; } } return prop . toArray ( new String [ 0 ] ) ; } | Read parameter values to an array . |
25,477 | public String getIndexFileName ( final String outputFileRoot ) { final File indexDir = new File ( outputFileRoot ) . getParentFile ( ) ; setFilePath ( indexDir . getAbsolutePath ( ) ) ; return new File ( indexDir , "index.xml" ) . getAbsolutePath ( ) ; } | Get index file name . |
25,478 | public void setDitadir ( final File ditaDir ) { if ( ! ditaDir . isAbsolute ( ) ) { throw new IllegalArgumentException ( "ditadir attribute value must be an absolute path: " + ditaDir ) ; } this . ditaDir = ditaDir ; } | Set the ditaDir . |
25,479 | private Element getTopicDoc ( final URI absolutePathToFile ) { final DocumentBuilder builder = getDocumentBuilder ( ) ; try { final Document doc = builder . parse ( absolutePathToFile . toString ( ) ) ; return doc . getDocumentElement ( ) ; } catch ( final SAXException | IOException e ) { logger . error ( "Failed to parse " + absolutePathToFile + ": " + e . getMessage ( ) , e ) ; } return null ; } | get the document node of a topic file . |
25,480 | public void addSubTerm ( final IndexTerm term ) { int i = 0 ; final int subTermNum = subTerms . size ( ) ; if ( IndexTermPrefix . SEE != term . getTermPrefix ( ) && IndexTermPrefix . SEE_ALSO != term . getTermPrefix ( ) ) { leaf = false ; } for ( ; i < subTermNum ; i ++ ) { final IndexTerm subTerm = subTerms . get ( i ) ; if ( subTerm . equals ( term ) ) { return ; } if ( subTerm . getTermFullName ( ) . equals ( term . getTermFullName ( ) ) && subTerm . getTermKey ( ) . equals ( term . getTermKey ( ) ) ) { subTerm . addTargets ( term . getTargetList ( ) ) ; subTerm . addSubTerms ( term . getSubTerms ( ) ) ; return ; } } if ( i == subTermNum ) { subTerms . add ( term ) ; } } | Add a sub term into the sub term list . |
25,481 | public void addSubTerms ( final List < IndexTerm > terms ) { int subTermsNum ; if ( terms == null ) { return ; } subTermsNum = terms . size ( ) ; for ( int i = 0 ; i < subTermsNum ; i ++ ) { addSubTerm ( terms . get ( i ) ) ; } } | Add all the sub terms in the list . |
25,482 | public void sortSubTerms ( ) { final int subTermNum = subTerms . size ( ) ; if ( subTerms != null && subTermNum > 0 ) { Collections . sort ( subTerms ) ; for ( final IndexTerm subTerm : subTerms ) { subTerm . sortSubTerms ( ) ; } } } | Sort all the subterms iteratively . |
25,483 | public int compareTo ( final IndexTerm obj ) { return DITAOTCollator . getInstance ( termLocale ) . compare ( termKey , obj . getTermKey ( ) ) ; } | Compare the given indexterm with current term . |
25,484 | public void addTargets ( final List < IndexTermTarget > targets ) { int targetNum ; if ( targets == null ) { return ; } targetNum = targets . size ( ) ; for ( int i = 0 ; i < targetNum ; i ++ ) { addTarget ( targets . get ( i ) ) ; } } | Add all the indexterm targets in the list . |
25,485 | public String getTermFullName ( ) { if ( termPrefix == null ) { return termName ; } else { if ( termLocale == null ) { return termPrefix . message + STRING_BLANK + termName ; } else { final String key = "IndexTerm." + termPrefix . message . toLowerCase ( ) . trim ( ) . replace ( ' ' , '-' ) ; final String msg = Messages . getString ( key , termLocale ) ; if ( rtlLocaleList . contains ( termLocale . toString ( ) ) ) { return termName + STRING_BLANK + msg ; } else { return msg + STRING_BLANK + termName ; } } } } | Get the full term with any prefix . |
25,486 | public void updateSubTerm ( ) { if ( subTerms . size ( ) == 1 ) { final IndexTerm term = subTerms . get ( 0 ) ; if ( term . getTermPrefix ( ) == IndexTermPrefix . SEE ) { term . setTermPrefix ( IndexTermPrefix . SEE_ALSO ) ; } } } | Update the sub - term prefix from See also to See if there is only one sub - term . |
25,487 | public void read ( final URI filename , final Document doc ) { currentFile = filename ; rootScope = null ; KeyScope keyScope = readScopes ( doc ) ; keyScope = cascadeChildKeys ( keyScope ) ; keyScope = inheritParentKeys ( keyScope ) ; rootScope = resolveIntermediate ( keyScope ) ; } | Read key definitions |
25,488 | private KeyScope readScopes ( final Document doc ) { final List < KeyScope > scopes = readScopes ( doc . getDocumentElement ( ) ) ; if ( scopes . size ( ) == 1 && scopes . get ( 0 ) . name == null ) { return scopes . get ( 0 ) ; } else { return new KeyScope ( "#root" , null , Collections . emptyMap ( ) , scopes ) ; } } | Read keys scopes in map . |
25,489 | private void readScope ( final Element scope , final Map < String , KeyDef > keyDefs ) { final List < Element > maps = new ArrayList < > ( ) ; maps . add ( scope ) ; for ( final Element child : getChildElements ( scope ) ) { collectMaps ( child , maps ) ; } for ( final Element map : maps ) { readMap ( map , keyDefs ) ; } } | Read key definitions from a key scope . |
25,490 | private void readMap ( final Element map , final Map < String , KeyDef > keyDefs ) { readKeyDefinition ( map , keyDefs ) ; for ( final Element elem : getChildElements ( map ) ) { if ( ! ( SUBMAP . matches ( elem ) || elem . getAttributeNode ( ATTRIBUTE_NAME_KEYSCOPE ) != null ) ) { readMap ( elem , keyDefs ) ; } } } | Recursively read key definitions from a single map fragment . |
25,491 | private KeyScope cascadeChildKeys ( final KeyScope rootScope ) { final Map < String , KeyDef > res = new HashMap < > ( rootScope . keyDefinition ) ; cascadeChildKeys ( rootScope , res , "" ) ; return new KeyScope ( rootScope . id , rootScope . name , res , new ArrayList < > ( rootScope . childScopes ) ) ; } | Cascade child keys with prefixes to parent key scopes . |
25,492 | private KeyScope resolveIntermediate ( final KeyScope scope ) { final Map < String , KeyDef > keys = new HashMap < > ( scope . keyDefinition ) ; for ( final Map . Entry < String , KeyDef > e : scope . keyDefinition . entrySet ( ) ) { final KeyDef res = resolveIntermediate ( scope , e . getValue ( ) , Collections . singletonList ( e . getValue ( ) ) ) ; keys . put ( e . getKey ( ) , res ) ; } final List < KeyScope > children = new ArrayList < > ( ) ; for ( final KeyScope child : scope . childScopes ) { final KeyScope resolvedChild = resolveIntermediate ( child ) ; children . add ( resolvedChild ) ; } return new KeyScope ( scope . id , scope . name , keys , children ) ; } | Resolve intermediate key references . |
25,493 | private DocumentFragment replaceContent ( final DocumentFragment pushcontent ) { final NodeList children = pushcontent . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { final Node child = children . item ( i ) ; switch ( child . getNodeType ( ) ) { case Node . ELEMENT_NODE : final Element e = ( Element ) child ; replaceLinkAttributes ( e ) ; final NodeList elements = e . getElementsByTagName ( "*" ) ; for ( int j = 0 ; i < elements . getLength ( ) ; i ++ ) { replaceLinkAttributes ( ( Element ) elements . item ( j ) ) ; } break ; } } return pushcontent ; } | Rewrite link attributes . |
25,494 | private boolean needPushTerm ( ) { if ( elementStack . empty ( ) ) { return false ; } if ( elementStack . peek ( ) instanceof TopicrefElement ) { final TopicrefElement elem = ( TopicrefElement ) elementStack . peek ( ) ; if ( indexMoved && ( elem . getFormat ( ) == null || elem . getFormat ( ) . equals ( ATTR_FORMAT_VALUE_DITA ) || elem . getFormat ( ) . equals ( ATTR_FORMAT_VALUE_DITAMAP ) ) ) { return false ; } } return true ; } | Check element stack for the root topicref or indexterm element . |
25,495 | public boolean matches ( final Node node ) { if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { return matches ( ( ( Element ) node ) . getAttribute ( ATTRIBUTE_NAME_CLASS ) ) ; } return false ; } | Test if given DITA class string matches this DITA class . |
25,496 | public AbstractPipelineOutput execute ( final AbstractPipelineInput input ) throws DITAOTException { if ( fileInfoFilter == null ) { fileInfoFilter = f -> f . format == null || f . format . equals ( ATTR_FORMAT_VALUE_DITA ) || f . format . equals ( ATTR_FORMAT_VALUE_DITAMAP ) ; } final Collection < FileInfo > fis = job . getFileInfo ( fileInfoFilter ) . stream ( ) . filter ( f -> f . hasKeyref ) . collect ( Collectors . toSet ( ) ) ; if ( ! fis . isEmpty ( ) ) { try { final String cls = Optional . ofNullable ( job . getProperty ( "temp-file-name-scheme" ) ) . orElse ( configuration . get ( "temp-file-name-scheme" ) ) ; tempFileNameScheme = ( GenMapAndTopicListModule . TempFileNameScheme ) Class . forName ( cls ) . newInstance ( ) ; } catch ( InstantiationException | IllegalAccessException | ClassNotFoundException e ) { throw new RuntimeException ( e ) ; } tempFileNameScheme . setBaseDir ( job . getInputDir ( ) ) ; initFilters ( ) ; final Document doc = readMap ( ) ; final KeyrefReader reader = new KeyrefReader ( ) ; reader . setLogger ( logger ) ; final Job . FileInfo in = job . getFileInfo ( fi -> fi . isInput ) . iterator ( ) . next ( ) ; final URI mapFile = in . uri ; logger . info ( "Reading " + job . tempDirURI . resolve ( mapFile ) . toString ( ) ) ; reader . read ( job . tempDirURI . resolve ( mapFile ) , doc ) ; final KeyScope rootScope = reader . getKeyDefinition ( ) ; final List < ResolveTask > jobs = collectProcessingTopics ( fis , rootScope , doc ) ; writeMap ( doc ) ; transtype = input . getAttribute ( ANT_INVOKER_EXT_PARAM_TRANSTYPE ) ; delayConrefUtils = transtype . equals ( INDEX_TYPE_ECLIPSEHELP ) ? new DelayConrefUtils ( ) : null ; for ( final ResolveTask r : jobs ) { if ( r . out != null ) { processFile ( r ) ; } } for ( final ResolveTask r : jobs ) { if ( r . out == null ) { processFile ( r ) ; } } for ( final URI file : normalProcessingRole ) { final FileInfo f = job . getFileInfo ( file ) ; if ( f != null ) { f . isResourceOnly = false ; job . add ( f ) ; } } try { job . write ( ) ; } catch ( final IOException e ) { throw new DITAOTException ( "Failed to store job state: " + e . getMessage ( ) , e ) ; } } return null ; } | Entry point of KeyrefModule . |
25,497 | private List < ResolveTask > collectProcessingTopics ( final Collection < FileInfo > fis , final KeyScope rootScope , final Document doc ) { final List < ResolveTask > res = new ArrayList < > ( ) ; final FileInfo input = job . getFileInfo ( fi -> fi . isInput ) . iterator ( ) . next ( ) ; res . add ( new ResolveTask ( rootScope , input , null ) ) ; walkMap ( doc . getDocumentElement ( ) , rootScope , res ) ; for ( final FileInfo f : fis ) { if ( ! usage . containsKey ( f . uri ) ) { res . add ( processTopic ( f , rootScope , f . isResourceOnly ) ) ; } } final List < ResolveTask > deduped = removeDuplicateResolveTargets ( res ) ; if ( fileInfoFilter != null ) { return adjustResourceRenames ( deduped . stream ( ) . filter ( rs -> fileInfoFilter . test ( rs . in ) ) . collect ( Collectors . toList ( ) ) ) ; } else { return adjustResourceRenames ( deduped ) ; } } | Collect topics for key reference processing and modify map to reflect new file names . |
25,498 | private List < ResolveTask > removeDuplicateResolveTargets ( List < ResolveTask > renames ) { return renames . stream ( ) . collect ( Collectors . groupingBy ( rt -> rt . scope , Collectors . toMap ( rt -> rt . in . uri , Function . identity ( ) , ( rt1 , rt2 ) -> rt1 ) ) ) . values ( ) . stream ( ) . flatMap ( m -> m . values ( ) . stream ( ) ) . collect ( Collectors . toList ( ) ) ; } | Remove duplicate sources within the same scope |
25,499 | List < ResolveTask > adjustResourceRenames ( final List < ResolveTask > renames ) { final Map < KeyScope , List < ResolveTask > > scopes = renames . stream ( ) . collect ( Collectors . groupingBy ( rt -> rt . scope ) ) ; final List < ResolveTask > res = new ArrayList < > ( ) ; for ( final Map . Entry < KeyScope , List < ResolveTask > > group : scopes . entrySet ( ) ) { final KeyScope scope = group . getKey ( ) ; final List < ResolveTask > tasks = group . getValue ( ) ; final Map < URI , URI > rewrites = tasks . stream ( ) . filter ( t -> t . out != null ) . collect ( toMap ( t -> t . in . uri , t -> t . out . uri ) ) ; final KeyScope resScope = rewriteScopeTargets ( scope , rewrites ) ; tasks . stream ( ) . map ( t -> new ResolveTask ( resScope , t . in , t . out ) ) . forEach ( res :: add ) ; } return res ; } | Adjust key targets per rewrites |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.