idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
9,800 | private boolean getQosImplicity ( final QOS qos ) { if ( this . getQos ( ) == QOS . ALL ) { return true ; } if ( qos == QOS . ALL ) { return false ; } else if ( this . getQos ( ) == QOS . ZERO_ONE ) { return ( qos == QOS . ZERO ) || ( qos == QOS . ONE ) || ( qos == QOS . ZERO_ONE ) ; } else if ( this . getQos ( ) == QOS . ONE_TWO ) { return ( qos == QOS . ONE ) || ( qos == QOS . TWO ) || ( qos == QOS . ONE_TWO ) ; } else if ( this . getQos ( ) == QOS . ZERO_TWO ) { return ( qos == QOS . ZERO ) || ( qos == QOS . TWO ) || ( qos == QOS . ZERO_TWO ) ; } return this . getQos ( ) == qos ; } | Checks if the MqttTopicPermission implies a given QoS |
9,801 | private boolean getActivityImplicity ( final ACTIVITY activity ) { if ( this . activity == ACTIVITY . ALL ) { return true ; } if ( ( activity == ACTIVITY . SUBSCRIBE ) && ( this . activity == ACTIVITY . PUBLISH ) ) { return false ; } else if ( ( activity == ACTIVITY . PUBLISH ) && ( this . activity == ACTIVITY . SUBSCRIBE ) ) { return false ; } else if ( activity == ACTIVITY . ALL && this . getActivity ( ) != ACTIVITY . ALL ) { return false ; } return true ; } | Checks if an activity implies another activity |
9,802 | protected void initializeMailTemplates ( ) { this . mailAddressTemplate = FaxClientSpiConfigurationConstants . MAIL_ADDRESS_TEMPLATE_VALUE . toString ( ) ; this . mailSubjectTemplate = FaxClientSpiConfigurationConstants . MAIL_SUBJECT_TEMPLATE_VALUE . toString ( ) ; } | This function initializes the mail templates . |
9,803 | protected Object [ ] setupSubmitFaxJobInput ( FaxJob faxJob ) { List < Object > inputList = new LinkedList < Object > ( ) ; inputList . add ( this . faxServerName ) ; File file = faxJob . getFile ( ) ; inputList . add ( file ) ; String documentName = faxJob . getProperty ( FaxJobExtendedPropertyConstants . DOCUMENT_NAME_FAX_JOB_PROPERTY_KEY . toString ( ) , null ) ; if ( ( documentName == null ) || ( documentName . length ( ) == 0 ) ) { documentName = file . getName ( ) ; } inputList . add ( documentName ) ; if ( this . useWin2kAPI ) { inputList . add ( faxJob . getTargetAddress ( ) ) ; inputList . add ( faxJob . getTargetName ( ) ) ; inputList . add ( faxJob . getSenderName ( ) ) ; inputList . add ( faxJob . getSenderFaxNumber ( ) ) ; } else { FaxJobPriority priority = faxJob . getPriority ( ) ; String valueStr = "fptNORMAL" ; if ( priority != null ) { switch ( priority ) { case LOW_PRIORITY : valueStr = "fptLOW" ; break ; case MEDIUM_PRIORITY : valueStr = "fptNORMAL" ; break ; case HIGH_PRIORITY : valueStr = "fptHIGH" ; break ; } } inputList . add ( valueStr ) ; inputList . add ( faxJob . getTargetAddress ( ) ) ; inputList . add ( faxJob . getTargetName ( ) ) ; inputList . add ( faxJob . getSenderName ( ) ) ; inputList . add ( faxJob . getSenderFaxNumber ( ) ) ; inputList . add ( faxJob . getSenderEmail ( ) ) ; } int size = inputList . size ( ) ; Object [ ] input = inputList . toArray ( new Object [ size ] ) ; return input ; } | This function creates an input array with the needed info to submit a new fax job based on the provided data . |
9,804 | protected Object formatObject ( Object object ) { Object formattedObject = object ; if ( object == null ) { formattedObject = "" ; } else if ( object instanceof String ) { String string = ( String ) object ; string = string . replaceAll ( "\n" , "" ) ; string = string . replaceAll ( "\r" , "" ) ; string = string . replaceAll ( "\t" , "" ) ; string = string . replaceAll ( "\f" , "" ) ; string = string . replaceAll ( "\b" , "" ) ; string = string . replaceAll ( "'" , "" ) ; string = string . replaceAll ( "\"" , "" ) ; formattedObject = string ; } else if ( object instanceof File ) { File file = ( File ) object ; String filePath = null ; try { filePath = file . getCanonicalPath ( ) ; } catch ( IOException exception ) { throw new FaxException ( "Unable to get file path." , exception ) ; } filePath = filePath . replaceAll ( "\\\\" , "\\\\\\\\" ) ; formattedObject = filePath ; } return formattedObject ; } | This function formats the provided object to enable embedding in VBS code . |
9,805 | protected FaxJobStatus invokeExistingFaxJobAction ( String scriptName , FaxJob faxJob , FaxActionType faxActionType ) { Object [ ] input = new String [ 2 ] ; input [ 0 ] = this . faxServerName ; input [ 1 ] = faxJob . getID ( ) ; return this . invokeScript ( faxJob , scriptName , input , faxActionType ) ; } | Invokes a basic fax action |
9,806 | protected FaxJobStatus invokeScript ( FaxJob faxJob , String name , Object [ ] input , FaxActionType faxActionType ) { String script = this . generateScript ( name , input ) ; ProcessOutput processOutput = this . invokeScript ( script ) ; this . processOutputValidator . validateProcessOutput ( this , processOutput , faxActionType ) ; FaxJobStatus output = null ; switch ( faxActionType ) { case SUBMIT_FAX_JOB : this . processOutputHandler . updateFaxJob ( this , faxJob , processOutput , faxActionType ) ; break ; case GET_FAX_JOB_STATUS : output = this . processOutputHandler . getFaxJobStatus ( this , processOutput ) ; break ; default : break ; } return output ; } | Invokes the VB script and returns its output . |
9,807 | protected ProcessOutput invokeScript ( String script ) { File file = null ; try { file = File . createTempFile ( "fax4j_" , ".vbs" ) ; } catch ( IOException exception ) { throw new FaxException ( "Unable to create temporary vbscript file." , exception ) ; } file . deleteOnExit ( ) ; StringBuilder buffer = new StringBuilder ( ) ; buffer . append ( this . getVBSExePath ( ) ) ; buffer . append ( " \"" ) ; buffer . append ( file . getAbsolutePath ( ) ) ; buffer . append ( "\"" ) ; String command = buffer . toString ( ) ; try { IOHelper . writeTextFile ( script , file ) ; } catch ( IOException exception ) { throw new FaxException ( "Unable to write vbscript to temporary file." , exception ) ; } Logger logger = this . getLogger ( ) ; logger . logDebug ( new Object [ ] { "Invoking command: " , command , " script:" , Logger . SYSTEM_EOL , script } , null ) ; ProcessOutput vbsOutput = ProcessExecutorHelper . executeProcess ( this , command ) ; int exitCode = vbsOutput . getExitCode ( ) ; boolean fileDeleted = file . delete ( ) ; logger . logDebug ( new Object [ ] { "Temp script file deleted: " , String . valueOf ( fileDeleted ) } , null ) ; if ( exitCode != 0 ) { throw new FaxException ( "Error while invoking script, exit code: " + exitCode + " script output:\n" + vbsOutput . getOutputText ( ) + "\nScript error:\n" + vbsOutput . getErrorText ( ) ) ; } return vbsOutput ; } | Invokes the VB script and returns the output . |
9,808 | protected String generateScript ( String name , Object [ ] input ) { String template = VBSFaxClientSpi . VBS_SCRIPTS . get ( name ) ; if ( ( template == null ) || ( template . length ( ) == 0 ) ) { this . throwUnsupportedException ( ) ; } String commonScript = VBSFaxClientSpi . VBS_SCRIPTS . get ( VBSFaxClientSpi . VBS_SCRIPT ) ; Object [ ] formattedInput = null ; if ( input != null ) { int size = input . length ; formattedInput = new Object [ size ] ; Object object = null ; for ( int index = 0 ; index < size ; index ++ ) { object = input [ index ] ; object = this . formatObject ( object ) ; formattedInput [ index ] = object ; } } String updatedScript = MessageFormat . format ( template , formattedInput ) ; StringBuilder buffer = new StringBuilder ( commonScript . length ( ) + updatedScript . length ( ) ) ; buffer . append ( commonScript ) ; buffer . append ( updatedScript ) ; String script = buffer . toString ( ) ; return script ; } | This function generates the script and returns it . |
9,809 | protected static final Logger initializeLogger ( ) { Logger logger = Logger . getLogger ( FaxClient . class . getName ( ) ) ; logger . setLevel ( Level . ALL ) ; logger . setFilter ( null ) ; logger . setUseParentHandlers ( true ) ; Formatter formatter = new SimpleFormatter ( ) ; Handler handler = new StreamHandler ( System . out , formatter ) ; handler . setLevel ( logger . getLevel ( ) ) ; handler . setFilter ( logger . getFilter ( ) ) ; logger . addHandler ( handler ) ; return logger ; } | This function initializes and returns the logger . |
9,810 | protected boolean validateCondition ( String key , String value ) { boolean valid = false ; FaxClientSpiConfigurationConstants condition = FaxClientSpiConfigurationConstants . getEnum ( key ) ; String propertyValue = null ; switch ( condition ) { case PROPERTY_CONDITION : propertyValue = this . getConfigurationValue ( value ) ; if ( propertyValue != null ) { valid = true ; } break ; case OS_CONDITION : String osName = System . getProperty ( "os.name" ) ; osName = osName . toLowerCase ( ) ; String updatedValue = value . toLowerCase ( ) ; if ( osName . contains ( updatedValue ) ) { valid = true ; } break ; case JAVA_CLASS_CONDITION : try { ReflectionHelper . getType ( value ) ; valid = true ; } catch ( Throwable throwable ) { } break ; case NATIVE_LIB_CONDITION : try { System . loadLibrary ( value ) ; valid = true ; } catch ( Throwable throwable ) { } break ; case EXECUTABLE_CONDITION : String systemPath = System . getProperty ( "java.library.path" ) ; String [ ] systemPathElements = systemPath . split ( System . getProperty ( "path.separator" ) ) ; int amount = systemPathElements . length ; String directoryPath = null ; File file = null ; for ( int index = 0 ; index < amount ; index ++ ) { directoryPath = systemPathElements [ index ] ; file = new File ( directoryPath , value ) ; if ( ( file . exists ( ) ) && ( file . isFile ( ) ) ) { valid = true ; } } break ; case STABLE_CONDITION : String propertyKey = FaxClientSpiConfigurationConstants . SPI_STABLE_PROPERTY_KEY_PREFIX + value + FaxClientSpiConfigurationConstants . SPI_STABLE_PROPERTY_KEY_SUFFIX ; propertyValue = this . getConfigurationValue ( propertyKey ) ; valid = Boolean . parseBoolean ( propertyValue ) ; break ; default : throw new FaxException ( "Invalid condition key provided: " + key ) ; } return valid ; } | Validates the SPI condition . |
9,811 | protected void createFaxClientSpi ( String type ) { Properties configuration = this . createFaxClientSpiConfiguration ( ) ; this . faxClientSpi = FaxClientSpiFactory . createChildFaxClientSpi ( type , configuration ) ; } | This function creates a new fax client SPI based on the provided configuration . |
9,812 | protected Properties createFaxClientSpiConfiguration ( ) { Map < String , String > configuration = this . getConfiguration ( ) ; Properties internalSPIConfiguration = new Properties ( ) ; Properties overrideConfiguration = new Properties ( ) ; Iterator < Entry < String , String > > iterator = configuration . entrySet ( ) . iterator ( ) ; Entry < String , String > entry = null ; String key = null ; String value = null ; String overrideKey = null ; String overridePrefix = FaxClientSpiConfigurationConstants . SPI_CONFIGURATION_OVERRIDE_PROPERTY_KEY_PREFIX . toString ( ) ; int prefixLength = overridePrefix . length ( ) ; while ( iterator . hasNext ( ) ) { entry = iterator . next ( ) ; key = entry . getKey ( ) ; value = entry . getValue ( ) ; if ( ( key . startsWith ( overridePrefix ) ) ) { if ( key . length ( ) != prefixLength ) { overrideKey = key . substring ( prefixLength ) ; overrideConfiguration . setProperty ( overrideKey , value ) ; } } internalSPIConfiguration . setProperty ( key , value ) ; } internalSPIConfiguration . putAll ( overrideConfiguration ) ; return internalSPIConfiguration ; } | This function creates and returns the internal fax client SPI configuration . |
9,813 | public List < String > getSupportedCipherSuites ( ) throws SslException { try { final SSLEngine engine = getDefaultSslEngine ( ) ; return ImmutableList . copyOf ( engine . getSupportedCipherSuites ( ) ) ; } catch ( NoSuchAlgorithmException | KeyManagementException e ) { throw new SslException ( "Not able to get list of supported cipher suites from JVM" , e ) ; } } | Returns a list of all supported Cipher Suites of the JVM . |
9,814 | protected Transport createTransport ( Session session ) { Transport transport = null ; try { transport = session . getTransport ( this . transportProtocol ) ; if ( this . transportPort > 0 ) { transport . connect ( this . transportHost , this . transportPort , this . userName , this . password ) ; } else { transport . connect ( this . transportHost , this . userName , this . password ) ; } } catch ( Exception exception ) { throw new FaxException ( "Error while connecting to mail host: " + this . transportHost , exception ) ; } return transport ; } | This function returns a transport for the provided session . |
9,815 | private static File getFax4jInternalTemporaryDirectoryImpl ( ) { File temporaryFile = null ; try { temporaryFile = File . createTempFile ( "temp_" , ".temp" ) ; } catch ( IOException exception ) { throw new FaxException ( "Unable to create temporary file." , exception ) ; } File temporaryDirectory = temporaryFile . getParentFile ( ) ; boolean deleted = temporaryFile . delete ( ) ; if ( ! deleted ) { temporaryFile . deleteOnExit ( ) ; } Properties properties = LibraryConfigurationLoader . readInternalConfiguration ( ) ; String name = properties . getProperty ( "org.fax4j.product.name" ) ; String version = properties . getProperty ( "org.fax4j.product.version" ) ; File fax4jTemporaryDirectory = new File ( temporaryDirectory , name + "_" + version ) ; if ( ! fax4jTemporaryDirectory . exists ( ) ) { boolean created = fax4jTemporaryDirectory . mkdirs ( ) ; if ( ! created ) { throw new FaxException ( "Unable to create fax4j internal temporary directory: " + fax4jTemporaryDirectory ) ; } } return fax4jTemporaryDirectory ; } | This function returns the fax4j library internal temporary directory . |
9,816 | private static String getEncodingToUse ( String encoding ) { String updatedEncoding = encoding ; if ( updatedEncoding == null ) { updatedEncoding = IOHelper . getDefaultEncoding ( ) ; } return updatedEncoding ; } | This function returns the encoding to use . If provided encoding is null the default system encoding is returend . |
9,817 | public static byte [ ] convertStringToBinary ( String text , String encoding ) { byte [ ] data = null ; if ( text != null ) { if ( text . length ( ) == 0 ) { data = new byte [ 0 ] ; } else { LoggerManager loggerManager = LoggerManager . getInstance ( ) ; Logger logger = loggerManager . getLogger ( ) ; String encodingToUse = encoding ; if ( ( encodingToUse != null ) && ( encodingToUse . length ( ) > 0 ) ) { try { data = text . getBytes ( encodingToUse ) ; } catch ( UnsupportedEncodingException exception ) { logger . logError ( new Object [ ] { "Unable to convert text to binary using encoding: " , encodingToUse , " using default system encoding." } , exception ) ; } } if ( data == null ) { encodingToUse = IOHelper . getDefaultEncoding ( ) ; try { data = text . getBytes ( encodingToUse ) ; } catch ( UnsupportedEncodingException exception ) { logger . logError ( new Object [ ] { "Unable to convert text to binary using default encoding: " , encodingToUse } , exception ) ; throw new FaxException ( "Unable to convert text to binary using encoding: " + encodingToUse , exception ) ; } } } } return data ; } | This function converts the provided string to binary data . |
9,818 | public static Reader createReader ( InputStream inputStream , String encoding ) { String updatedEncoding = IOHelper . getEncodingToUse ( encoding ) ; Reader reader = null ; try { reader = new InputStreamReader ( inputStream , updatedEncoding ) ; } catch ( UnsupportedEncodingException exception ) { throw new FaxException ( "Unable to create reader, unsupported encoding: " + encoding , exception ) ; } return reader ; } | This function creates and returns a new reader for the provided input stream . |
9,819 | public static Writer createWriter ( OutputStream outputStream , String encoding ) { String updatedEncoding = IOHelper . getEncodingToUse ( encoding ) ; Writer writer = null ; try { writer = new OutputStreamWriter ( outputStream , updatedEncoding ) ; } catch ( UnsupportedEncodingException exception ) { throw new FaxException ( "Unable to create writer, unsupported encoding: " + encoding , exception ) ; } return writer ; } | This function creates and returns a new writer for the provided output stream . |
9,820 | public static String readTextStream ( Reader reader ) throws IOException { char [ ] buffer = new char [ 5000 ] ; Writer stringWriter = new StringWriter ( ) ; int read = - 1 ; try { do { read = reader . read ( buffer ) ; if ( read != - 1 ) { stringWriter . write ( buffer , 0 , read ) ; } } while ( read != - 1 ) ; } finally { IOHelper . closeResource ( reader ) ; } String text = stringWriter . toString ( ) ; return text ; } | Reads the text from the stream . |
9,821 | public static String readTextFile ( File file ) throws IOException { InputStream inputStream = new FileInputStream ( file ) ; Reader reader = IOHelper . createReader ( inputStream , null ) ; String text = IOHelper . readTextStream ( reader ) ; return text ; } | Reads the text from the file . |
9,822 | public static void writeTextFile ( String text , File file ) throws IOException { Writer writer = null ; try { OutputStream outputStream = new FileOutputStream ( file ) ; writer = IOHelper . createWriter ( outputStream , null ) ; writer . write ( text ) ; } finally { IOHelper . closeResource ( writer ) ; } } | Writes the text to the file . |
9,823 | public static void readAndWriteStreams ( InputStream inputStream , OutputStream outputStream ) throws IOException { byte [ ] buffer = new byte [ 5000 ] ; int read = - 1 ; try { do { read = inputStream . read ( buffer ) ; if ( read != - 1 ) { outputStream . write ( buffer , 0 , read ) ; } } while ( read != - 1 ) ; } finally { IOHelper . closeResource ( inputStream ) ; IOHelper . closeResource ( outputStream ) ; } } | Reads the data from the input stream and writes to the output stream . |
9,824 | public static byte [ ] readStream ( InputStream inputStream ) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( 5000 ) ; IOHelper . readAndWriteStreams ( inputStream , outputStream ) ; byte [ ] data = outputStream . toByteArray ( ) ; return data ; } | Reads the data from the stream . |
9,825 | public static byte [ ] readFile ( File file ) throws IOException { InputStream inputStream = new FileInputStream ( file ) ; byte [ ] data = IOHelper . readStream ( inputStream ) ; return data ; } | Reads the data from the file . |
9,826 | public static void writeFile ( byte [ ] content , File file ) throws IOException { OutputStream outputStream = null ; try { outputStream = new FileOutputStream ( file ) ; outputStream . write ( content ) ; } finally { IOHelper . closeResource ( outputStream ) ; } } | Writes the content to the file . |
9,827 | public static File getFileFromPathList ( String fileNameWithNoPath , String [ ] pathList ) { File foundFile = null ; if ( pathList != null ) { int amount = pathList . length ; String directoryPath = null ; File file = null ; for ( int index = 0 ; index < amount ; index ++ ) { directoryPath = pathList [ index ] ; file = new File ( directoryPath , fileNameWithNoPath ) ; if ( ( file . exists ( ) ) && ( file . isFile ( ) ) ) { foundFile = file ; break ; } } } return foundFile ; } | This function returns the file object of the first location in which the requested file is found . |
9,828 | public static File getFileFromNativePath ( String fileNameWithNoPath ) { String systemPath = System . getProperty ( "java.library.path" ) ; String pathSeperator = System . getProperty ( "path.separator" ) ; String [ ] systemPathElements = systemPath . split ( pathSeperator ) ; File file = IOHelper . getFileFromPathList ( fileNameWithNoPath , systemPathElements ) ; return file ; } | This function returns the file object of the first location in which the requested file is found . The path list used is the current native path of the process . |
9,829 | public FaxJob submitFaxJob ( T inputData ) { if ( inputData == null ) { throw new FaxException ( "Input data not provided." ) ; } FaxJob faxJob = this . createFaxJob ( ) ; this . requestParser . updateFaxJobFromInputData ( inputData , faxJob ) ; FileInfo fileInfo = this . requestParser . getFileInfoFromInputData ( inputData ) ; if ( fileInfo == null ) { throw new FaxException ( "Unable to extract file info from input data." ) ; } this . submitFaxJob ( faxJob , fileInfo ) ; return faxJob ; } | This function will submit a new fax job . |
9,830 | protected String getTargetAddress ( Message mailMessage ) throws MessagingException { String subject = mailMessage . getSubject ( ) ; String targetAddress = null ; if ( ( subject != null ) && ( subject . startsWith ( "fax:" ) ) && ( subject . length ( ) > 4 ) ) { targetAddress = subject . substring ( 4 ) ; } return targetAddress ; } | Returns the target address from the provided mail object . |
9,831 | protected String getSenderEmail ( Message mailMessage ) throws MessagingException { Address [ ] addresses = mailMessage . getFrom ( ) ; String senderEmail = null ; if ( ( addresses != null ) && ( addresses . length > 0 ) ) { Address address = addresses [ 0 ] ; senderEmail = address . toString ( ) ; } return senderEmail ; } | Returns the sender email from the provided mail object . |
9,832 | protected Map < String , String > initializeAdditionalParameters ( ) { Map < String , String > configuration = this . getConfiguration ( ) ; String propertyPart = this . getPropertyPart ( ) ; String prefix = FaxJob2HTTPRequestConverterConfigurationConstants . ADDITIONAL_PARAMETER_PROPERTY_KEY_PREFIX . toString ( ) ; prefix = MessageFormat . format ( prefix , propertyPart ) ; Map < String , String > additionalParametersMap = new HashMap < String , String > ( ) ; Iterator < Entry < String , String > > iterator = configuration . entrySet ( ) . iterator ( ) ; Entry < String , String > entry = null ; String key = null ; String value = null ; while ( iterator . hasNext ( ) ) { entry = iterator . next ( ) ; key = entry . getKey ( ) ; if ( key != null ) { key = MessageFormat . format ( key , propertyPart ) ; key = key . trim ( ) ; if ( key . length ( ) > 0 ) { if ( key . startsWith ( prefix ) ) { value = entry . getValue ( ) ; if ( value != null ) { value = value . trim ( ) ; if ( value . length ( ) > 0 ) { key = key . substring ( prefix . length ( ) ) ; additionalParametersMap . put ( key , value ) ; } } } } } } return additionalParametersMap ; } | This function builds and returns the additional parameters map . |
9,833 | protected HTTPRequest createCommonHTTPRequest ( HTTPFaxClientSpi faxClientSpi , FaxActionType faxActionType ) { HTTPRequest httpRequest = new HTTPRequest ( ) ; String resource = faxClientSpi . getHTTPResource ( faxActionType ) ; httpRequest . setResource ( resource ) ; String urlParameters = faxClientSpi . getHTTPURLParameters ( ) ; httpRequest . setParametersText ( urlParameters ) ; return httpRequest ; } | Creates a HTTP request with the common data . |
9,834 | protected final void addContentPart ( List < ContentPart < ? > > contentList , String key , String value ) { if ( ( key != null ) && ( value != null ) && ( value . length ( ) > 0 ) ) { if ( this . shouldAddContentPart ( key ) ) { contentList . add ( new ContentPart < String > ( key , value , ContentPartType . STRING ) ) ; } } } | This function adds a string content part |
9,835 | protected final void addAdditionalParameters ( List < ContentPart < ? > > contentList ) { if ( this . additionalParameters != null ) { Iterator < Entry < String , String > > iterator = this . additionalParameters . entrySet ( ) . iterator ( ) ; Entry < String , String > entry = null ; String key = null ; String value = null ; while ( iterator . hasNext ( ) ) { entry = iterator . next ( ) ; key = entry . getKey ( ) ; value = entry . getValue ( ) ; if ( ( key != null ) && ( value != null ) ) { this . addContentPart ( contentList , key , value ) ; } } } } | This function adds the additional parameters . |
9,836 | protected void addAdditionalContentParts ( HTTPFaxClientSpi faxClientSpi , FaxActionType faxActionType , FaxJob faxJob , List < ContentPart < ? > > contentList ) { } | This function enables extending classes to add additional content parts . |
9,837 | public FileInfo getFileInfoFromInputData ( T inputData ) { if ( ! this . initialized ) { throw new FaxException ( "Fax bridge not initialized." ) ; } FileInfo fileInfo = this . getFileInfoFromInputDataImpl ( inputData ) ; return fileInfo ; } | This function returns the file info from the input data . |
9,838 | protected FaxJobStatus getFaxJobStatusFromWindowsFaxJobStatusString ( String faxJobStatusStr ) { FaxJobStatus faxJobStatus = FaxJobStatus . UNKNOWN ; if ( ( faxJobStatusStr != null ) && ( faxJobStatusStr . length ( ) > 0 ) ) { if ( ( faxJobStatusStr . equalsIgnoreCase ( "Pending" ) ) || ( faxJobStatusStr . equalsIgnoreCase ( "Paused" ) ) || ( faxJobStatusStr . equalsIgnoreCase ( "Retrying" ) ) ) { faxJobStatus = FaxJobStatus . PENDING ; } else if ( faxJobStatusStr . equalsIgnoreCase ( "In Progress" ) ) { faxJobStatus = FaxJobStatus . IN_PROGRESS ; } else if ( ( faxJobStatusStr . equalsIgnoreCase ( "Failed" ) ) || ( faxJobStatusStr . equalsIgnoreCase ( "No Line" ) ) || ( faxJobStatusStr . equalsIgnoreCase ( "Retries Exceeded" ) ) ) { faxJobStatus = FaxJobStatus . ERROR ; } } return faxJobStatus ; } | This function returns the fax job status based on the windows fax job status string value . |
9,839 | protected void updateFaxJob ( FaxJob faxJob , HTTPResponse httpResponse , FaxActionType faxActionType ) { this . httpResponseHandler . updateFaxJob ( faxJob , httpResponse , faxActionType ) ; } | Updates the fax job based on the data from the HTTP response . |
9,840 | public final synchronized void initialize ( String type , Properties configuration , Object flowOwner ) { if ( this . initialized ) { throw new FaxException ( "Fax bridge already initialized." ) ; } this . initialized = true ; Map < String , String > map = new HashMap < String , String > ( ) ; SpiUtil . copyPropertiesToMap ( configuration , map ) ; this . bridgeConfiguration = new ConfigurationHolderImpl ( map ) ; this . faxClient = FaxClientFactory . createFaxClient ( type , configuration ) ; LoggerManager loggerManager = LoggerManager . getInstance ( ) ; this . bridgeLogger = loggerManager . getLogger ( ) ; this . vendorPolicy = this . createVendorPolicy ( ) ; if ( this . vendorPolicy == null ) { throw new FaxException ( "Unable to create vendor policy" ) ; } this . vendorPolicy . initialize ( flowOwner ) ; if ( this . vendorPolicy instanceof FaxMonitorEventListener ) { this . faxClient . addFaxMonitorEventListener ( ( FaxMonitorEventListener ) this . vendorPolicy ) ; } this . bridgeLogger . logDebug ( new Object [ ] { "Initializing fax bridge of type: " , this . getClass ( ) . getName ( ) , "\nProvider Information:\n" , this . getProvider ( ) , "\nFax Bridge Configuration:\n" , configuration , "\nVendor Policy Type: " , this . vendorPolicy . getClass ( ) . getName ( ) } , null ) ; this . initializeImpl ( ) ; } | This function initializes the fax bridge . |
9,841 | public static void copyPropertiesToMap ( Properties source , Map < String , String > target ) { if ( source != null ) { Iterator < Entry < Object , Object > > iterator = source . entrySet ( ) . iterator ( ) ; Entry < Object , Object > entry = null ; String key = null ; String value = null ; while ( iterator . hasNext ( ) ) { entry = iterator . next ( ) ; key = ( String ) entry . getKey ( ) ; value = ( String ) entry . getValue ( ) ; target . put ( key , value ) ; } } } | This function copies all mappings from source properties to target map . |
9,842 | public static String replaceTemplateParameter ( String template , String parameter , String value , TemplateParameterEncoder encoder ) { String text = template ; if ( ( text != null ) && ( parameter != null ) ) { String updatedValue = value ; if ( updatedValue == null ) { updatedValue = SpiUtil . EMPTY_STRING ; } else if ( encoder != null ) { updatedValue = encoder . encodeTemplateParameter ( updatedValue ) ; } text = text . replace ( parameter , updatedValue ) ; } return text ; } | This function replaces the parameter with the provided value . |
9,843 | public static String urlEncode ( String text ) { String urlEncodedString = text ; if ( text != null ) { try { urlEncodedString = URLEncoder . encode ( text , SpiUtil . UTF_8_ENCODING_NAME ) ; } catch ( UnsupportedEncodingException exception ) { throw new FaxException ( "Error while URL encoding text." , exception ) ; } } return urlEncodedString ; } | This function URL encodes the given text . |
9,844 | public static String urlDecode ( String text ) { String urlEncodedString = text ; if ( text != null ) { try { urlEncodedString = URLDecoder . decode ( text , SpiUtil . UTF_8_ENCODING_NAME ) ; } catch ( UnsupportedEncodingException exception ) { throw new FaxException ( "Error while URL decoding text." , exception ) ; } } return urlEncodedString ; } | This function URL decodes the given text . |
9,845 | private static String getFileParameterValue ( FaxJob faxJob ) { String value = null ; File file = faxJob . getFile ( ) ; if ( file != null ) { try { value = IOHelper . readTextFile ( faxJob . getFile ( ) ) ; } catch ( IOException exception ) { throw new FaxException ( "Error while reading file." , exception ) ; } } return value ; } | This function returns the file parameter value based on the file content . |
9,846 | protected void initializeImpl ( ) { this . data = new HashMap < FaxClientSpi , Map < FaxJob , FaxJobStatus > > ( 20 ) ; String value = this . getConfigurationValue ( FaxJobMonitorImpl . POLLING_INTERVAL_IN_MILLIES_PROPERTY_KEY ) ; this . pollingInterval = 5000 ; if ( value != null ) { this . pollingInterval = Long . parseLong ( value ) ; if ( this . pollingInterval <= 0 ) { throw new FaxException ( "Polling interval set to an invalid value: " + this . pollingInterval ) ; } } value = this . getConfigurationValue ( FaxJobMonitorImpl . FIXED_POLLING_INTERVAL_PROPERTY_KEY ) ; this . fixedPollingInterval = Boolean . parseBoolean ( value ) ; value = this . getConfigurationValue ( FaxJobMonitorImpl . POLLING_THREAD_PRIORITY_PROPERTY_KEY ) ; this . pollingThreadPriority = 2 ; if ( value != null ) { this . pollingThreadPriority = Integer . parseInt ( value ) ; if ( ( this . pollingThreadPriority < Thread . MIN_PRIORITY ) || ( this . pollingThreadPriority > Thread . MAX_PRIORITY ) ) { throw new FaxException ( "Polling thread priority set to an invalid value: " + this . pollingThreadPriority ) ; } } this . pollerTask = new PollerTask ( this ) ; } | This function initializes the fax job monitor . |
9,847 | protected void runPollingCycle ( ) { synchronized ( this . LOCK ) { Set < Entry < FaxClientSpi , Map < FaxJob , FaxJobStatus > > > entrySet = this . data . entrySet ( ) ; Iterator < Entry < FaxClientSpi , Map < FaxJob , FaxJobStatus > > > faxClientSpiIterator = entrySet . iterator ( ) ; Entry < FaxClientSpi , Map < FaxJob , FaxJobStatus > > faxClientSpiEntry = null ; FaxClientSpi faxClientSpi = null ; Map < FaxJob , FaxJobStatus > faxJobMap = null ; Iterator < Entry < FaxJob , FaxJobStatus > > faxJobIterator = null ; Entry < FaxJob , FaxJobStatus > faxJobEntry = null ; FaxJob [ ] faxJobs = null ; FaxJobStatus [ ] previousFaxJobStatuses = null ; FaxJobStatus [ ] currentFaxJobStatuses = null ; FaxJob faxJob = null ; FaxJobStatus previousFaxJobStatus = null ; FaxJobStatus currentFaxJobStatus = null ; int counter = 0 ; while ( faxClientSpiIterator . hasNext ( ) ) { faxClientSpiEntry = faxClientSpiIterator . next ( ) ; faxClientSpi = faxClientSpiEntry . getKey ( ) ; faxJobMap = faxClientSpiEntry . getValue ( ) ; faxJobIterator = faxJobMap . entrySet ( ) . iterator ( ) ; int amount = faxJobMap . size ( ) ; if ( amount > 0 ) { faxJobs = new FaxJob [ amount ] ; previousFaxJobStatuses = new FaxJobStatus [ amount ] ; counter = 0 ; while ( faxJobIterator . hasNext ( ) ) { faxJobEntry = faxJobIterator . next ( ) ; faxJob = faxJobEntry . getKey ( ) ; previousFaxJobStatus = faxJobEntry . getValue ( ) ; faxJobs [ counter ] = faxJob ; previousFaxJobStatuses [ counter ] = previousFaxJobStatus ; counter ++ ; } currentFaxJobStatuses = faxClientSpi . pollForFaxJobStatues ( faxJobs ) ; if ( ( currentFaxJobStatuses != null ) && ( currentFaxJobStatuses . length == amount ) ) { for ( int index = 0 ; index < amount ; index ++ ) { currentFaxJobStatus = currentFaxJobStatuses [ index ] ; if ( currentFaxJobStatus != null ) { faxJob = faxJobs [ index ] ; previousFaxJobStatus = previousFaxJobStatuses [ index ] ; if ( ! previousFaxJobStatus . equals ( currentFaxJobStatus ) ) { faxJobMap . put ( faxJob , currentFaxJobStatus ) ; faxClientSpi . fireFaxMonitorEvent ( FaxMonitorEventID . FAX_JOB_STATUS_CHANGE , faxJob , currentFaxJobStatus ) ; } switch ( currentFaxJobStatus ) { case UNKNOWN : case ERROR : faxJobMap . remove ( faxJob ) ; break ; case IN_PROGRESS : case PENDING : default : break ; } } } } } if ( faxJobMap . isEmpty ( ) ) { faxClientSpiIterator . remove ( ) ; } } } this . checkAndStopMonitor ( ) ; } | Runs the polling cycle to fetch and create monitor events . |
9,848 | protected final String getConfigurationValue ( String key ) { String value = this . monitorConfiguration . get ( key ) ; if ( value != null ) { value = value . trim ( ) ; if ( value . length ( ) == 0 ) { value = null ; } } this . monitorLogger . logDebug ( new Object [ ] { "Extracted configuration for key: " , key , " value: " , value } , null ) ; return value ; } | Returns the value from the monitor configuration based on the provided configuration key . |
9,849 | public static void loadNativeLibrary ( Logger logger ) { synchronized ( WindowsFaxClientSpiHelper . NATIVE_LOCK ) { if ( ! WindowsFaxClientSpiHelper . nativeLibraryLoaded ) { try { File directory = IOHelper . getFax4jInternalTemporaryDirectory ( ) ; File dllFile = new File ( directory , "fax4j.dll" ) ; String path = dllFile . getPath ( ) ; System . load ( path ) ; logger . logDebug ( new Object [ ] { "Loaded native library runtime path." } , null ) ; WindowsFaxClientSpiHelper . nativeLibraryLoaded = true ; } catch ( Throwable throwable ) { logger . logError ( new Object [ ] { "Error while loading native library from runtime path." } , throwable ) ; } if ( ! WindowsFaxClientSpiHelper . nativeLibraryLoaded ) { try { System . loadLibrary ( "fax4j" ) ; logger . logDebug ( new Object [ ] { "Loaded native library from native path." } , null ) ; WindowsFaxClientSpiHelper . nativeLibraryLoaded = true ; } catch ( Throwable throwable ) { logger . logError ( new Object [ ] { "Error while loading native library from native path." } , throwable ) ; } } } } } | Loads the native library if not loaded before . |
9,850 | public static String getServerNameFromConfiguration ( FaxClientSpi faxClientSpi ) { Logger logger = faxClientSpi . getLogger ( ) ; String faxServerName = faxClientSpi . getConfigurationValue ( FaxClientSpiConfigurationConstants . FAX_SERVER_NAME_PROPERTY_KEY ) ; logger . logDebug ( new Object [ ] { "Fax server name: " , faxServerName } , null ) ; return faxServerName ; } | This function returns the server name from the SPI configuration . |
9,851 | public static String getOutputPart ( ProcessOutput processOutput , String prefix ) { String output = processOutput . getOutputText ( ) ; if ( output != null ) { boolean validOutput = false ; int index = output . indexOf ( prefix ) ; if ( index != - 1 ) { index = index + prefix . length ( ) ; if ( output . length ( ) > index ) { output = output . substring ( index ) ; output = output . trim ( ) ; index = output . indexOf ( "\n" ) ; if ( index != - 1 ) { output = output . substring ( 0 , index ) ; output = output . trim ( ) ; } if ( output . length ( ) > 0 ) { validOutput = true ; } } } if ( ! validOutput ) { output = null ; } } return output ; } | This function returns the relevant part from the process output . |
9,852 | public InputStream getInputStream ( ) { InputStream stream = null ; try { stream = this . commPort . getInputStream ( ) ; } catch ( IOException exception ) { throw new FaxException ( "Unable to extract input stream." , exception ) ; } return stream ; } | This function returns the input stream to the COMM port . |
9,853 | public OutputStream getOutputStream ( ) { OutputStream stream = null ; try { stream = this . commPort . getOutputStream ( ) ; } catch ( IOException exception ) { throw new FaxException ( "Unable to extract output stream." , exception ) ; } return stream ; } | This function returns the output stream to the COMM port . |
9,854 | private static Logger getLogger ( ) { if ( FaxClientSpiFactory . logger == null ) { synchronized ( FaxClientSpiFactory . class ) { if ( FaxClientSpiFactory . logger == null ) { LoggerManager loggerManager = LoggerManager . getInstance ( ) ; Logger localLogger = loggerManager . getLogger ( ) ; localLogger . logDebug ( new Object [ ] { ProductInfo . getProductInfoPrintout ( ) } , null ) ; FaxClientSpiFactory . logger = localLogger ; } } } return FaxClientSpiFactory . logger ; } | This function returns the internal logger for the fax4j framework . |
9,855 | private static FaxJobMonitor getFaxJobMonitor ( ) { Map < String , String > systemConfig = LibraryConfigurationLoader . getSystemConfiguration ( ) ; if ( FaxClientSpiFactory . faxJobMonitor == null ) { synchronized ( FaxClientSpiFactory . class ) { if ( FaxClientSpiFactory . faxJobMonitor == null ) { FaxJobMonitor localFaxJobMonitor = FaxClientSpiFactory . createFaxJobMonitor ( systemConfig ) ; Logger localLogger = FaxClientSpiFactory . getLogger ( ) ; localFaxJobMonitor . initialize ( systemConfig , localLogger ) ; FaxClientSpiFactory . faxJobMonitor = localFaxJobMonitor ; } } } return FaxClientSpiFactory . faxJobMonitor ; } | This function returns the fax job monitor . |
9,856 | private static FaxJobMonitor createFaxJobMonitor ( Map < String , String > systemConfig ) { String className = systemConfig . get ( FaxClientSpiFactory . FAX_JOB_MONITOR_CLASS_NAME_PROPERTY_KEY ) ; if ( ( className == null ) || ( className . length ( ) == 0 ) ) { className = FaxJobMonitorImpl . class . getName ( ) ; } FaxJobMonitor faxJobMonitorInstance = ( FaxJobMonitor ) ReflectionHelper . createInstance ( className ) ; return faxJobMonitorInstance ; } | This function creates the fax job monitor used by the fax4j framework . |
9,857 | private static FaxClientSpiProxy createFaxClientSpiProxy ( FaxClientSpi faxClientSpi ) { FaxClientSpiInterceptor [ ] interceptors = FaxClientSpiFactory . createFaxClientSpiInterceptors ( faxClientSpi ) ; String className = faxClientSpi . getConfigurationValue ( FaxClientSpiFactory . SPI_PROXY_CLASS_NAME_PROPERTY_KEY ) ; if ( className == null ) { className = FaxClientSpiProxyImpl . class . getName ( ) ; } FaxClientSpiProxy faxClientSpiProxy = ( FaxClientSpiProxy ) ReflectionHelper . createInstance ( className ) ; faxClientSpiProxy . initialize ( faxClientSpi , interceptors ) ; return faxClientSpiProxy ; } | This function creates the fax client SPI proxy . |
9,858 | private static FaxClientSpiInterceptor [ ] createFaxClientSpiInterceptors ( FaxClientSpi faxClientSpi ) { String typeListStr = faxClientSpi . getConfigurationValue ( FaxClientSpiFactory . SPI_INTERCEPTOR_LIST_PROPERTY_KEY ) ; FaxClientSpiInterceptor [ ] interceptors = null ; if ( typeListStr != null ) { String [ ] types = typeListStr . split ( FaxClientSpiFactory . SPI_INTERCEPTOR_LIST_SEPARATOR ) ; int amount = types . length ; String type = null ; String propertyKey = null ; String className = null ; FaxClientSpiInterceptor interceptor = null ; List < FaxClientSpiInterceptor > interceptorList = new LinkedList < FaxClientSpiInterceptor > ( ) ; for ( int index = 0 ; index < amount ; index ++ ) { type = types [ index ] ; if ( ( type != null ) && ( type . length ( ) > 0 ) ) { propertyKey = FaxClientSpiFactory . SPI_INTERCEPTOR_TYPE_PROPERTY_KEY_PREFIX + type ; className = faxClientSpi . getConfigurationValue ( propertyKey ) ; if ( className == null ) { throw new FaxException ( "Class name not defined by property: " + propertyKey + " for SPI interceptor." ) ; } interceptor = ( FaxClientSpiInterceptor ) ReflectionHelper . createInstance ( className ) ; interceptor . initialize ( faxClientSpi ) ; interceptorList . add ( interceptor ) ; } interceptors = interceptorList . toArray ( new FaxClientSpiInterceptor [ interceptorList . size ( ) ] ) ; } } return interceptors ; } | This function creates the fax client SPI interceptors . |
9,859 | protected void preNativeCall ( ) { Logger logger = this . getLogger ( ) ; LogLevel logLevel = logger . getLogLevel ( ) ; boolean debugMode = false ; if ( logLevel . equals ( LogLevel . DEBUG ) ) { debugMode = true ; } WindowsJNIFaxClientSpi . setDebugModeNative ( debugMode ) ; } | This function is invoked before any native call to set the native layer debug mode . |
9,860 | private String winGetFaxJobStatus ( String serverName , int faxJobID ) { String status = null ; synchronized ( WindowsFaxClientSpiHelper . NATIVE_LOCK ) { this . preNativeCall ( ) ; status = WindowsJNIFaxClientSpi . getFaxJobStatusNative ( serverName , faxJobID ) ; } return status ; } | This function returns the fax job status . |
9,861 | protected String getContentPartAsString ( Map < String , ContentPart < ? > > contentPartsMap , String parameter ) { String stringValue = null ; ContentPart < ? > contentPart = contentPartsMap . get ( parameter ) ; if ( contentPart != null ) { ContentPartType contentPartType = contentPart . getType ( ) ; Object content = contentPart . getContent ( ) ; if ( content != null ) { switch ( contentPartType ) { case STRING : stringValue = ( String ) content ; break ; case BINARY : byte [ ] data = ( byte [ ] ) content ; String encoding = IOHelper . getDefaultEncoding ( ) ; try { stringValue = new String ( data , encoding ) ; } catch ( UnsupportedEncodingException exception ) { throw new FaxException ( "Unable to convert binary data to string for parameter: " + parameter , exception ) ; } break ; default : throw new FaxException ( "Unsupported content part type: " + contentPartType ) ; } } } return stringValue ; } | This function returns the content part string value . |
9,862 | protected Map < String , ContentPart < ? > > getContentPartsAsMap ( HTTPRequest httpRequest ) { Map < String , ContentPart < ? > > contentPartsMap = null ; ContentType contentType = httpRequest . getContentType ( ) ; switch ( contentType ) { case MULTI_PART : contentPartsMap = new HashMap < String , HTTPRequest . ContentPart < ? > > ( ) ; ContentPart < ? > [ ] contentParts = httpRequest . getContentAsParts ( ) ; int amount = contentParts . length ; ContentPart < ? > contentPart = null ; String partName = null ; for ( int index = 0 ; index < amount ; index ++ ) { contentPart = contentParts [ index ] ; partName = contentPart . getName ( ) ; contentPartsMap . put ( partName , contentPart ) ; } break ; default : throw new FaxException ( "Unsupported content type: " + contentType ) ; } return contentPartsMap ; } | This function returns the HTTP request multi parts as map . |
9,863 | public static String getProductInfoPrintout ( ) { Properties properties = LibraryConfigurationLoader . readInternalConfiguration ( ) ; String name = properties . getProperty ( "org.fax4j.product.name" ) ; String version = properties . getProperty ( "org.fax4j.product.version" ) ; StringBuilder buffer = new StringBuilder ( ) ; buffer . append ( name ) ; buffer . append ( " library." ) ; buffer . append ( Logger . SYSTEM_EOL ) ; buffer . append ( "Version: " ) ; buffer . append ( version ) ; String text = buffer . toString ( ) ; return text ; } | Returns the product info printout . |
9,864 | protected List < String > parseCommand ( ConfigurationHolder configurationHolder , String command ) { List < String > commandList = new LinkedList < String > ( ) ; StringBuilder buffer = new StringBuilder ( command ) ; String part = null ; int quoteIndex = - 1 ; int spaceIndex = - 1 ; int length = - 1 ; do { quoteIndex = buffer . indexOf ( "\"" ) ; spaceIndex = buffer . indexOf ( " " ) ; if ( quoteIndex == - 1 ) { if ( spaceIndex == - 1 ) { buffer = this . addAllBuffer ( commandList , buffer ) ; } else { buffer = this . addPart ( commandList , buffer , spaceIndex , true ) ; } } else if ( spaceIndex == - 1 ) { if ( quoteIndex == - 1 ) { buffer = this . addAllBuffer ( commandList , buffer ) ; } else if ( quoteIndex == 0 ) { quoteIndex = buffer . indexOf ( "\"" , 1 ) ; if ( quoteIndex == - 1 ) { throw new FaxException ( "Unable to parse command: " + command ) ; } buffer = this . addPart ( commandList , buffer , quoteIndex , false ) ; } else { throw new FaxException ( "Unable to parse command: " + command ) ; } } else if ( quoteIndex < spaceIndex ) { if ( quoteIndex == 0 ) { quoteIndex = buffer . indexOf ( "\"" , 1 ) ; if ( quoteIndex == - 1 ) { throw new FaxException ( "Unable to parse command: " + command ) ; } buffer = this . addPart ( commandList , buffer , quoteIndex , false ) ; } else { buffer = this . addPart ( commandList , buffer , spaceIndex , true ) ; } } else { buffer = this . addPart ( commandList , buffer , spaceIndex , true ) ; } length = buffer . length ( ) ; if ( length > 0 ) { part = buffer . toString ( ) ; part = part . trim ( ) ; buffer . delete ( 0 , length ) ; buffer . append ( part ) ; length = buffer . length ( ) ; } } while ( length > 0 ) ; return commandList ; } | This function parsers the command and converts to a command array . |
9,865 | public void initialize ( FaxClientSpi faxClientSpi ) { if ( this . initialized ) { throw new FaxException ( "Fax Modem Adapter already initialized." ) ; } this . initialized = true ; Logger logger = faxClientSpi . getLogger ( ) ; logger . logDebug ( new Object [ ] { "Initializing fax modem adapter of type: " , this . getClass ( ) . getName ( ) , "\nProvider Information:\n" , this . getProvider ( ) } , null ) ; this . initializeImpl ( faxClientSpi ) ; } | This function initializes the fax modem adapter . |
9,866 | protected final MailConnectionFactory createMailConnectionFactoryImpl ( String className ) { String factoryClassName = className ; if ( factoryClassName == null ) { factoryClassName = MailConnectionFactoryImpl . class . getName ( ) ; } MailConnectionFactory factory = ( MailConnectionFactory ) ReflectionHelper . createInstance ( factoryClassName ) ; factory . initialize ( this ) ; return factory ; } | Creates and returns the mail connection factory . |
9,867 | protected Connection < MailResourcesHolder > createMailConnection ( ) { Connection < MailResourcesHolder > mailConnection = this . connectionFactory . createConnection ( ) ; Logger logger = this . getLogger ( ) ; logger . logInfo ( new Object [ ] { "Created mail connection." } , null ) ; return mailConnection ; } | Creates and returns the mail connection to be used to send the fax via mail . |
9,868 | protected void closeMailConnection ( Connection < MailResourcesHolder > mailConnection ) throws IOException { if ( mailConnection != null ) { Logger logger = this . getLogger ( ) ; logger . logInfo ( new Object [ ] { "Closing mail connection." } , null ) ; mailConnection . close ( ) ; } } | This function closes the provided mail connection . |
9,869 | protected Connection < MailResourcesHolder > getMailConnection ( ) { Connection < MailResourcesHolder > mailConnection = null ; if ( this . usePersistentConnection ) { synchronized ( this ) { if ( this . connection == null ) { this . connection = this . createMailConnection ( ) ; } } mailConnection = this . connection ; } else { mailConnection = this . createMailConnection ( ) ; } return mailConnection ; } | Returns the mail connection to be used to send the fax via mail . |
9,870 | protected void sendMail ( FaxJob faxJob , Connection < MailResourcesHolder > mailConnection , Message message ) { if ( message == null ) { this . throwUnsupportedException ( ) ; } else { MailResourcesHolder mailResourcesHolder = mailConnection . getResource ( ) ; Transport transport = mailResourcesHolder . getTransport ( ) ; try { message . saveChanges ( ) ; if ( transport == null ) { Transport . send ( message , message . getAllRecipients ( ) ) ; } else { transport . sendMessage ( message , message . getAllRecipients ( ) ) ; } } catch ( Throwable throwable ) { throw new FaxException ( "Unable to send message." , throwable ) ; } finally { if ( ! this . usePersistentConnection ) { try { this . closeMailConnection ( mailConnection ) ; } catch ( Exception exception ) { Logger logger = this . getLogger ( ) ; logger . logInfo ( new Object [ ] { "Error while releasing mail connection." } , exception ) ; } } } } } | This function will send the mail message . |
9,871 | protected void updateFaxJobWithFileInfo ( FaxJob faxJob , FileInfo fileInfo ) { File file = fileInfo . getFile ( ) ; if ( file == null ) { String fileName = fileInfo . getName ( ) ; byte [ ] content = fileInfo . getContent ( ) ; try { file = File . createTempFile ( "fax_" , fileName ) ; IOHelper . writeFile ( content , file ) ; } catch ( IOException exception ) { throw new FaxException ( "Unable to write file content to temporary file." , exception ) ; } } faxJob . setFile ( file ) ; } | This function stores the file in the local machine and updates the fax job with the new file data . |
9,872 | protected Map < String , String > convertParametersTextToMap ( HTTPRequest request ) { Map < String , String > map = new HashMap < String , String > ( ) ; String parametersText = request . getParametersText ( ) ; if ( parametersText != null ) { String [ ] keyValuePairs = parametersText . split ( "&" ) ; int pairsAmount = keyValuePairs . length ; String keyValuePair = null ; String [ ] parts = null ; String key = null ; String value = null ; for ( int index = 0 ; index < pairsAmount ; index ++ ) { keyValuePair = keyValuePairs [ index ] ; parts = keyValuePair . split ( "=" ) ; if ( parts . length == 2 ) { key = parts [ 0 ] ; if ( key . length ( ) > 0 ) { key = SpiUtil . urlDecode ( key ) ; value = parts [ 1 ] . trim ( ) ; value = SpiUtil . urlDecode ( value ) ; map . put ( key , value ) ; } } } } return map ; } | This function converts the provided query string to a map object . |
9,873 | protected String createSubmitFaxCommand ( FaxJob faxJob ) { StringBuilder buffer = new StringBuilder ( ) ; buffer . append ( this . submitCommand ) ; buffer . append ( " " ) ; buffer . append ( this . printQueueParameter ) ; buffer . append ( " " ) ; buffer . append ( this . printQueueName ) ; buffer . append ( " " ) ; buffer . append ( this . generalParameters ) ; buffer . append ( " " ) ; buffer . append ( this . phoneParameter ) ; buffer . append ( "=" ) ; buffer . append ( faxJob . getTargetAddress ( ) ) ; String targetName = faxJob . getTargetName ( ) ; if ( ( targetName != null ) && ( targetName . length ( ) > 0 ) ) { buffer . append ( " " ) ; buffer . append ( this . faxToParameter ) ; buffer . append ( "=\"" ) ; targetName = SpiUtil . urlEncode ( targetName ) ; buffer . append ( targetName ) ; buffer . append ( "\"" ) ; } buffer . append ( " \"" ) ; buffer . append ( faxJob . getFilePath ( ) ) ; buffer . append ( "\"" ) ; String command = buffer . toString ( ) ; return command ; } | Creates and returns the submit fax command . |
9,874 | protected ProcessOutput executeProcess ( String command , FaxActionType faxActionType ) { ProcessOutput processOutput = ProcessExecutorHelper . executeProcess ( this , command ) ; this . processOutputValidator . validateProcessOutput ( this , processOutput , faxActionType ) ; return processOutput ; } | This function executes the external command to send the fax . |
9,875 | protected String formatLogMessage ( LogLevel level , Object [ ] message , Throwable throwable ) { String messageText = this . format ( message ) ; String throwableText = this . format ( throwable ) ; StringBuilder buffer = new StringBuilder ( ) ; buffer . append ( "[fax4j][" ) ; buffer . append ( level . getName ( ) ) ; buffer . append ( "] " ) ; if ( messageText != null ) { buffer . append ( messageText ) ; if ( throwableText != null ) { buffer . append ( Logger . SYSTEM_EOL ) ; buffer . append ( throwableText ) ; } } else if ( throwableText != null ) { buffer . append ( throwableText ) ; } String text = buffer . toString ( ) ; return text ; } | Converts the provided data to string . |
9,876 | protected String format ( Object [ ] message ) { String text = null ; if ( message != null ) { StringBuilder buffer = new StringBuilder ( ) ; int amount = message . length ; Object object = null ; for ( int index = 0 ; index < amount ; index ++ ) { object = message [ index ] ; buffer . append ( object ) ; } text = buffer . toString ( ) ; } return text ; } | Converts the provided message object array to string . |
9,877 | protected String format ( Throwable throwable ) { String text = null ; if ( throwable != null ) { StringWriter writer = new StringWriter ( 1500 ) ; throwable . printStackTrace ( new PrintWriter ( writer ) ) ; text = writer . toString ( ) ; } return text ; } | Converts the provided throwable to string . |
9,878 | public final void setLogLevel ( LogLevel logLevel ) { LogLevel updatedLogLevel = logLevel ; if ( updatedLogLevel == null ) { updatedLogLevel = LogLevel . NONE ; } this . logLevel = updatedLogLevel ; } | Sets the minimum log level . |
9,879 | public void logDebug ( Object [ ] message , Throwable throwable ) { this . log ( LogLevel . DEBUG , message , throwable ) ; } | Logs the provided data at the debug level . |
9,880 | public void logInfo ( Object [ ] message , Throwable throwable ) { this . log ( LogLevel . INFO , message , throwable ) ; } | Logs the provided data at the info level . |
9,881 | public void logError ( Object [ ] message , Throwable throwable ) { this . log ( LogLevel . ERROR , message , throwable ) ; } | Logs the provided data at the error level . |
9,882 | public final void fireFaxMonitorEvent ( FaxMonitorEventID id , FaxJob faxJob , FaxJobStatus faxJobStatus ) { this . fireFaxEvent ( id , faxJob , faxJobStatus ) ; } | This function fires a new fax monitor event . |
9,883 | protected void invokeFaxJobIDValidation ( FaxJob faxJob ) { this . invokeFaxJobNullValidation ( faxJob ) ; String faxJobID = faxJob . getID ( ) ; if ( ( faxJobID == null ) || ( faxJobID . length ( ) == 0 ) ) { throw new FaxException ( "Fax job ID not provided." ) ; } } | This function invokes the fax job null validation . |
9,884 | public final void setHeaderProperties ( Properties headerProperties ) { this . headerProperties = null ; if ( headerProperties != null ) { this . headerProperties = new Properties ( ) ; this . headerProperties . putAll ( headerProperties ) ; } } | This function sets the header properties . |
9,885 | public HTTPClientConfiguration createHTTPClientConfiguration ( ConfigurationHolder configurationHolder ) { String hostName = configurationHolder . getConfigurationValue ( HTTPClientConfigurationConstants . HOST_NAME_PROPERTY_KEY ) ; if ( hostName == null ) { throw new FaxException ( "Host name not defined in property: " + HTTPClientConfigurationConstants . HOST_NAME_PROPERTY_KEY ) ; } String value = configurationHolder . getConfigurationValue ( HTTPClientConfigurationConstants . PORT_PROPERTY_KEY ) ; if ( value == null ) { value = String . valueOf ( - 1 ) ; } int port = Integer . parseInt ( value ) ; boolean ssl = Boolean . parseBoolean ( configurationHolder . getConfigurationValue ( HTTPClientConfigurationConstants . SSL_PROPERTY_KEY ) ) ; CommonHTTPClientConfiguration configuration = new CommonHTTPClientConfiguration ( ) ; configuration . setHostName ( hostName ) ; configuration . setPort ( port ) ; configuration . setSSL ( ssl ) ; Enum < ? > [ ] methodProperties = new Enum < ? > [ ] { HTTPClientConfigurationConstants . SUBMIT_HTTP_METHOD_PROPERTY_KEY , HTTPClientConfigurationConstants . SUSPEND_HTTP_METHOD_PROPERTY_KEY , HTTPClientConfigurationConstants . RESUME_HTTP_METHOD_PROPERTY_KEY , HTTPClientConfigurationConstants . CANCEL_HTTP_METHOD_PROPERTY_KEY , HTTPClientConfigurationConstants . GET_STATUS_HTTP_METHOD_PROPERTY_KEY } ; FaxActionType [ ] faxActionTypes = new FaxActionType [ ] { FaxActionType . SUBMIT_FAX_JOB , FaxActionType . SUSPEND_FAX_JOB , FaxActionType . RESUME_FAX_JOB , FaxActionType . CANCEL_FAX_JOB , FaxActionType . GET_FAX_JOB_STATUS } ; HTTPMethod httpMethod = null ; for ( int index = 0 ; index < methodProperties . length ; index ++ ) { value = configurationHolder . getConfigurationValue ( methodProperties [ index ] ) ; httpMethod = HTTPMethod . POST ; if ( value != null ) { httpMethod = HTTPMethod . valueOf ( value ) ; } configuration . setMethod ( faxActionTypes [ index ] , httpMethod ) ; } return configuration ; } | This function creates the HTTP client configuration to be used later on by this HTTP client type . |
9,886 | public static File findAbsoluteAndRelative ( final String fileLocation ) { final File file = new File ( fileLocation ) ; if ( file . isAbsolute ( ) ) { return file ; } else { return new File ( getHiveMQHomeFolder ( ) , fileLocation ) ; } } | Tries to find a file in the given absolute path or relative to the HiveMQ home folder |
9,887 | protected HttpMethodBase createMethod ( String url , HTTPMethod httpMethod ) { if ( httpMethod == null ) { throw new FaxException ( "HTTP method not provided." ) ; } if ( ( url == null ) || ( url . length ( ) == 0 ) ) { throw new FaxException ( "HTTP URL not provided." ) ; } HttpMethodBase httpMethodClient = null ; switch ( httpMethod ) { case POST : httpMethodClient = new PostMethod ( url ) ; break ; case GET : httpMethodClient = new GetMethod ( url ) ; break ; case PUT : httpMethodClient = new PutMethod ( url ) ; break ; } return httpMethodClient ; } | This function creates and returns a new HTTP method . |
9,888 | protected HTTPResponse createHTTPResponse ( int statusCode , String responseContent ) { HTTPResponse httpResponse = new HTTPResponse ( ) ; httpResponse . setStatusCode ( statusCode ) ; httpResponse . setContent ( responseContent ) ; return httpResponse ; } | This function creates and returns the HTTP response object . |
9,889 | protected void appendParameters ( StringBuilder buffer , String parameters ) { if ( ( parameters != null ) && ( parameters . length ( ) > 0 ) ) { String updatedParameters = parameters ; if ( parameters . startsWith ( "?" ) ) { updatedParameters = parameters . substring ( 1 ) ; } if ( updatedParameters . length ( ) > 0 ) { int currentLength = buffer . length ( ) ; if ( ( currentLength > 0 ) && ( buffer . charAt ( currentLength - 1 ) == '/' ) ) { int length = currentLength ; buffer . delete ( length - 1 , length ) ; } buffer . append ( "?" ) ; try { String [ ] parameterPairs = updatedParameters . split ( "&" ) ; int amount = parameterPairs . length ; String parameterPair = null ; String [ ] values = null ; boolean addedParameters = false ; for ( int index = 0 ; index < amount ; index ++ ) { parameterPair = parameterPairs [ index ] ; values = parameterPair . split ( "=" ) ; if ( values . length == 2 ) { if ( addedParameters ) { buffer . append ( "&" ) ; } buffer . append ( URLEncoder . encode ( values [ 0 ] , "UTF-8" ) ) ; buffer . append ( "=" ) ; buffer . append ( URLEncoder . encode ( values [ 1 ] , "UTF-8" ) ) ; addedParameters = true ; } } } catch ( Exception exception ) { throw new FaxException ( "Unable to encode parameters." , exception ) ; } } } } | This function appends the parameters text to the base URL . |
9,890 | protected String createURL ( HTTPRequest httpRequest , HTTPClientConfiguration configuration ) { StringBuilder buffer = new StringBuilder ( 100 ) ; String resource = httpRequest . getResource ( ) ; this . appendBaseURL ( buffer , resource , configuration ) ; String parameters = httpRequest . getParametersText ( ) ; this . appendParameters ( buffer , parameters ) ; String url = buffer . toString ( ) ; return url ; } | This function creates the full URL from the provided values . |
9,891 | protected void setupHTTPRequestHeaderProperties ( HTTPRequest httpRequest , HttpMethodBase httpMethodClient ) { Properties headerProperties = httpRequest . getHeaderProperties ( ) ; if ( headerProperties != null ) { Iterator < Entry < Object , Object > > iterator = headerProperties . entrySet ( ) . iterator ( ) ; Entry < Object , Object > entry = null ; while ( iterator . hasNext ( ) ) { entry = iterator . next ( ) ; httpMethodClient . addRequestHeader ( ( String ) entry . getKey ( ) , ( String ) entry . getValue ( ) ) ; } } } | This function sets the header properties in the HTTP method . |
9,892 | protected RequestEntity createStringRequestContent ( HTTPRequest httpRequest ) { RequestEntity requestEntity = null ; String contentString = httpRequest . getContentAsString ( ) ; if ( contentString != null ) { try { requestEntity = new StringRequestEntity ( contentString , "text/plain" , null ) ; } catch ( UnsupportedEncodingException exception ) { throw new FaxException ( "Unable to set string request entity." , exception ) ; } } return requestEntity ; } | This function creates a string type request entity and populates it with the data from the provided HTTP request . |
9,893 | protected RequestEntity createBinaryRequestContent ( HTTPRequest httpRequest ) { RequestEntity requestEntity = null ; byte [ ] contentBinary = httpRequest . getContentAsBinary ( ) ; if ( contentBinary != null ) { requestEntity = new ByteArrayRequestEntity ( contentBinary , "binary/octet-stream" ) ; } return requestEntity ; } | This function creates a binary type request entity and populates it with the data from the provided HTTP request . |
9,894 | protected RequestEntity createMultiPartRequestContent ( HTTPRequest httpRequest , HttpMethodBase httpMethodClient ) { RequestEntity requestEntity = null ; ContentPart < ? > [ ] contentParts = httpRequest . getContentAsParts ( ) ; if ( contentParts != null ) { int partsAmount = contentParts . length ; if ( partsAmount > 0 ) { Part [ ] parts = new Part [ partsAmount ] ; ContentPart < ? > contentPart = null ; String name = null ; Object content = null ; ContentPartType contentPartType = null ; for ( int index = 0 ; index < partsAmount ; index ++ ) { contentPart = contentParts [ index ] ; if ( contentPart != null ) { name = contentPart . getName ( ) ; content = contentPart . getContent ( ) ; contentPartType = contentPart . getType ( ) ; switch ( contentPartType ) { case FILE : File file = ( File ) content ; try { parts [ index ] = new FilePart ( name , file ) ; } catch ( FileNotFoundException exception ) { throw new FaxException ( "Fax file: " + file . getAbsolutePath ( ) + " not found." , exception ) ; } break ; case STRING : parts [ index ] = new StringPart ( name , ( String ) content ) ; break ; default : throw new FaxException ( "Unsupported content type provided: " + contentPartType ) ; } } } requestEntity = new MultipartRequestEntity ( parts , httpMethodClient . getParams ( ) ) ; } } return requestEntity ; } | This function creates a multi part type request entity and populates it with the data from the provided HTTP request . |
9,895 | protected void setRequestContent ( HTTPRequest httpRequest , HttpMethodBase httpMethodClient ) { if ( httpMethodClient instanceof EntityEnclosingMethod ) { EntityEnclosingMethod pushMethod = ( EntityEnclosingMethod ) httpMethodClient ; RequestEntity requestEntity = null ; ContentType contentType = httpRequest . getContentType ( ) ; switch ( contentType ) { case STRING : requestEntity = this . createStringRequestContent ( httpRequest ) ; break ; case BINARY : requestEntity = this . createBinaryRequestContent ( httpRequest ) ; break ; case MULTI_PART : requestEntity = this . createMultiPartRequestContent ( httpRequest , httpMethodClient ) ; break ; default : throw new FaxException ( "Unsupported content type: " + contentType ) ; } if ( requestEntity != null ) { pushMethod . setRequestEntity ( requestEntity ) ; pushMethod . setContentChunked ( false ) ; } } } | This function sets the request content . |
9,896 | public void releaseConnection ( Connection < T > connection ) { if ( connection != null ) { try { this . LOGGER . logInfo ( new Object [ ] { "Closing connection using factory type: " , this . getClass ( ) . getName ( ) } , null ) ; T resource = connection . getResource ( ) ; this . releaseResource ( resource ) ; CloseableResourceManager . unregisterCloseable ( connection ) ; this . LOGGER . logInfo ( new Object [ ] { "Connection closed." } , null ) ; } catch ( Exception exception ) { this . LOGGER . logInfo ( new Object [ ] { "Unable to close connection." } , exception ) ; } } } | Releases the connection . |
9,897 | protected final HylaFAXClientConnectionFactory createHylaFAXClientConnectionFactory ( String className ) { HylaFAXClientConnectionFactory factory = ( HylaFAXClientConnectionFactory ) ReflectionHelper . createInstance ( className ) ; factory . initialize ( this ) ; return factory ; } | Creates and returns the hylafax client connection factory . |
9,898 | protected synchronized HylaFAXClient getHylaFAXClient ( ) { HylaFAXClient client = null ; if ( this . connection == null ) { this . connection = this . connectionFactory . createConnection ( ) ; } client = this . connection . getResource ( ) ; return client ; } | Returns an instance of the hyla fax client . |
9,899 | public static ClassLoader getThreadContextClassLoader ( ) { Thread thread = Thread . currentThread ( ) ; ClassLoader classLoader = thread . getContextClassLoader ( ) ; return classLoader ; } | This function returns the thread context class loader . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.