private PathExpression getCondition ( Node config ) throws IllegalNameException , RepositoryException { Node conditionAttr = config . getAttributes ( ) . getNamedItem ( "condition" ) ; if ( conditionAttr == null ) { return null ; } String conditionString = conditionAttr . getNodeValue ( ) ; int idx ; int axis ; InternalQName elementTest = null ; InternalQName nameTest = null ; InternalQName propertyName ; String propertyValue ; // parse axis if ( conditionString . startsWith ( "ancestor::" ) ) { axis = PathExpression . ANCESTOR ; idx = "ancestor::" . length ( ) ; } else if ( conditionString . startsWith ( "parent::" ) ) { axis = PathExpression . PARENT ; idx = "parent::" . length ( ) ; } else if ( conditionString . startsWith ( "@" ) ) { axis = PathExpression . SELF ; idx = "@" . length ( ) ; } else { axis = PathExpression . CHILD ; idx = 0 ; } try { if ( conditionString . startsWith ( "element(" , idx ) ) { int colon = conditionString . indexOf ( ' ' , idx + "element(" . length ( ) ) ; String name = conditionString . substring ( idx + "element(" . length ( ) , colon ) . trim ( ) ; if ( ! name . equals ( "*" ) ) { nameTest = resolver . parseJCRName ( ISO9075 . decode ( name ) ) . getInternalName ( ) ; } idx = conditionString . indexOf ( ")/@" , colon ) ; String type = conditionString . substring ( colon + 1 , idx ) . trim ( ) ; elementTest = resolver . parseJCRName ( ISO9075 . decode ( type ) ) . getInternalName ( ) ; idx += ")/@" . length ( ) ; } else { if ( axis == PathExpression . ANCESTOR || axis == PathExpression . CHILD || axis == PathExpression . PARENT ) { // simple name test String name = conditionString . substring ( idx , conditionString . indexOf ( ' ' , idx ) ) ; if ( ! name . equals ( "*" ) ) { nameTest = resolver . parseJCRName ( ISO9075 . decode ( name ) ) . getInternalName ( ) ; } idx += name . length ( ) + "/@" . length ( ) ; } } // parse property name int eq = conditionString . indexOf ( ' ' , idx ) ; String name = conditionString . substring ( idx , eq ) . trim ( ) ; propertyName = resolver . parseJCRName ( ISO9075 . decode ( name ) ) . getInternalName ( ) ; // parse string value int quote = conditionString . indexOf ( ' ' , eq ) + 1 ; propertyValue = conditionString . substring ( quote , conditionString . indexOf ( ' ' , quote ) ) ; } catch ( IndexOutOfBoundsException e ) { throw new RepositoryException ( conditionString ) ; } return new PathExpression ( axis , elementTest , nameTest , propertyName , propertyValue ) ; }
Gets the condition expression from the configuration .