private void getAnchorLegacyMetadataFromRel ( ValueMap resourceProps , Element element ) { // Check href attribute - do not change elements with no href or links to anchor names String href = element . getAttributeValue ( "href" ) ; String linkWindowTarget = element . getAttributeValue ( "target" ) ; if ( href == null || href . startsWith ( "#" ) ) { return ; } // get link metadata from rel element JSONObject metadata = null ; String metadataString = element . getAttributeValue ( "rel" ) ; if ( StringUtils . isNotEmpty ( metadataString ) ) { try { metadata = new JSONObject ( metadataString ) ; } catch ( JSONException ex ) { log . debug ( "Invalid link metadata: " + metadataString , ex ) ; } } if ( metadata == null ) { metadata = new JSONObject ( ) ; } // transform link metadata to virtual JCR resource with JCR properties JSONArray metadataPropertyNames = metadata . names ( ) ; if ( metadataPropertyNames != null ) { for ( int i = 0 ; i < metadataPropertyNames . length ( ) ; i ++ ) { String metadataPropertyName = metadataPropertyNames . optString ( i ) ; // check if value is array JSONArray valueArray = metadata . optJSONArray ( metadataPropertyName ) ; if ( valueArray != null ) { // store array values List < String > values = new ArrayList < String > ( ) ; for ( int j = 0 ; j < valueArray . length ( ) ; j ++ ) { values . add ( valueArray . optString ( j ) ) ; } resourceProps . put ( metadataPropertyName , values . toArray ( new String [ values . size ( ) ] ) ) ; } else { // store simple value Object value = metadata . opt ( metadataPropertyName ) ; if ( value != null ) { resourceProps . put ( metadataPropertyName , value ) ; } } } } // detect link type LinkType linkType = null ; String linkTypeString = resourceProps . get ( LinkNameConstants . PN_LINK_TYPE , String . class ) ; for ( Class < ? extends LinkType > candidateClass : linkHandlerConfig . getLinkTypes ( ) ) { LinkType candidate = AdaptTo . notNull ( adaptable , candidateClass ) ; if ( StringUtils . isNotEmpty ( linkTypeString ) ) { if ( StringUtils . equals ( linkTypeString , candidate . getId ( ) ) ) { linkType = candidate ; break ; } } else if ( candidate . accepts ( href ) ) { linkType = candidate ; break ; } } if ( linkType == null ) { // skip further processing if link type was not detected return ; } // workaround: strip off ".html" extension if it was added automatically by the RTE if ( linkType instanceof InternalLinkType || linkType instanceof MediaLinkType ) { String htmlSuffix = "." + FileExtension . HTML ; if ( StringUtils . endsWith ( href , htmlSuffix ) ) { href = StringUtils . substringBeforeLast ( href , htmlSuffix ) ; } } // store link reference (property depending on link type) resourceProps . put ( linkType . getPrimaryLinkRefProperty ( ) , href ) ; resourceProps . put ( LinkNameConstants . PN_LINK_WINDOW_TARGET , linkWindowTarget ) ; }
Support legacy data structures where link metadata is stored as JSON fragment in rel attribute .