idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
23,100 | private void indent ( ) throws IOException { if ( mIndent ) { for ( int i = 0 ; i < mStack . size ( ) * mIndentSpaces ; i ++ ) { mOut . write ( " " . getBytes ( ) ) ; } } } | Indentation of output . | 59 | 6 |
23,101 | private void write ( final long mValue ) throws IOException { final int length = ( int ) Math . log10 ( ( double ) mValue ) ; int digit = 0 ; long remainder = mValue ; for ( int i = length ; i >= 0 ; i -- ) { digit = ( byte ) ( remainder / LONG_POWERS [ i ] ) ; mOut . write ( ( byte ) ( digit + ASCII_OFFSET ) ) ; remainder -= digit * LONG_POWERS [ i ] ; } } | Write non - negative non - zero long as UTF - 8 bytes . | 109 | 14 |
23,102 | public static String isoDate ( final Date val ) { synchronized ( isoDateFormat ) { try { isoDateFormat . setTimeZone ( Timezones . getDefaultTz ( ) ) ; } catch ( TimezonesException tze ) { throw new RuntimeException ( tze ) ; } return isoDateFormat . format ( val ) ; } } | Turn Date into yyyyMMdd | 73 | 8 |
23,103 | public static String rfcDate ( final Date val ) { synchronized ( rfcDateFormat ) { try { rfcDateFormat . setTimeZone ( Timezones . getDefaultTz ( ) ) ; } catch ( TimezonesException tze ) { throw new RuntimeException ( tze ) ; } return rfcDateFormat . format ( val ) ; } } | Turn Date into yyyy - MM - dd | 77 | 10 |
23,104 | public static String isoDateTime ( final Date val ) { synchronized ( isoDateTimeFormat ) { try { isoDateTimeFormat . setTimeZone ( Timezones . getDefaultTz ( ) ) ; } catch ( TimezonesException tze ) { throw new RuntimeException ( tze ) ; } return isoDateTimeFormat . format ( val ) ; } } | Turn Date into yyyyMMddTHHmmss | 77 | 11 |
23,105 | public static String isoDateTime ( final Date val , final TimeZone tz ) { synchronized ( isoDateTimeTZFormat ) { isoDateTimeTZFormat . setTimeZone ( tz ) ; return isoDateTimeTZFormat . format ( val ) ; } } | Turn Date into yyyyMMddTHHmmss for a given timezone | 58 | 16 |
23,106 | public static Date fromISODate ( final String val ) throws BadDateException { try { synchronized ( isoDateFormat ) { try { isoDateFormat . setTimeZone ( Timezones . getDefaultTz ( ) ) ; } catch ( TimezonesException tze ) { throw new RuntimeException ( tze ) ; } return isoDateFormat . parse ( val ) ; } } catch ( Throwable t ) { throw new BadDateException ( ) ; } } | Get Date from yyyyMMdd | 98 | 8 |
23,107 | public static Date fromRfcDate ( final String val ) throws BadDateException { try { synchronized ( rfcDateFormat ) { try { rfcDateFormat . setTimeZone ( Timezones . getDefaultTz ( ) ) ; } catch ( TimezonesException tze ) { throw new RuntimeException ( tze ) ; } return rfcDateFormat . parse ( val ) ; } } catch ( Throwable t ) { throw new BadDateException ( ) ; } } | Get Date from yyyy - MM - dd | 101 | 10 |
23,108 | public static Date fromISODateTime ( final String val ) throws BadDateException { try { synchronized ( isoDateTimeFormat ) { try { isoDateTimeFormat . setTimeZone ( Timezones . getDefaultTz ( ) ) ; } catch ( TimezonesException tze ) { throw new RuntimeException ( tze ) ; } return isoDateTimeFormat . parse ( val ) ; } } catch ( Throwable t ) { throw new BadDateException ( ) ; } } | Get Date from yyyyMMddThhmmss | 102 | 12 |
23,109 | public static Date fromISODateTime ( final String val , final TimeZone tz ) throws BadDateException { try { synchronized ( isoDateTimeTZFormat ) { isoDateTimeTZFormat . setTimeZone ( tz ) ; return isoDateTimeTZFormat . parse ( val ) ; } } catch ( Throwable t ) { throw new BadDateException ( ) ; } } | Get Date from yyyyMMddThhmmss with timezone | 83 | 15 |
23,110 | @ SuppressWarnings ( "unused" ) public static Date fromISODateTimeUTC ( final String val , final TimeZone tz ) throws BadDateException { try { synchronized ( isoDateTimeUTCTZFormat ) { isoDateTimeUTCTZFormat . setTimeZone ( tz ) ; return isoDateTimeUTCTZFormat . parse ( val ) ; } } catch ( Throwable t ) { throw new BadDateException ( ) ; } } | Get Date from yyyyMMddThhmmssZ with timezone | 99 | 16 |
23,111 | public static Date fromISODateTimeUTC ( final String val ) throws BadDateException { try { synchronized ( isoDateTimeUTCFormat ) { return isoDateTimeUTCFormat . parse ( val ) ; } } catch ( Throwable t ) { throw new BadDateException ( ) ; } } | Get Date from yyyyMMddThhmmssZ | 61 | 13 |
23,112 | public static String fromISODateTimeUTCtoRfc822 ( final String val ) throws BadDateException { try { synchronized ( isoDateTimeUTCFormat ) { return rfc822Date ( isoDateTimeUTCFormat . parse ( val ) ) ; } } catch ( Throwable t ) { throw new BadDateException ( ) ; } } | Get RFC822 form from yyyyMMddThhmmssZ | 73 | 16 |
23,113 | public static boolean isISODate ( final String val ) throws BadDateException { try { if ( val . length ( ) != 8 ) { return false ; } fromISODate ( val ) ; return true ; } catch ( Throwable t ) { return false ; } } | Check Date is yyyyMMdd | 58 | 8 |
23,114 | public static boolean isISODateTimeUTC ( final String val ) throws BadDateException { try { if ( val . length ( ) != 16 ) { return false ; } fromISODateTimeUTC ( val ) ; return true ; } catch ( Throwable t ) { return false ; } } | Check Date is yyyyMMddThhmmddZ | 62 | 13 |
23,115 | public static boolean isISODateTime ( final String val ) throws BadDateException { try { if ( val . length ( ) != 15 ) { return false ; } fromISODateTime ( val ) ; return true ; } catch ( Throwable t ) { return false ; } } | Check Date is yyyyMMddThhmmdd | 60 | 12 |
23,116 | public static Date fromDate ( final String dt ) throws BadDateException { try { if ( dt == null ) { return null ; } if ( dt . indexOf ( "T" ) > 0 ) { return fromDateTime ( dt ) ; } if ( ! dt . contains ( "-" ) ) { return fromISODate ( dt ) ; } return fromRfcDate ( dt ) ; } catch ( Throwable t ) { throw new BadDateException ( ) ; } } | Return rfc or iso String date or datetime as java Date | 108 | 13 |
23,117 | public static Date fromDateTime ( final String dt ) throws BadDateException { try { if ( dt == null ) { return null ; } if ( ! dt . contains ( "-" ) ) { return fromISODateTimeUTC ( dt ) ; } return fromRfcDateTimeUTC ( dt ) ; } catch ( Throwable t ) { throw new BadDateException ( ) ; } } | Return rfc or iso String datetime as java Date | 87 | 11 |
23,118 | public AbstractModule createModule ( ) { return new AbstractModule ( ) { @ Override protected void configure ( ) { bind ( IDataFactory . class ) . to ( mDataFacClass ) ; bind ( IMetaEntryFactory . class ) . to ( mMetaFacClass ) ; bind ( IRevisioning . class ) . to ( mRevisioningClass ) ; bind ( IByteHandlerPipeline . class ) . toInstance ( mByteHandler ) ; install ( new FactoryModuleBuilder ( ) . implement ( IBackend . class , mBackend ) . build ( IBackendFactory . class ) ) ; install ( new FactoryModuleBuilder ( ) . build ( IResourceConfigurationFactory . class ) ) ; bind ( Key . class ) . toInstance ( mKey ) ; install ( new FactoryModuleBuilder ( ) . build ( ISessionConfigurationFactory . class ) ) ; } } ; } | Creating an Guice Module based on the parameters set . | 189 | 11 |
23,119 | public void setProperty ( final String name , final String val ) { if ( props == null ) { props = new Properties ( ) ; } props . setProperty ( name , val ) ; } | Allows applications to provide parameters to methods using this object class | 40 | 11 |
23,120 | public void startEmit ( final Writer wtr , final String dtd ) throws IOException { this . wtr = wtr ; this . dtd = dtd ; } | Emit any headers dtd and namespace declarations | 37 | 9 |
23,121 | public void openTag ( final QName tag , final String attrName , final String attrVal ) throws IOException { blanks ( ) ; openTagSameLine ( tag , attrName , attrVal ) ; newline ( ) ; indent += 2 ; } | open with attribute | 57 | 3 |
23,122 | public void openTagSameLine ( final QName tag , final String attrName , final String attrVal ) throws IOException { lb ( ) ; emitQName ( tag ) ; attribute ( attrName , attrVal ) ; endOpeningTag ( ) ; } | Emit an opening tag ready for nested values . No new line | 57 | 13 |
23,123 | private void value ( final String val , final String quoteChar ) throws IOException { if ( val == null ) { return ; } String q = quoteChar ; if ( q == null ) { q = "" ; } if ( ( val . indexOf ( ' ' ) >= 0 ) || ( val . indexOf ( ' ' ) >= 0 ) ) { out ( "<![CDATA[" ) ; out ( q ) ; out ( val ) ; out ( q ) ; out ( "]]>" ) ; } else { out ( q ) ; out ( val ) ; out ( q ) ; } } | Write out a value | 126 | 4 |
23,124 | public OptionElement parseOptions ( final InputStream is ) throws OptionsException { Reader rdr = null ; try { rdr = new InputStreamReader ( is ) ; DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; factory . setNamespaceAware ( false ) ; DocumentBuilder builder = factory . newDocumentBuilder ( ) ; Document doc = builder . parse ( new InputSource ( rdr ) ) ; /* We expect a root element named as specified */ Element root = doc . getDocumentElement ( ) ; if ( ! root . getNodeName ( ) . equals ( outerTag . getLocalPart ( ) ) ) { throw new OptionsException ( "org.bedework.bad.options" ) ; } OptionElement oel = new OptionElement ( ) ; oel . name = "root" ; doChildren ( oel , root , new Stack < Object > ( ) ) ; return oel ; } catch ( OptionsException ce ) { throw ce ; } catch ( Throwable t ) { throw new OptionsException ( t ) ; } finally { if ( rdr != null ) { try { rdr . close ( ) ; } catch ( Throwable t ) { } } } } | Parse the input stream and return the internal representation . | 250 | 11 |
23,125 | public void toXml ( final OptionElement root , final OutputStream str ) throws OptionsException { Writer wtr = null ; try { XmlEmit xml = new XmlEmit ( true ) ; wtr = new OutputStreamWriter ( str ) ; xml . startEmit ( wtr ) ; xml . openTag ( outerTag ) ; for ( OptionElement oe : root . getChildren ( ) ) { childToXml ( oe , xml ) ; } xml . closeTag ( outerTag ) ; } catch ( OptionsException ce ) { throw ce ; } catch ( Throwable t ) { throw new OptionsException ( t ) ; } finally { if ( wtr != null ) { try { wtr . close ( ) ; } catch ( Throwable t ) { } } } } | Emit the options as xml . | 168 | 7 |
23,126 | @ Override public Object getProperty ( final String name ) throws OptionsException { Object val = getOptProperty ( name ) ; if ( val == null ) { throw new OptionsException ( "Missing property " + name ) ; } return val ; } | Get required property throw exception if absent | 51 | 7 |
23,127 | @ Override public String getStringProperty ( final String name ) throws OptionsException { Object val = getProperty ( name ) ; if ( ! ( val instanceof String ) ) { throw new OptionsException ( "org.bedework.calenv.bad.option.value" ) ; } return ( String ) val ; } | Return the String value of the named property . | 67 | 9 |
23,128 | public Collection match ( final String name ) throws OptionsException { if ( useSystemwideValues ) { return match ( optionsRoot , makePathElements ( name ) , - 1 ) ; } return match ( localOptionsRoot , makePathElements ( name ) , - 1 ) ; } | Match for values . | 59 | 4 |
23,129 | public static String getProperty ( final MessageResources msg , final String pname , final String def ) throws Throwable { String p = msg . getMessage ( pname ) ; if ( p == null ) { return def ; } return p ; } | Return a property value or the default | 51 | 7 |
23,130 | public static String getReqProperty ( final MessageResources msg , final String pname ) throws Throwable { String p = getProperty ( msg , pname , null ) ; if ( p == null ) { logger . error ( "No definition for property " + pname ) ; throw new Exception ( ": No definition for property " + pname ) ; } return p ; } | Return a required property value | 79 | 5 |
23,131 | public static boolean getBoolProperty ( final MessageResources msg , final String pname , final boolean def ) throws Throwable { String p = msg . getMessage ( pname ) ; if ( p == null ) { return def ; } return Boolean . valueOf ( p ) ; } | Return a boolean property value or the default | 59 | 8 |
23,132 | public static int getIntProperty ( final MessageResources msg , final String pname , final int def ) throws Throwable { String p = msg . getMessage ( pname ) ; if ( p == null ) { return def ; } return Integer . valueOf ( p ) ; } | Return an int property value or the default | 58 | 8 |
23,133 | public static MessageEmit getErrorObj ( final HttpServletRequest request , final String errorObjAttrName ) { if ( errorObjAttrName == null ) { // don't set return null ; } HttpSession sess = request . getSession ( false ) ; if ( sess == null ) { logger . error ( "No session!!!!!!!" ) ; return null ; } Object o = sess . getAttribute ( errorObjAttrName ) ; if ( ( o != null ) && ( o instanceof MessageEmit ) ) { return ( MessageEmit ) o ; } return null ; } | Get the existing error object from the session or null . | 130 | 11 |
23,134 | public static MessageEmit getMessageObj ( final HttpServletRequest request , final String messageObjAttrName ) { if ( messageObjAttrName == null ) { // don't set return null ; } HttpSession sess = request . getSession ( false ) ; if ( sess == null ) { logger . error ( "No session!!!!!!!" ) ; return null ; } Object o = sess . getAttribute ( messageObjAttrName ) ; if ( ( o != null ) && ( o instanceof MessageEmit ) ) { return ( MessageEmit ) o ; } return null ; } | Get the existing message object from the session or null . | 130 | 11 |
23,135 | public static double quickRatio ( final String paramFirst , final String paramSecond ) { if ( paramFirst == null || paramSecond == null ) { return 1 ; } double matches = 0 ; // Use a sparse array to reduce the memory usage // for unicode characters. final int x [ ] [ ] = new int [ 256 ] [ ] ; for ( char c : paramSecond . toCharArray ( ) ) { if ( x [ c >> 8 ] == null ) { x [ c >> 8 ] = new int [ 256 ] ; } x [ c >> 8 ] [ c & 0xFF ] ++ ; } for ( char c : paramFirst . toCharArray ( ) ) { final int n = ( x [ c >> 8 ] == null ) ? 0 : x [ c >> 8 ] [ c & 0xFF ] -- ; if ( n > 0 ) { matches ++ ; } } return 2.0 * matches / ( paramFirst . length ( ) + paramSecond . length ( ) ) ; } | Calculates the similarity of two strings . This is done by comparing the frequency each character occures in both strings . | 212 | 24 |
23,136 | public ObjectName createCustomComponentMBeanName ( final String type , final String name ) { ObjectName result = null ; String tmp = jmxDomainName + ":" + "type=" + sanitizeString ( type ) + ",name=" + sanitizeString ( name ) ; try { result = new ObjectName ( tmp ) ; } catch ( MalformedObjectNameException e ) { error ( "Couldn't create ObjectName from: " + type + " , " + name ) ; } return result ; } | Formulate and return the MBean ObjectName of a custom control MBean | 110 | 17 |
23,137 | public static ObjectName getSystemObjectName ( final String domainName , final String containerName , final Class theClass ) throws MalformedObjectNameException { String tmp = domainName + ":" + "type=" + theClass . getName ( ) + ",name=" + getRelativeName ( containerName , theClass ) ; return new ObjectName ( tmp ) ; } | Retrieve a System ObjectName | 77 | 6 |
23,138 | public void unregisterMBean ( final ObjectName name ) throws JMException { if ( ( beanServer != null ) && beanServer . isRegistered ( name ) && registeredMBeanNames . remove ( name ) ) { beanServer . unregisterMBean ( name ) ; } } | Unregister an MBean | 61 | 6 |
23,139 | public void set ( final T paramOrigin , final T paramDestination , final boolean paramBool ) { assert paramOrigin != null ; assert paramDestination != null ; if ( ! mMap . containsKey ( paramOrigin ) ) { mMap . put ( paramOrigin , new IdentityHashMap < T , Boolean > ( ) ) ; } mMap . get ( paramOrigin ) . put ( paramDestination , paramBool ) ; } | Sets the connection between a and b . | 92 | 9 |
23,140 | public boolean get ( final T paramOrigin , final T paramDestination ) { assert paramOrigin != null ; assert paramDestination != null ; if ( ! mMap . containsKey ( paramOrigin ) ) { return false ; } final Boolean bool = mMap . get ( paramOrigin ) . get ( paramDestination ) ; return bool != null && bool ; } | Returns whether there is a connection between a and b . Unknown objects do never have a connection . | 75 | 19 |
23,141 | public void toStringSegment ( final ToString ts ) { ts . append ( "sysCode" , String . valueOf ( getSysCode ( ) ) ) ; ts . append ( "dtstamp" , getDtstamp ( ) ) ; ts . append ( "sequence" , getSequence ( ) ) ; } | Add our stuff to the ToString object | 70 | 8 |
23,142 | public synchronized byte [ ] toByteArray ( ) { byte [ ] outBuff = new byte [ count ] ; int pos = 0 ; for ( BufferPool . Buffer b : buffers ) { System . arraycopy ( b . buf , 0 , outBuff , pos , b . pos ) ; pos += b . pos ; } return outBuff ; } | Creates a newly allocated byte array . Its size is the current size of this output stream and the valid contents of the buffer have been copied into it . | 72 | 31 |
23,143 | public void release ( ) throws IOException { for ( BufferPool . Buffer b : buffers ) { PooledBuffers . release ( b ) ; } buffers . clear ( ) ; count = 0 ; } | This really release buffers back to the pool . MUST be called to gain the benefit of pooling . | 42 | 20 |
23,144 | public static boolean createFolderStructure ( final File pFile , IConfigurationPath [ ] pPaths ) throws TTIOException { boolean returnVal = true ; pFile . mkdirs ( ) ; // creation of folder structure for ( IConfigurationPath paths : pPaths ) { final File toCreate = new File ( pFile , paths . getFile ( ) . getName ( ) ) ; if ( paths . isFolder ( ) ) { returnVal = toCreate . mkdir ( ) ; } else { try { returnVal = toCreate . createNewFile ( ) ; } catch ( final IOException exc ) { throw new TTIOException ( exc ) ; } } if ( ! returnVal ) { break ; } } return returnVal ; } | Creating a folder structure based on a set of paths given as parameter and returning a boolean determining the success . | 157 | 21 |
23,145 | public static int compareStructure ( final File pFile , IConfigurationPath [ ] pPaths ) { int existing = 0 ; for ( final IConfigurationPath path : pPaths ) { final File currentFile = new File ( pFile , path . getFile ( ) . getName ( ) ) ; if ( currentFile . exists ( ) ) { existing ++ ; } } return existing - pPaths . length ; } | Checking a structure in a folder to be equal with the data in this enum . | 89 | 17 |
23,146 | public static synchronized void invokeFullDiff ( final Builder paramBuilder ) throws TTException { checkParams ( paramBuilder ) ; DiffKind . FULL . invoke ( paramBuilder ) ; } | Do a full diff . | 37 | 5 |
23,147 | public static synchronized void invokeStructuralDiff ( final Builder paramBuilder ) throws TTException { checkParams ( paramBuilder ) ; DiffKind . STRUCTURAL . invoke ( paramBuilder ) ; } | Do a structural diff . | 41 | 5 |
23,148 | private static void checkParams ( final Builder paramBuilder ) { checkState ( paramBuilder . mSession != null && paramBuilder . mKey >= 0 && paramBuilder . mNewRev >= 0 && paramBuilder . mOldRev >= 0 && paramBuilder . mObservers != null && paramBuilder . mKind != null , "No valid arguments specified!" ) ; checkState ( paramBuilder . mNewRev != paramBuilder . mOldRev && paramBuilder . mNewRev >= paramBuilder . mOldRev , "Revision numbers must not be the same and the new revision must have a greater number than the old revision!" ) ; } | Check parameters for validity and assign global static variables . | 133 | 10 |
23,149 | public boolean equalsAllBut ( DirRecord that , String [ ] attrIDs ) throws NamingException { if ( attrIDs == null ) throw new NamingException ( "DirectoryRecord: null attrID list" ) ; if ( ! dnEquals ( that ) ) { return false ; } int n = attrIDs . length ; if ( n == 0 ) return true ; Attributes thisAttrs = getAttributes ( ) ; Attributes thatAttrs = that . getAttributes ( ) ; if ( thisAttrs == null ) { if ( thatAttrs == null ) return true ; return false ; } if ( thatAttrs == null ) { return false ; } /** We need to ensure that all attributes are checked. We init thatLeft to the number of attributes in the source. We decrement for each checked attribute. We then decrement for each ignored attribute present in that If the result is non-zero, then there are some extra attributes in that so we return unequal. */ int sz = thisAttrs . size ( ) ; int thatLeft = sz ; if ( ( sz == 0 ) && ( thatAttrs . size ( ) == 0 ) ) { return true ; } NamingEnumeration ne = thisAttrs . getAll ( ) ; if ( ne == null ) { return false ; } while ( ne . hasMore ( ) ) { Attribute attr = ( Attribute ) ne . next ( ) ; String id = attr . getID ( ) ; boolean present = false ; for ( int i = 0 ; i < attrIDs . length ; i ++ ) { if ( id . equalsIgnoreCase ( attrIDs [ i ] ) ) { present = true ; break ; } } if ( present ) { // We don't compare if ( thatAttrs . get ( id ) != null ) thatLeft -- ; } else { Attribute thatAttr = thatAttrs . get ( id ) ; if ( thatAttr == null ) { return false ; } if ( ! thatAttr . contains ( attr ) ) { return false ; } thatLeft -- ; } } return ( thatLeft == 0 ) ; } | This compares all but the named attributes allbut true = > All must be equal except those on the list | 455 | 21 |
23,150 | public boolean dnEquals ( DirRecord that ) throws NamingException { if ( that == null ) { throw new NamingException ( "Null record for dnEquals" ) ; } String thisDn = getDn ( ) ; if ( thisDn == null ) { throw new NamingException ( "No dn for this record" ) ; } String thatDn = that . getDn ( ) ; if ( thatDn == null ) { throw new NamingException ( "That record has no dn" ) ; } return ( thisDn . equals ( thatDn ) ) ; } | Check dns for equality | 132 | 5 |
23,151 | public void addAttr ( String attr , Object val ) throws NamingException { // System.out.println("addAttr " + attr); Attribute a = findAttr ( attr ) ; if ( a == null ) { setAttr ( attr , val ) ; } else { a . add ( val ) ; } } | Add the attribute value to the table . If an attribute already exists add it to the end of its values . | 74 | 22 |
23,152 | public boolean contains ( Attribute attr ) throws NamingException { if ( attr == null ) { return false ; // protect } Attribute recAttr = getAttributes ( ) . get ( attr . getID ( ) ) ; if ( recAttr == null ) { return false ; } NamingEnumeration ne = attr . getAll ( ) ; while ( ne . hasMore ( ) ) { if ( ! recAttr . contains ( ne . next ( ) ) ) { return false ; } } return true ; } | Return true if the record contains all of the values of the given attribute . | 114 | 15 |
23,153 | public NamingEnumeration attrElements ( String attr ) throws NamingException { Attribute a = findAttr ( attr ) ; if ( a == null ) { return null ; } return a . getAll ( ) ; } | Retrieve an enumeration of the named attribute s values . The behaviour of this enumeration is unspecified if the the attribute s values are added changed or removed while the enumeration is in progress . If the attribute values are ordered the enumeration s items will be ordered . | 52 | 54 |
23,154 | private void emitEndTag ( ) throws TTIOException { final long nodeKey = mRtx . getNode ( ) . getDataKey ( ) ; mEvent = mFac . createEndElement ( mRtx . getQNameOfCurrentNode ( ) , new NamespaceIterator ( mRtx ) ) ; mRtx . moveTo ( nodeKey ) ; } | Emit end tag . | 78 | 5 |
23,155 | private void emitNode ( ) throws TTIOException { switch ( mRtx . getNode ( ) . getKind ( ) ) { case ROOT : mEvent = mFac . createStartDocument ( ) ; break ; case ELEMENT : final long key = mRtx . getNode ( ) . getDataKey ( ) ; final QName qName = mRtx . getQNameOfCurrentNode ( ) ; mEvent = mFac . createStartElement ( qName , new AttributeIterator ( mRtx ) , new NamespaceIterator ( mRtx ) ) ; mRtx . moveTo ( key ) ; break ; case TEXT : mEvent = mFac . createCharacters ( mRtx . getValueOfCurrentNode ( ) ) ; break ; default : throw new IllegalStateException ( "Kind not known!" ) ; } } | Emit a node . | 178 | 5 |
23,156 | private void emit ( ) throws TTIOException { // Emit pending end elements. if ( mCloseElements ) { if ( ! mStack . empty ( ) && mStack . peek ( ) != ( ( ITreeStructData ) mRtx . getNode ( ) ) . getLeftSiblingKey ( ) ) { mRtx . moveTo ( mStack . pop ( ) ) ; emitEndTag ( ) ; mRtx . moveTo ( mKey ) ; } else if ( ! mStack . empty ( ) ) { mRtx . moveTo ( mStack . pop ( ) ) ; emitEndTag ( ) ; mRtx . moveTo ( mKey ) ; mCloseElements = false ; mCloseElementsEmitted = true ; } } else { mCloseElementsEmitted = false ; // Emit node. emitNode ( ) ; final long nodeKey = mRtx . getNode ( ) . getDataKey ( ) ; mLastKey = nodeKey ; // Push end element to stack if we are a start element. if ( mRtx . getNode ( ) . getKind ( ) == ELEMENT ) { mStack . push ( nodeKey ) ; } // Remember to emit all pending end elements from stack if // required. if ( ! ( ( ITreeStructData ) mRtx . getNode ( ) ) . hasFirstChild ( ) && ! ( ( ITreeStructData ) mRtx . getNode ( ) ) . hasRightSibling ( ) ) { mGoUp = true ; moveToNextNode ( ) ; } else if ( mRtx . getNode ( ) . getKind ( ) == ELEMENT && ! ( ( ElementNode ) mRtx . getNode ( ) ) . hasFirstChild ( ) ) { // Case: Empty elements with right siblings. mGoBack = true ; moveToNextNode ( ) ; } } } | Move to node and emit it . | 402 | 7 |
23,157 | private boolean isBooleanFalse ( ) { if ( getNode ( ) . getDataKey ( ) >= 0 ) { return false ; } else { // is AtomicValue if ( getNode ( ) . getTypeKey ( ) == NamePageHash . generateHashForString ( "xs:boolean" ) ) { // atomic value of type boolean // return true, if atomic values's value is false return ! ( Boolean . parseBoolean ( new String ( ( ( ITreeValData ) getNode ( ) ) . getRawValue ( ) ) ) ) ; } else { return false ; } } } | Tests whether current Item is an atomic value with boolean value false . | 126 | 14 |
23,158 | private String expandString ( ) { final FastStringBuffer fsb = new FastStringBuffer ( FastStringBuffer . SMALL ) ; try { final INodeReadTrx rtx = createRtxAndMove ( ) ; final FilterAxis axis = new FilterAxis ( new DescendantAxis ( rtx ) , rtx , new TextFilter ( rtx ) ) ; while ( axis . hasNext ( ) ) { if ( rtx . getNode ( ) . getKind ( ) == TEXT ) { fsb . append ( rtx . getValueOfCurrentNode ( ) ) ; } axis . next ( ) ; } rtx . close ( ) ; } catch ( final TTException exc ) { LOGGER . error ( exc . toString ( ) ) ; } return fsb . condense ( ) . toString ( ) ; } | Filter text nodes . | 178 | 4 |
23,159 | public int getTypeAnnotation ( ) { int type = 0 ; if ( nodeKind == ATTRIBUTE ) { type = StandardNames . XS_UNTYPED_ATOMIC ; } else { type = StandardNames . XS_UNTYPED ; } return type ; } | Get the type annotation . | 63 | 5 |
23,160 | public boolean walk ( OutputHandler outputHandler ) throws IOException { try ( ZipFile zipFile = new ZipFile ( zip ) ) { // walk all entries and look for matches Enumeration < ? extends ZipEntry > entries = zipFile . entries ( ) ; while ( entries . hasMoreElements ( ) ) { ZipEntry entry = entries . nextElement ( ) ; // first check if the file matches the name, if a name-pattern is given File file = new File ( zip , entry . getName ( ) ) ; if ( outputHandler . found ( file , zipFile . getInputStream ( entry ) ) ) { return true ; } // look for name or content inside zip-files as well, do it recursively to also // look at content of nested zip-files if ( ZipUtils . isZip ( entry . getName ( ) ) ) { if ( walkRecursive ( file , zipFile . getInputStream ( entry ) , outputHandler ) ) { return true ; } } } return false ; } } | Run the ZipFileWalker using the given OutputHandler | 216 | 10 |
23,161 | public void updateConfigInfo ( final HttpServletRequest request , final XSLTConfig xcfg ) throws ServletException { PresentationState ps = getPresentationState ( request ) ; if ( ps == null ) { // Still can't do a thing return ; } if ( xcfg . nextCfg == null ) { xcfg . nextCfg = new XSLTFilterConfigInfo ( ) ; } else { xcfg . cfg . updateFrom ( xcfg . nextCfg ) ; } xcfg . cfg . setAppRoot ( ps . getAppRoot ( ) ) ; xcfg . nextCfg . setAppRoot ( ps . getAppRoot ( ) ) ; /** Transfer the state */ if ( ps . getNoXSLTSticky ( ) ) { xcfg . cfg . setDontFilter ( true ) ; xcfg . nextCfg . setDontFilter ( true ) ; } else { xcfg . cfg . setDontFilter ( ps . getNoXSLT ( ) ) ; ps . setNoXSLT ( false ) ; } /* ============== Don't filter ================= */ if ( xcfg . cfg . getDontFilter ( ) ) { // I think that's enough return ; } /* ============== Locale ================= */ Locale l = request . getLocale ( ) ; String lang = l . getLanguage ( ) ; if ( ( lang == null ) || ( lang . length ( ) == 0 ) ) { lang = xcfg . cfg . getDefaultLang ( ) ; } String country = l . getCountry ( ) ; if ( ( country == null ) || ( country . length ( ) == 0 ) ) { country = xcfg . cfg . getDefaultCountry ( ) ; } xcfg . cfg . setLocaleInfo ( XSLTFilterConfigInfo . makeLocale ( lang , country ) ) ; /* locale always sticky */ xcfg . nextCfg . setLocaleInfo ( XSLTFilterConfigInfo . makeLocale ( lang , country ) ) ; /* ============== Browser type ================= */ String temp = ps . getBrowserType ( ) ; if ( temp != null ) { xcfg . cfg . setBrowserType ( temp ) ; } if ( ! ps . getBrowserTypeSticky ( ) ) { ps . setBrowserType ( null ) ; } else { xcfg . nextCfg . setBrowserType ( temp ) ; } /* ============== Skin name ================= */ temp = ps . getSkinName ( ) ; if ( temp != null ) { xcfg . cfg . setSkinName ( temp ) ; } if ( ! ps . getSkinNameSticky ( ) ) { ps . setSkinName ( null ) ; } else { xcfg . nextCfg . setSkinName ( temp ) ; } /* ============== Content type ================= */ xcfg . cfg . setContentType ( ps . getContentType ( ) ) ; if ( ! ps . getContentTypeSticky ( ) ) { ps . setContentType ( null ) ; } else { xcfg . nextCfg . setContentType ( ps . getContentType ( ) ) ; } /* ============== Refresh ================= */ xcfg . cfg . setForceReload ( ps . getForceXSLTRefresh ( ) ) ; ps . setForceXSLTRefresh ( false ) ; /* I don't think we ever want to allow this info.setReloadAlways(ps.getForceXSLTRefreshAlways()); */ } | This method can be overridden to allow a subclass to set up ready for a transformation . | 750 | 18 |
23,162 | protected PresentationState getPresentationState ( HttpServletRequest request ) { String attrName = getPresentationAttrName ( ) ; if ( ( attrName == null ) || ( attrName . equals ( "NONE" ) ) ) { return null ; } /* First try the request */ Object o = request . getAttribute ( attrName ) ; if ( o == null ) { HttpSession sess = request . getSession ( false ) ; if ( sess == null ) { return null ; } o = sess . getAttribute ( attrName ) ; } if ( o == null ) { return null ; } PresentationState ps = ( PresentationState ) o ; if ( debug ( ) ) { ps . debugDump ( "ConfiguredXSLTFilter" ) ; } return ps ; } | Obtain the presentation state from the session . Override if you want different behaviour . | 178 | 17 |
23,163 | private boolean tryPath ( StringBuilder prefix , String el , boolean dir ) { String path = prefix + "/" + el ; if ( dir && directoryBrowsingDisallowed ) { path += "/" + xsltdirMarkerName ; } if ( debug ( ) ) { debug ( "trypath: " + path ) ; } try { URL u = new URL ( path ) ; URLConnection uc = u . openConnection ( ) ; if ( ! ( uc instanceof HttpURLConnection ) ) { return false ; } HttpURLConnection huc = ( HttpURLConnection ) uc ; if ( huc . getResponseCode ( ) != 200 ) { return false ; } prefix . append ( "/" ) ; prefix . append ( el ) ; return true ; } catch ( final Throwable t ) { if ( debug ( ) ) { debug ( "trypath exception: " ) ; error ( t ) ; } } return false ; } | Try a path and see if it exists . If so append the element | 202 | 14 |
23,164 | public static final DumbData [ ] [ ] createDatas ( final int [ ] pDatasPerRevision ) { final DumbData [ ] [ ] returnVal = new DumbData [ pDatasPerRevision . length ] [ ] ; for ( int i = 0 ; i < pDatasPerRevision . length ; i ++ ) { returnVal [ i ] = new DumbData [ pDatasPerRevision [ i ] ] ; for ( int j = 0 ; j < pDatasPerRevision [ i ] ; j ++ ) { returnVal [ i ] [ j ] = generateOne ( ) ; } } return returnVal ; } | Generating new data - elements passed on a given number of datas within a revision | 138 | 16 |
23,165 | public Void call ( ) throws TTException { emitStartDocument ( ) ; long [ ] versionsToUse ; // if there are no versions specified, take the last one, of not version==0 if ( mVersions . length == 0 ) { if ( mSession . getMostRecentVersion ( ) > 0 ) { versionsToUse = new long [ ] { mSession . getMostRecentVersion ( ) } ; } // revision 0 = bootstrapped page else { versionsToUse = new long [ 0 ] ; } } // if there is any negative number specified, take the entire range of versions, otherwise take the // parameter else { // sort the versions first Arrays . sort ( mVersions ) ; if ( mVersions [ 0 ] < 0 ) { versionsToUse = new long [ ( int ) mSession . getMostRecentVersion ( ) - 1 ] ; for ( int i = 0 ; i < versionsToUse . length ; i ++ ) { versionsToUse [ i ] = i + 1 ; } } // otherwise take the versions as requested as params else { int index = Arrays . binarySearch ( mVersions , 1 ) ; versionsToUse = Arrays . copyOfRange ( mVersions , index , mVersions . length ) ; } } for ( int i = 0 ; i < versionsToUse . length ; i ++ ) { INodeReadTrx rtx = new NodeReadTrx ( mSession . beginBucketRtx ( versionsToUse [ i ] ) ) ; if ( versionsToUse == null || mVersions . length > 1 ) { emitStartManualElement ( i ) ; } rtx . moveTo ( mNodeKey ) ; final AbsAxis descAxis = new DescendantAxis ( rtx , true ) ; // Setup primitives. boolean closeElements = false ; long key = rtx . getNode ( ) . getDataKey ( ) ; // Iterate over all nodes of the subtree including self. while ( descAxis . hasNext ( ) ) { key = descAxis . next ( ) ; ITreeStructData currentStruc = ( ITreeStructData ) rtx . getNode ( ) ; // Emit all pending end elements. if ( closeElements ) { while ( ! mStack . empty ( ) && mStack . peek ( ) != currentStruc . getLeftSiblingKey ( ) ) { rtx . moveTo ( mStack . pop ( ) ) ; emitEndElement ( rtx ) ; rtx . moveTo ( key ) ; } if ( ! mStack . empty ( ) ) { rtx . moveTo ( mStack . pop ( ) ) ; emitEndElement ( rtx ) ; } rtx . moveTo ( key ) ; closeElements = false ; } // Emit node. emitStartElement ( rtx ) ; // Push end element to stack if we are a start element with // children. if ( currentStruc . getKind ( ) == IConstants . ELEMENT && currentStruc . hasFirstChild ( ) ) { mStack . push ( rtx . getNode ( ) . getDataKey ( ) ) ; } // Remember to emit all pending end elements from stack if // required. if ( ! currentStruc . hasFirstChild ( ) && ! currentStruc . hasRightSibling ( ) ) { closeElements = true ; } } // Finally emit all pending end elements. while ( ! mStack . empty ( ) ) { rtx . moveTo ( mStack . pop ( ) ) ; emitEndElement ( rtx ) ; } if ( versionsToUse == null || mVersions . length > 1 ) { emitEndManualElement ( i ) ; } } emitEndDocument ( ) ; return null ; } | Serialize the storage . | 795 | 5 |
23,166 | public static Node getOneTaggedNode ( final Node el , final String name ) throws SAXException { if ( ! el . hasChildNodes ( ) ) { return null ; } final NodeList children = el . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { final Node n = children . item ( i ) ; if ( name . equals ( n . getNodeName ( ) ) ) { return n ; } } return null ; } | Get the single named element . | 109 | 6 |
23,167 | public static String getOneNodeVal ( final Node el , final String name ) throws SAXException { /* We expect one child of type text */ if ( ! el . hasChildNodes ( ) ) { return null ; } NodeList children = el . getChildNodes ( ) ; if ( children . getLength ( ) > 1 ) { throw new SAXException ( "Multiple property values: " + name ) ; } Node child = children . item ( 0 ) ; return child . getNodeValue ( ) ; } | Get the value of an element . We expect 0 or 1 child nodes . For no child node we return null for more than one we raise an exception . | 109 | 31 |
23,168 | public static String getReqOneNodeVal ( final Node el , final String name ) throws SAXException { String str = getOneNodeVal ( el , name ) ; if ( ( str == null ) || ( str . length ( ) == 0 ) ) { throw new SAXException ( "Missing property value: " + name ) ; } return str ; } | Get the value of an element . We expect 1 child node otherwise we raise an exception . | 76 | 18 |
23,169 | public static String getAttrVal ( final Element el , final String name ) throws SAXException { Attr at = el . getAttributeNode ( name ) ; if ( at == null ) { return null ; } return at . getValue ( ) ; } | Return the value of the named attribute of the given element . | 54 | 12 |
23,170 | public static String getReqAttrVal ( final Element el , final String name ) throws SAXException { String str = getAttrVal ( el , name ) ; if ( ( str == null ) || ( str . length ( ) == 0 ) ) { throw new SAXException ( "Missing attribute value: " + name ) ; } return str ; } | Return the required value of the named attribute of the given element . | 76 | 13 |
23,171 | public static String getAttrVal ( final NamedNodeMap nnm , final String name ) { Node nmAttr = nnm . getNamedItem ( name ) ; if ( ( nmAttr == null ) || ( absent ( nmAttr . getNodeValue ( ) ) ) ) { return null ; } return nmAttr . getNodeValue ( ) ; } | Return the attribute value of the named attribute from the given map . | 78 | 13 |
23,172 | public static Boolean getYesNoAttrVal ( final NamedNodeMap nnm , final String name ) throws SAXException { String val = getAttrVal ( nnm , name ) ; if ( val == null ) { return null ; } if ( ( ! "yes" . equals ( val ) ) && ( ! "no" . equals ( val ) ) ) { throw new SAXException ( "Invalid attribute value: " + val ) ; } return new Boolean ( "yes" . equals ( val ) ) ; } | The attribute value of the named attribute in the given map must be absent or yes or no . | 110 | 19 |
23,173 | public static List < Element > getElements ( final Node nd ) throws SAXException { final List < Element > al = new ArrayList <> ( ) ; NodeList children = nd . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { Node curnode = children . item ( i ) ; if ( curnode . getNodeType ( ) == Node . TEXT_NODE ) { String val = curnode . getNodeValue ( ) ; if ( val != null ) { for ( int vi = 0 ; vi < val . length ( ) ; vi ++ ) { if ( ! Character . isWhitespace ( val . charAt ( vi ) ) ) { throw new SAXException ( "Non-whitespace text in element body for " + nd . getLocalName ( ) + "\n text=" + val ) ; } } } } else if ( curnode . getNodeType ( ) == Node . COMMENT_NODE ) { // Ignore } else if ( curnode . getNodeType ( ) == Node . ELEMENT_NODE ) { al . add ( ( Element ) curnode ) ; } else { throw new SAXException ( "Unexpected child node " + curnode . getLocalName ( ) + " for " + nd . getLocalName ( ) ) ; } } return al ; } | All the children must be elements or white space text nodes . | 305 | 12 |
23,174 | public static String getElementContent ( final Element el , final boolean trim ) throws SAXException { StringBuilder sb = new StringBuilder ( ) ; NodeList children = el . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { Node curnode = children . item ( i ) ; if ( curnode . getNodeType ( ) == Node . TEXT_NODE ) { sb . append ( curnode . getNodeValue ( ) ) ; } else if ( curnode . getNodeType ( ) == Node . CDATA_SECTION_NODE ) { sb . append ( curnode . getNodeValue ( ) ) ; } else if ( curnode . getNodeType ( ) == Node . COMMENT_NODE ) { // Ignore } else { throw new SAXException ( "Unexpected child node " + curnode . getLocalName ( ) + " for " + el . getLocalName ( ) ) ; } } if ( ! trim ) { return sb . toString ( ) ; } return sb . toString ( ) . trim ( ) ; } | Return the content for the current element . All leading and trailing whitespace and embedded comments will be removed . | 250 | 21 |
23,175 | public static void setElementContent ( final Node n , final String s ) throws SAXException { NodeList children = n . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { Node curnode = children . item ( i ) ; n . removeChild ( curnode ) ; } Document d = n . getOwnerDocument ( ) ; final Node textNode = d . createTextNode ( s ) ; n . appendChild ( textNode ) ; } | Replace the content for the current element . | 111 | 9 |
23,176 | public static boolean hasContent ( final Element el ) throws SAXException { String s = getElementContent ( el ) ; return ( s != null ) && ( s . length ( ) > 0 ) ; } | Return true if the current element has non zero length content . | 43 | 12 |
23,177 | public static boolean hasChildren ( final Element el ) throws SAXException { NodeList children = el . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { Node curnode = children . item ( i ) ; short ntype = curnode . getNodeType ( ) ; if ( ( ntype != Node . TEXT_NODE ) && ( ntype != Node . CDATA_SECTION_NODE ) && ( ntype != Node . COMMENT_NODE ) ) { return true ; } } return false ; } | See if this node has any children | 127 | 7 |
23,178 | public static boolean nodeMatches ( final Node nd , final QName tag ) { if ( tag == null ) { return false ; } String ns = nd . getNamespaceURI ( ) ; if ( ns == null ) { /* It appears a node can have a NULL namespace but a QName has a zero length */ if ( ( tag . getNamespaceURI ( ) != null ) && ( ! "" . equals ( tag . getNamespaceURI ( ) ) ) ) { return false ; } } else if ( ! ns . equals ( tag . getNamespaceURI ( ) ) ) { return false ; } String ln = nd . getLocalName ( ) ; if ( ln == null ) { if ( tag . getLocalPart ( ) != null ) { return false ; } } else if ( ! ln . equals ( tag . getLocalPart ( ) ) ) { return false ; } return true ; } | See if node matches tag | 195 | 5 |
23,179 | public static QName fromNode ( final Node nd ) { String ns = nd . getNamespaceURI ( ) ; if ( ns == null ) { /* It appears a node can have a NULL namespace but a QName has a zero length */ ns = "" ; } return new QName ( ns , nd . getLocalName ( ) ) ; } | Return a QName for the node | 75 | 7 |
23,180 | public static SSLSocketFactory getSslSocketFactory ( ) { if ( ! sslDisabled ) { return SSLSocketFactory . getSocketFactory ( ) ; } try { final X509Certificate [ ] _AcceptedIssuers = new X509Certificate [ ] { } ; final SSLContext ctx = SSLContext . getInstance ( "TLS" ) ; final X509TrustManager tm = new X509TrustManager ( ) { @ Override public X509Certificate [ ] getAcceptedIssuers ( ) { return _AcceptedIssuers ; } @ Override public void checkServerTrusted ( final X509Certificate [ ] chain , final String authType ) throws CertificateException { } @ Override public void checkClientTrusted ( final X509Certificate [ ] chain , final String authType ) throws CertificateException { } } ; ctx . init ( null , new TrustManager [ ] { tm } , new SecureRandom ( ) ) ; return new SSLSocketFactory ( ctx , SSLSocketFactory . ALLOW_ALL_HOSTNAME_VERIFIER ) ; } catch ( final Throwable t ) { throw new RuntimeException ( t ) ; } } | Allow testing of features when we don t have any valid certs . | 253 | 13 |
23,181 | public void setCredentials ( final String user , final String pw ) { if ( user == null ) { credentials = null ; } else { credentials = new UsernamePasswordCredentials ( user , pw ) ; } } | Set the credentials . user == null for unauthenticated . | 48 | 12 |
23,182 | public int sendRequest ( final String methodName , final String url , final List < Header > hdrs , final String contentType , final int contentLen , final byte [ ] content ) throws HttpException { int sz = 0 ; if ( content != null ) { sz = content . length ; } if ( debug ( ) ) { debug ( "About to send request: method=" + methodName + " url=" + url + " contentLen=" + contentLen + " content.length=" + sz + " contentType=" + contentType ) ; } try { URI u = new URI ( url ) ; if ( ! hostSpecified && ( u . getHost ( ) == null ) ) { if ( ( baseURI == null ) && ( baseURIValue != null ) ) { baseURI = new URI ( baseURIValue ) ; } if ( baseURI == null ) { throw new HttpException ( "No base URI specified for non-absolute URI " + url ) ; } if ( baseURI . getHost ( ) == null ) { throw new HttpException ( "Base URI must be absolute: " + baseURI ) ; } u = baseURI . resolve ( u ) ; } if ( debug ( ) ) { debug ( " url resolves to " + u ) ; } method = findMethod ( methodName , u ) ; if ( credentials != null ) { getCredentialsProvider ( ) . setCredentials ( new AuthScope ( u . getHost ( ) , u . getPort ( ) ) , credentials ) ; } if ( ! Util . isEmpty ( hdrs ) ) { for ( final Header hdr : hdrs ) { method . addHeader ( hdr ) ; } } if ( method instanceof HttpEntityEnclosingRequestBase ) { if ( content != null ) { if ( contentType == null ) { setContent ( content , "text/xml" ) ; } else { setContent ( content , contentType ) ; } } } response = execute ( method ) ; } catch ( final HttpException he ) { throw he ; } catch ( final Throwable t ) { throw new HttpException ( t . getLocalizedMessage ( ) , t ) ; } status = response . getStatusLine ( ) . getStatusCode ( ) ; return status ; } | Send a request to the server | 493 | 6 |
23,183 | protected HttpRequestBase findMethod ( final String name , final URI uri ) throws HttpException { String nm = name . toUpperCase ( ) ; if ( "PUT" . equals ( nm ) ) { return new HttpPut ( uri ) ; } if ( "GET" . equals ( nm ) ) { return new HttpGet ( uri ) ; } if ( "DELETE" . equals ( nm ) ) { return new HttpDelete ( uri ) ; } if ( "POST" . equals ( nm ) ) { return new HttpPost ( uri ) ; } if ( "PROPFIND" . equals ( nm ) ) { return new HttpPropfind ( uri ) ; } if ( "MKCALENDAR" . equals ( nm ) ) { return new HttpMkcalendar ( uri ) ; } if ( "MKCOL" . equals ( nm ) ) { return new HttpMkcol ( uri ) ; } if ( "OPTIONS" . equals ( nm ) ) { return new HttpOptions ( uri ) ; } if ( "REPORT" . equals ( nm ) ) { return new HttpReport ( uri ) ; } if ( "HEAD" . equals ( nm ) ) { return new HttpHead ( uri ) ; } throw new HttpException ( "Illegal method: " + name ) ; } | Specify the next method by name . | 300 | 8 |
23,184 | public void release ( ) throws HttpException { try { HttpEntity ent = getResponseEntity ( ) ; if ( ent != null ) { InputStream is = ent . getContent ( ) ; is . close ( ) ; } } catch ( Throwable t ) { throw new HttpException ( t . getLocalizedMessage ( ) , t ) ; } } | Release the connection | 76 | 3 |
23,185 | public int addItem ( final AtomicValue pItem ) { final int key = mList . size ( ) ; pItem . setNodeKey ( key ) ; // TODO: +2 is necessary, because key -1 is the NULLDATA final int itemKey = ( key + 2 ) * ( - 1 ) ; pItem . setNodeKey ( itemKey ) ; mList . add ( pItem ) ; return itemKey ; } | Adding to this list . | 91 | 5 |
23,186 | static void release ( BufferPool . Buffer buff ) throws IOException { if ( buff . buf . length == staticConf . getSmallBufferSize ( ) ) { smallBufferPool . put ( buff ) ; } else if ( buff . buf . length == staticConf . getMediumBufferSize ( ) ) { mediumBufferPool . put ( buff ) ; } else if ( buff . buf . length == staticConf . getLargeBufferSize ( ) ) { largeBufferPool . put ( buff ) ; } } | Release a buffer back to the pool . MUST be called to gain the benefit of pooling . | 104 | 19 |
23,187 | private static NotificationsHandler getHandler ( final String queueName , final Properties pr ) throws NotificationException { if ( handler != null ) { return handler ; } synchronized ( synchit ) { handler = new JmsNotificationsHandlerImpl ( queueName , pr ) ; } return handler ; } | Return a handler for the system event | 60 | 7 |
23,188 | public static void post ( final SysEvent ev , final String queueName , final Properties pr ) throws NotificationException { getHandler ( queueName , pr ) . post ( ev ) ; } | Called to notify container that an event occurred . In general this should not be called directly as consumers may receive the messages immediately perhaps before the referenced data has been written . | 39 | 34 |
23,189 | public static < T > AdjustCollectionResult < T > adjustCollection ( final Collection < T > newCol , final Collection < T > toAdjust ) { final AdjustCollectionResult < T > acr = new AdjustCollectionResult <> ( ) ; acr . removed = new ArrayList <> ( ) ; acr . added = new ArrayList <> ( ) ; acr . added . addAll ( newCol ) ; if ( toAdjust != null ) { for ( final T ent : toAdjust ) { if ( newCol . contains ( ent ) ) { acr . added . remove ( ent ) ; continue ; } acr . removed . add ( ent ) ; } for ( final T ent : acr . added ) { toAdjust . add ( ent ) ; acr . numAdded ++ ; } for ( final T ent : acr . removed ) { if ( toAdjust . remove ( ent ) ) { acr . numRemoved ++ ; } } } return acr ; } | Used to adjust a collection toAdjust so that it looks like the collection newCol . The collection newCol will be unchanged but the result object will contain a list of added and removed values . | 207 | 38 |
23,190 | public static String pathElement ( final int index , final String path ) { final String [ ] paths = path . split ( "/" ) ; int idx = index ; if ( ( paths [ 0 ] == null ) || ( paths [ 0 ] . length ( ) == 0 ) ) { // skip empty first part - leading "/" idx ++ ; } if ( idx >= paths . length ) { return null ; } return paths [ idx ] ; } | get the nth element from the path - first is 0 . | 96 | 13 |
23,191 | public static Locale makeLocale ( final String val ) throws Throwable { String lang = null ; String country = "" ; // NOT null for Locale String variant = "" ; if ( val == null ) { throw new Exception ( "Bad Locale: NULL" ) ; } if ( val . length ( ) == 2 ) { lang = val ; } else { int pos = val . indexOf ( ' ' ) ; if ( pos != 2 ) { throw new Exception ( "Bad Locale: " + val ) ; } lang = val . substring ( 0 , 2 ) ; pos = val . indexOf ( "_" , 3 ) ; if ( pos < 0 ) { if ( val . length ( ) != 5 ) { throw new Exception ( "Bad Locale: " + val ) ; } country = val . substring ( 3 ) ; } else { country = val . substring ( 3 , 5 ) ; if ( val . length ( ) > 6 ) { variant = val . substring ( 6 ) ; } } } return new Locale ( lang , country , variant ) ; } | make a locale from the standard underscore separated parts - no idea why this isn t in Locale | 230 | 19 |
23,192 | public static Properties getPropertiesFromResource ( final String name ) throws Throwable { Properties pr = new Properties ( ) ; InputStream is = null ; try { try { // The jboss?? way - should work for others as well. ClassLoader cl = Thread . currentThread ( ) . getContextClassLoader ( ) ; is = cl . getResourceAsStream ( name ) ; } catch ( Throwable clt ) { } if ( is == null ) { // Try another way is = Util . class . getResourceAsStream ( name ) ; } if ( is == null ) { throw new Exception ( "Unable to load properties file" + name ) ; } pr . load ( is ) ; //if (debug) { // pr.list(System.out); // Logger.getLogger(Util.class).debug( // "file.encoding=" + System.getProperty("file.encoding")); //} return pr ; } finally { if ( is != null ) { try { is . close ( ) ; } catch ( Throwable t1 ) { } } } } | Load a named resource as a Properties object | 232 | 8 |
23,193 | public static Object getObject ( final String className , final Class cl ) throws Exception { try { Object o = Class . forName ( className ) . newInstance ( ) ; if ( o == null ) { throw new Exception ( "Class " + className + " not found" ) ; } if ( ! cl . isInstance ( o ) ) { throw new Exception ( "Class " + className + " is not a subclass of " + cl . getName ( ) ) ; } return o ; } catch ( Exception e ) { throw e ; } catch ( Throwable t ) { throw new Exception ( t ) ; } } | Given a class name return an object of that class . The class parameter is used to check that the named class is an instance of that class . | 132 | 29 |
23,194 | public static String fmtMsg ( final String fmt , final String arg1 , final String arg2 ) { Object [ ] o = new Object [ 2 ] ; o [ 0 ] = arg1 ; o [ 1 ] = arg2 ; return MessageFormat . format ( fmt , o ) ; } | Format a message consisting of a format string plus two string parameters | 60 | 12 |
23,195 | public static String fmtMsg ( final String fmt , final int arg ) { Object [ ] o = new Object [ 1 ] ; o [ 0 ] = new Integer ( arg ) ; return MessageFormat . format ( fmt , o ) ; } | Format a message consisting of a format string plus one integer parameter | 49 | 12 |
23,196 | public static String makeRandomString ( int length , int maxVal ) { if ( length < 0 ) { return null ; } length = Math . min ( length , 1025 ) ; if ( maxVal < 0 ) { return null ; } maxVal = Math . min ( maxVal , 35 ) ; StringBuffer res = new StringBuffer ( ) ; Random rand = new Random ( ) ; for ( int i = 0 ; i <= length ; i ++ ) { res . append ( randChars [ rand . nextInt ( maxVal + 1 ) ] ) ; } return res . toString ( ) ; } | Creates a string of given length where each character comes from a set of values 0 - 9 followed by A - Z . | 127 | 25 |
23,197 | public static String [ ] appendTextToArray ( String [ ] sarray , final String val , final int maxEntries ) { if ( sarray == null ) { if ( maxEntries > 0 ) { sarray = new String [ 1 ] ; sarray [ 0 ] = val ; } return sarray ; } if ( sarray . length > maxEntries ) { String [ ] neb = new String [ maxEntries ] ; System . arraycopy ( sarray , sarray . length - maxEntries , neb , 0 , maxEntries ) ; sarray = neb ; sarray [ sarray . length - 1 ] = val ; neb = null ; return sarray ; } if ( sarray . length < maxEntries ) { int newLen = sarray . length + 1 ; String [ ] neb = new String [ newLen ] ; System . arraycopy ( sarray , 0 , neb , 0 , sarray . length ) ; sarray = neb ; sarray [ sarray . length - 1 ] = val ; neb = null ; return sarray ; } if ( maxEntries > 1 ) { System . arraycopy ( sarray , 1 , sarray , 0 , sarray . length - 1 ) ; } sarray [ sarray . length - 1 ] = val ; return sarray ; } | Add a string to a string array of a given maximum length . Truncates the string array if required . | 278 | 22 |
23,198 | public static String encodeArray ( final String [ ] val ) { if ( val == null ) { return null ; } int len = val . length ; if ( len == 0 ) { return "" ; } StringBuffer sb = new StringBuffer ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( i > 0 ) { sb . append ( " " ) ; } String s = val [ i ] ; try { if ( s == null ) { sb . append ( "\t" ) ; } else { sb . append ( URLEncoder . encode ( s , "UTF-8" ) ) ; } } catch ( Throwable t ) { throw new RuntimeException ( t ) ; } } return sb . toString ( ) ; } | Return a String representing the given String array achieved by URLEncoding the individual String elements then concatenating with intervening blanks . | 166 | 27 |
23,199 | public static String [ ] decodeArray ( final String val ) { if ( val == null ) { return null ; } int len = val . length ( ) ; if ( len == 0 ) { return new String [ 0 ] ; } ArrayList < String > al = new ArrayList < String > ( ) ; int i = 0 ; while ( i < len ) { int end = val . indexOf ( " " , i ) ; String s ; if ( end < 0 ) { s = val . substring ( i ) ; i = len ; } else { s = val . substring ( i , end ) ; i = end + 1 ; } try { if ( s . equals ( "\t" ) ) { al . add ( null ) ; } else { al . add ( URLDecoder . decode ( s , "UTF-8" ) ) ; } } catch ( Throwable t ) { throw new RuntimeException ( t ) ; } } return al . toArray ( new String [ al . size ( ) ] ) ; } | Return a StringArray resulting from decoding the given String which should have been encoded by encodeArray | 217 | 18 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.