idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
25,500 | void walkMap ( final Element elem , final KeyScope scope , final List < ResolveTask > res ) { List < KeyScope > ss = Collections . singletonList ( scope ) ; if ( elem . getAttributeNode ( ATTRIBUTE_NAME_KEYSCOPE ) != null ) { ss = new ArrayList < > ( ) ; for ( final String keyscope : elem . getAttribute ( ATTRIBUTE_NAME_KEYSCOPE ) . trim ( ) . split ( "\\s+" ) ) { final KeyScope s = scope . getChildScope ( keyscope ) ; assert s != null ; ss . add ( s ) ; } } Attr hrefNode = elem . getAttributeNode ( ATTRIBUTE_NAME_COPY_TO ) ; if ( hrefNode == null ) { hrefNode = elem . getAttributeNode ( ATTRIBUTE_NAME_HREF ) ; } if ( hrefNode == null && SUBMAP . matches ( elem ) ) { hrefNode = elem . getAttributeNode ( ATTRIBUTE_NAME_DITA_OT_ORIG_HREF ) ; } final boolean isResourceOnly = isResourceOnly ( elem ) ; for ( final KeyScope s : ss ) { if ( hrefNode != null ) { final URI href = stripFragment ( job . getInputMap ( ) . resolve ( hrefNode . getValue ( ) ) ) ; final FileInfo fi = job . getFileInfo ( href ) ; if ( fi != null && fi . hasKeyref ) { final int count = usage . getOrDefault ( fi . uri , 0 ) ; final Optional < ResolveTask > existing = res . stream ( ) . filter ( rt -> rt . scope . equals ( s ) && rt . in . uri . equals ( fi . uri ) ) . findAny ( ) ; if ( count != 0 && existing . isPresent ( ) ) { final ResolveTask resolveTask = existing . get ( ) ; if ( resolveTask . out != null ) { final URI value = tempFileNameScheme . generateTempFileName ( resolveTask . out . result ) ; hrefNode . setValue ( value . toString ( ) ) ; } } else { final ResolveTask resolveTask = processTopic ( fi , s , isResourceOnly ) ; res . add ( resolveTask ) ; final Integer used = usage . get ( fi . uri ) ; if ( used > 1 ) { final URI value = tempFileNameScheme . generateTempFileName ( resolveTask . out . result ) ; hrefNode . setValue ( value . toString ( ) ) ; } } } } for ( final Element child : getChildElements ( elem , MAP_TOPICREF ) ) { walkMap ( child , s , res ) ; } } } | Recursively walk map and process topics that have keyrefs . |
25,501 | private ResolveTask processTopic ( final FileInfo f , final KeyScope scope , final boolean isResourceOnly ) { final int increment = isResourceOnly ? 0 : 1 ; final Integer used = usage . containsKey ( f . uri ) ? usage . get ( f . uri ) + increment : increment ; usage . put ( f . uri , used ) ; if ( used > 1 ) { final URI result = addSuffix ( f . result , "-" + ( used - 1 ) ) ; final URI out = tempFileNameScheme . generateTempFileName ( result ) ; final FileInfo fo = new FileInfo . Builder ( f ) . uri ( out ) . result ( result ) . build ( ) ; job . add ( fo ) ; return new ResolveTask ( scope , f , fo ) ; } else { return new ResolveTask ( scope , f , null ) ; } } | Determine how topic is processed for key reference processing . |
25,502 | private void processFile ( final ResolveTask r ) { final List < XMLFilter > filters = new ArrayList < > ( ) ; final ConkeyrefFilter conkeyrefFilter = new ConkeyrefFilter ( ) ; conkeyrefFilter . setLogger ( logger ) ; conkeyrefFilter . setJob ( job ) ; conkeyrefFilter . setKeyDefinitions ( r . scope ) ; conkeyrefFilter . setCurrentFile ( job . tempDirURI . resolve ( r . in . uri ) ) ; conkeyrefFilter . setDelayConrefUtils ( delayConrefUtils ) ; filters . add ( conkeyrefFilter ) ; filters . add ( topicFragmentFilter ) ; final KeyrefPaser parser = new KeyrefPaser ( ) ; parser . setLogger ( logger ) ; parser . setJob ( job ) ; parser . setKeyDefinition ( r . scope ) ; parser . setCurrentFile ( job . tempDirURI . resolve ( r . in . uri ) ) ; filters . add ( parser ) ; try { logger . debug ( "Using " + ( r . scope . name != null ? r . scope . name + " scope" : "root scope" ) ) ; if ( r . out != null ) { logger . info ( "Processing " + job . tempDirURI . resolve ( r . in . uri ) + " to " + job . tempDirURI . resolve ( r . out . uri ) ) ; xmlUtils . transform ( new File ( job . tempDir , r . in . file . getPath ( ) ) , new File ( job . tempDir , r . out . file . getPath ( ) ) , filters ) ; } else { logger . info ( "Processing " + job . tempDirURI . resolve ( r . in . uri ) ) ; xmlUtils . transform ( new File ( job . tempDir , r . in . file . getPath ( ) ) , filters ) ; } normalProcessingRole . addAll ( parser . getNormalProcessingRoleTargets ( ) ) ; } catch ( final DITAOTException e ) { logger . error ( "Failed to process key references: " + e . getMessage ( ) , e ) ; } } | Process key references in a topic . Topic is stored with a new name if it s been processed before . |
25,503 | private void writeKeyDefinition ( final Map < String , KeyDef > keydefs ) { try { KeyDef . writeKeydef ( new File ( job . tempDir , KEYDEF_LIST_FILE ) , keydefs . values ( ) ) ; } catch ( final DITAOTException e ) { logger . error ( "Failed to write key definition file: " + e . getMessage ( ) , e ) ; } } | Add key definition to job configuration |
25,504 | public synchronized Map < String , Argument > getPluginArguments ( ) { if ( PLUGIN_ARGUMENTS == null ) { final List < Element > params = toList ( Plugins . getPluginConfiguration ( ) . getElementsByTagName ( "param" ) ) ; PLUGIN_ARGUMENTS = params . stream ( ) . map ( ArgumentParser :: getArgument ) . collect ( Collectors . toMap ( arg -> ( "--" + arg . property ) , arg -> arg , ArgumentParser :: mergeArguments ) ) ; } return PLUGIN_ARGUMENTS ; } | Lazy load parameters |
25,505 | private Map < String , Object > handleArgDefine ( final String arg , final Deque < String > args ) { final Map . Entry < String , String > entry = parse ( arg . substring ( 2 ) , args ) ; if ( entry . getValue ( ) == null ) { throw new BuildException ( "Missing value for property " + entry . getKey ( ) ) ; } if ( RESERVED_PROPERTIES . containsKey ( entry . getKey ( ) ) ) { throw new BuildException ( "Property " + entry . getKey ( ) + " cannot be set with -D, use " + RESERVED_PROPERTIES . get ( entry . getKey ( ) ) + " instead" ) ; } return ImmutableMap . of ( entry . getKey ( ) , entry . getValue ( ) ) ; } | Handler - D argument |
25,506 | private void handleArgInput ( final String arg , final Deque < String > args , final Argument argument ) { final Map . Entry < String , String > entry = parse ( arg , args ) ; if ( entry . getValue ( ) == null ) { throw new BuildException ( "Missing value for input " + entry . getKey ( ) ) ; } inputs . add ( argument . getValue ( ( String ) entry . getValue ( ) ) ) ; } | Handler input argument |
25,507 | private Map < String , Object > handleParameterArg ( final String arg , final Deque < String > args , final Argument argument ) { final Map . Entry < String , String > entry = parse ( arg , args ) ; if ( entry . getValue ( ) == null ) { throw new BuildException ( "Missing value for property " + entry . getKey ( ) ) ; } return ImmutableMap . of ( argument . property , argument . getValue ( entry . getValue ( ) ) ) ; } | Handler parameter argument |
25,508 | private String getArgumentName ( final String arg ) { int pos = arg . indexOf ( "=" ) ; if ( pos == - 1 ) { pos = arg . indexOf ( ":" ) ; } return arg . substring ( 0 , pos != - 1 ? pos : arg . length ( ) ) ; } | Get argument name |
25,509 | public void setCurrentFile ( final URI currentFile ) { assert currentFile . isAbsolute ( ) ; super . setCurrentFile ( currentFile ) ; currentDir = currentFile . resolve ( "." ) ; } | Set current file absolute path |
25,510 | private void parseAttribute ( final Attributes atts ) { final URI attrValue = toURI ( atts . getValue ( ATTRIBUTE_NAME_HREF ) ) ; if ( attrValue == null ) { return ; } final String attrScope = atts . getValue ( ATTRIBUTE_NAME_SCOPE ) ; if ( isExternal ( attrValue , attrScope ) ) { return ; } String attrFormat = atts . getValue ( ATTRIBUTE_NAME_FORMAT ) ; if ( attrFormat == null || ATTR_FORMAT_VALUE_DITA . equals ( attrFormat ) ) { final File target = toFile ( attrValue ) ; topicHref = target . isAbsolute ( ) ? attrValue : currentDir . resolve ( attrValue ) ; if ( attrValue . getFragment ( ) != null ) { topicId = attrValue . getFragment ( ) ; } else { if ( attrFormat == null || attrFormat . equals ( ATTR_FORMAT_VALUE_DITA ) || attrFormat . equals ( ATTR_FORMAT_VALUE_DITAMAP ) ) { topicId = topicHref + QUESTION ; } } } else { topicHref = null ; topicId = null ; } } | Parse the href attribute for needed information . |
25,511 | private void processParseResult ( final URI currentFile ) { for ( final Reference file : listFilter . getNonCopytoResult ( ) ) { categorizeReferenceFile ( file ) ; updateUplevels ( file . filename ) ; } for ( final Map . Entry < URI , URI > e : listFilter . getCopytoMap ( ) . entrySet ( ) ) { final URI source = e . getValue ( ) ; final URI target = e . getKey ( ) ; copyTo . put ( target , source ) ; updateUplevels ( target ) ; } schemeSet . addAll ( listFilter . getSchemeRefSet ( ) ) ; for ( final Map . Entry < String , KeyDef > e : keydefFilter . getKeysDMap ( ) . entrySet ( ) ) { final String key = e . getKey ( ) ; final KeyDef value = e . getValue ( ) ; if ( schemeSet . contains ( currentFile ) ) { schemekeydefMap . put ( key , new KeyDef ( key , value . href , value . scope , value . format , currentFile , null ) ) ; } } hrefTargetSet . addAll ( listFilter . getHrefTargets ( ) ) ; conrefTargetSet . addAll ( listFilter . getConrefTargets ( ) ) ; nonConrefCopytoTargetSet . addAll ( listFilter . getNonConrefCopytoTargets ( ) ) ; coderefTargetSet . addAll ( listFilter . getCoderefTargets ( ) ) ; outDitaFilesSet . addAll ( listFilter . getOutFilesSet ( ) ) ; final Set < URI > schemeSet = listFilter . getSchemeSet ( ) ; if ( schemeSet != null && ! schemeSet . isEmpty ( ) ) { Set < URI > children = schemeDictionary . get ( currentFile ) ; if ( children == null ) { children = new HashSet < > ( ) ; } children . addAll ( schemeSet ) ; schemeDictionary . put ( currentFile , children ) ; final Set < URI > hrfSet = listFilter . getHrefTargets ( ) ; for ( final URI filename : hrfSet ) { children = schemeDictionary . get ( filename ) ; if ( children == null ) { children = new HashSet < > ( ) ; } children . addAll ( schemeSet ) ; schemeDictionary . put ( filename , children ) ; } } } | Process results from parsing a single topic or map |
25,512 | private void categorizeReferenceFile ( final Reference file ) { if ( listFilter . getCoderefTargets ( ) . contains ( file . filename ) ) { return ; } if ( isFormatDita ( file . format ) && listFilter . isDitaTopic ( ) && ! job . crawlTopics ( ) && ! listFilter . getConrefTargets ( ) . contains ( file . filename ) ) { return ; } else if ( ( isFormatDita ( file . format ) || ATTR_FORMAT_VALUE_DITAMAP . equals ( file . format ) ) ) { addToWaitList ( file ) ; } else if ( ATTR_FORMAT_VALUE_IMAGE . equals ( file . format ) ) { formatSet . add ( file ) ; if ( ! exists ( file . filename ) ) { logger . warn ( MessageUtils . getMessage ( "DOTX008E" , file . filename . toString ( ) ) . toString ( ) ) ; } } else if ( ATTR_FORMAT_VALUE_DITAVAL . equals ( file . format ) ) { formatSet . add ( file ) ; } else { htmlSet . put ( file . format , file . filename ) ; } } | Categorize file . |
25,513 | private String getLevelsPath ( final URI rootTemp ) { final int u = rootTemp . toString ( ) . split ( URI_SEPARATOR ) . length - 1 ; if ( u == 0 ) { return "" ; } final StringBuilder buff = new StringBuilder ( ) ; for ( int current = u ; current > 0 ; current -- ) { buff . append ( ".." ) . append ( File . separator ) ; } return buff . toString ( ) ; } | Get up - levels absolute path . |
25,514 | private Map < URI , URI > filterConflictingCopyTo ( final Map < URI , URI > copyTo , final Collection < FileInfo > fileInfos ) { final Set < URI > fileinfoTargets = fileInfos . stream ( ) . filter ( fi -> fi . src . equals ( fi . result ) ) . map ( fi -> fi . result ) . collect ( Collectors . toSet ( ) ) ; return copyTo . entrySet ( ) . stream ( ) . filter ( e -> ! fileinfoTargets . contains ( e . getKey ( ) ) ) . collect ( Collectors . toMap ( Map . Entry :: getKey , Map . Entry :: getValue ) ) ; } | Filter copy - to where target is used directly . |
25,515 | private void writeListFile ( final File inputfile , final String relativeRootFile ) { try ( Writer bufferedWriter = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( inputfile ) ) ) ) { bufferedWriter . write ( relativeRootFile ) ; bufferedWriter . flush ( ) ; } catch ( final IOException e ) { logger . error ( e . getMessage ( ) , e ) ; } } | Write list file . |
25,516 | private String getPrefix ( final File relativeRootFile ) { String res ; final File p = relativeRootFile . getParentFile ( ) ; if ( p != null ) { res = p . toString ( ) + File . separator ; } else { res = "" ; } return res ; } | Prefix path . |
25,517 | private Map < URI , Set < URI > > addMapFilePrefix ( final Map < URI , Set < URI > > map ) { final Map < URI , Set < URI > > res = new HashMap < > ( ) ; for ( final Map . Entry < URI , Set < URI > > e : map . entrySet ( ) ) { final URI key = e . getKey ( ) ; final Set < URI > newSet = new HashSet < > ( e . getValue ( ) . size ( ) ) ; for ( final URI file : e . getValue ( ) ) { newSet . add ( tempFileNameScheme . generateTempFileName ( file ) ) ; } res . put ( key . equals ( ROOT_URI ) ? key : tempFileNameScheme . generateTempFileName ( key ) , newSet ) ; } return res ; } | Convert absolute paths to relative temporary directory paths |
25,518 | private Map < URI , URI > addFilePrefix ( final Map < URI , URI > set ) { final Map < URI , URI > newSet = new HashMap < > ( ) ; for ( final Map . Entry < URI , URI > file : set . entrySet ( ) ) { final URI key = tempFileNameScheme . generateTempFileName ( file . getKey ( ) ) ; final URI value = tempFileNameScheme . generateTempFileName ( file . getValue ( ) ) ; newSet . put ( key , value ) ; } return newSet ; } | Add file prefix . For absolute paths the prefix is not added . |
25,519 | private void addFlagImagesSetToProperties ( final Job prop , final Set < URI > set ) { final Set < URI > newSet = new LinkedHashSet < > ( 128 ) ; for ( final URI file : set ) { if ( file . isAbsolute ( ) ) { newSet . add ( file . normalize ( ) ) ; } else { newSet . add ( file . normalize ( ) ) ; } } final String fileKey = org . dita . dost . util . Constants . REL_FLAGIMAGE_LIST . substring ( 0 , org . dita . dost . util . Constants . REL_FLAGIMAGE_LIST . lastIndexOf ( "list" ) ) + "file" ; prop . setProperty ( fileKey , org . dita . dost . util . Constants . REL_FLAGIMAGE_LIST . substring ( 0 , org . dita . dost . util . Constants . REL_FLAGIMAGE_LIST . lastIndexOf ( "list" ) ) + ".list" ) ; final File list = new File ( job . tempDir , prop . getProperty ( fileKey ) ) ; try ( Writer bufferedWriter = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( list ) ) ) ) { final Iterator < URI > it = newSet . iterator ( ) ; while ( it . hasNext ( ) ) { bufferedWriter . write ( it . next ( ) . getPath ( ) ) ; if ( it . hasNext ( ) ) { bufferedWriter . write ( "\n" ) ; } } bufferedWriter . flush ( ) ; } catch ( final IOException e ) { logger . error ( e . getMessage ( ) , e ) ; } prop . setProperty ( org . dita . dost . util . Constants . REL_FLAGIMAGE_LIST , StringUtils . join ( newSet , COMMA ) ) ; } | add FlagImangesSet to Properties which needn t to change the dir level just ouput to the ouput dir . |
25,520 | XMLReader getXmlReader ( final String format ) throws SAXException { if ( format == null || format . equals ( ATTR_FORMAT_VALUE_DITA ) ) { return reader ; } for ( final Map . Entry < String , String > e : parserMap . entrySet ( ) ) { if ( format . equals ( e . getKey ( ) ) ) { try { final XMLReader r = ( XMLReader ) Class . forName ( e . getValue ( ) ) . newInstance ( ) ; final Map < String , Boolean > features = parserFeatures . getOrDefault ( e . getKey ( ) , emptyMap ( ) ) ; for ( final Map . Entry < String , Boolean > feature : features . entrySet ( ) ) { try { r . setFeature ( feature . getKey ( ) , feature . getValue ( ) ) ; } catch ( final SAXNotRecognizedException ex ) { } } return r ; } catch ( final InstantiationException | ClassNotFoundException | IllegalAccessException ex ) { throw new SAXException ( ex ) ; } } } return reader ; } | Get reader for input format |
25,521 | void initXmlReader ( ) throws SAXException { if ( parserMap . containsKey ( ATTR_FORMAT_VALUE_DITA ) ) { reader = XMLReaderFactory . createXMLReader ( parserMap . get ( ATTR_FORMAT_VALUE_DITA ) ) ; final Map < String , Boolean > features = parserFeatures . getOrDefault ( ATTR_FORMAT_VALUE_DITA , emptyMap ( ) ) ; for ( final Map . Entry < String , Boolean > feature : features . entrySet ( ) ) { try { reader . setFeature ( feature . getKey ( ) , feature . getValue ( ) ) ; } catch ( final SAXNotRecognizedException e ) { } } } else { reader = XMLUtils . getXMLReader ( ) ; } reader . setFeature ( FEATURE_NAMESPACE_PREFIX , true ) ; if ( validate ) { reader . setFeature ( FEATURE_VALIDATION , true ) ; try { reader . setFeature ( FEATURE_VALIDATION_SCHEMA , true ) ; } catch ( final SAXNotRecognizedException e ) { } } if ( gramcache ) { final XMLGrammarPool grammarPool = GrammarPoolManager . getGrammarPool ( ) ; try { reader . setProperty ( FEATURE_GRAMMAR_POOL , grammarPool ) ; logger . info ( "Using Xerces grammar pool for DTD and schema caching." ) ; } catch ( final NoClassDefFoundError e ) { logger . debug ( "Xerces not available, not using grammar caching" ) ; } catch ( final SAXNotRecognizedException | SAXNotSupportedException e ) { logger . warn ( "Failed to set Xerces grammar pool for parser: " + e . getMessage ( ) ) ; } } CatalogUtils . setDitaDir ( ditaDir ) ; reader . setEntityResolver ( CatalogUtils . getCatalogResolver ( ) ) ; } | XML reader used for pipeline parsing DITA documents . |
25,522 | private Element migrate ( Element root ) { if ( root . getAttributeNode ( PLUGIN_VERSION_ATTR ) == null ) { final List < Element > features = toList ( root . getElementsByTagName ( FEATURE_ELEM ) ) ; final String version = features . stream ( ) . filter ( elem -> elem . getAttribute ( FEATURE_ID_ATTR ) . equals ( "package.version" ) ) . findFirst ( ) . map ( elem -> elem . getAttribute ( FEATURE_VALUE_ATTR ) ) . orElse ( "0.0.0" ) ; root . setAttribute ( PLUGIN_VERSION_ATTR , version ) ; } return root ; } | Migrate from deprecated plugin format to new format |
25,523 | private void addExtensionPoint ( final Element elem ) { final String id = elem . getAttribute ( EXTENSION_POINT_ID_ATTR ) ; if ( id == null ) { throw new IllegalArgumentException ( EXTENSION_POINT_ID_ATTR + " attribute not set on extension-point" ) ; } final String name = elem . getAttribute ( EXTENSION_POINT_NAME_ATTR ) ; features . addExtensionPoint ( new ExtensionPoint ( id , name , currentPlugin ) ) ; } | Add extension point . |
25,524 | private void domToSax ( final Node root ) throws SAXException { try { final Result result = new SAXResult ( new FilterHandler ( getContentHandler ( ) ) ) ; final NodeList children = root . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { final Node links = rewriteLinks ( ( Element ) children . item ( i ) ) ; final Source source = new DOMSource ( links ) ; saxToDomTransformer . transform ( source , result ) ; } } catch ( TransformerException e ) { throw new SAXException ( "Failed to serialize DOM node to SAX: " + e . getMessage ( ) , e ) ; } } | DOM to SAX conversion methods |
25,525 | private void onStartElement ( QName name , XMLAttributes atts ) { if ( detecting ) { detecting = false ; loadDefaults ( ) ; } if ( defaults != null ) { checkAndAddDefaults ( name , atts ) ; } } | On start element |
25,526 | private boolean nullOrValue ( String test , String value ) { if ( test == null ) return true ; if ( test . equals ( value ) ) return true ; return false ; } | Test if a string is either null or equal to a certain value |
25,527 | private String getFromPIDataPseudoAttribute ( String data , String name , boolean unescapeValue ) { int pos = 0 ; while ( pos <= data . length ( ) - 4 ) { int nextQuote = - 1 ; for ( int q = pos ; q < data . length ( ) ; q ++ ) { if ( data . charAt ( q ) == '"' || data . charAt ( q ) == '\'' ) { nextQuote = q ; break ; } } if ( nextQuote < 0 ) { return null ; } int closingQuote = data . indexOf ( data . charAt ( nextQuote ) , nextQuote + 1 ) ; if ( closingQuote < 0 ) { return null ; } int nextName = data . indexOf ( name , pos ) ; if ( nextName < 0 ) { return null ; } if ( nextName < nextQuote ) { boolean found = true ; for ( int s = nextName + name . length ( ) ; s < nextQuote ; s ++ ) { char c = data . charAt ( s ) ; if ( ! Character . isWhitespace ( c ) && c != '=' ) { found = false ; break ; } } if ( found ) { String val = data . substring ( nextQuote + 1 , closingQuote ) ; return unescapeValue ? unescape ( val ) : val ; } } pos = closingQuote + 1 ; } return null ; } | This method is copied from com . icl . saxon . ProcInstParser and used in the PIFinder . |
25,528 | private String unescape ( String value ) { if ( value . indexOf ( '&' ) < 0 ) { return value ; } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < value . length ( ) ; i ++ ) { char c = value . charAt ( i ) ; if ( c == '&' ) { if ( i + 2 < value . length ( ) && value . charAt ( i + 1 ) == '#' ) { if ( value . charAt ( i + 2 ) == 'x' ) { int x = i + 3 ; int charval = 0 ; while ( x < value . length ( ) && value . charAt ( x ) != ';' ) { int digit = "0123456789abcdef" . indexOf ( value . charAt ( x ) ) ; if ( digit < 0 ) { digit = "0123456789ABCDEF" . indexOf ( value . charAt ( x ) ) ; } if ( digit < 0 ) { return null ; } charval = charval * 16 + digit ; x ++ ; } char hexchar = ( char ) charval ; sb . append ( hexchar ) ; i = x ; } else { int x = i + 2 ; int charval = 0 ; while ( x < value . length ( ) && value . charAt ( x ) != ';' ) { int digit = "0123456789" . indexOf ( value . charAt ( x ) ) ; if ( digit < 0 ) { return null ; } charval = charval * 10 + digit ; x ++ ; } char decchar = ( char ) charval ; sb . append ( decchar ) ; i = x ; } } else if ( value . substring ( i + 1 ) . startsWith ( "lt;" ) ) { sb . append ( '<' ) ; i += 3 ; } else if ( value . substring ( i + 1 ) . startsWith ( "gt;" ) ) { sb . append ( '>' ) ; i += 3 ; } else if ( value . substring ( i + 1 ) . startsWith ( "amp;" ) ) { sb . append ( '&' ) ; i += 4 ; } else if ( value . substring ( i + 1 ) . startsWith ( "quot;" ) ) { sb . append ( '"' ) ; i += 5 ; } else if ( value . substring ( i + 1 ) . startsWith ( "apos;" ) ) { sb . append ( '\'' ) ; i += 5 ; } else { return null ; } } else { sb . append ( c ) ; } } return sb . toString ( ) ; } | This method is copied from com . icl . saxon . ProcInstParser and used in the PIFinder |
25,529 | public void setProperty ( String propertyId , Object value ) throws XMLConfigurationException { if ( propertyId . startsWith ( Constants . XERCES_PROPERTY_PREFIX ) ) { final int suffixLength = propertyId . length ( ) - Constants . XERCES_PROPERTY_PREFIX . length ( ) ; if ( suffixLength == Constants . SYMBOL_TABLE_PROPERTY . length ( ) && propertyId . endsWith ( Constants . SYMBOL_TABLE_PROPERTY ) ) { fSymbolTable = ( SymbolTable ) value ; } else if ( suffixLength == Constants . ENTITY_RESOLVER_PROPERTY . length ( ) && propertyId . endsWith ( Constants . ENTITY_RESOLVER_PROPERTY ) ) { fResolver = ( XMLEntityResolver ) value ; } } } | Sets the value of a property during parsing . |
25,530 | public void write ( final File filename ) throws DITAOTException { assert filename . isAbsolute ( ) ; super . write ( new File ( currentFile ) ) ; } | Process key references . |
25,531 | private void writeAlt ( Element srcElem ) throws SAXException { final AttributesImpl atts = new AttributesImpl ( ) ; XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_CLASS , TOPIC_ALT . toString ( ) ) ; getContentHandler ( ) . startElement ( NULL_NS_URI , TOPIC_ALT . localName , TOPIC_ALT . localName , atts ) ; domToSax ( srcElem , false ) ; getContentHandler ( ) . endElement ( NULL_NS_URI , TOPIC_ALT . localName , TOPIC_ALT . localName ) ; } | Write alt element |
25,532 | private boolean fallbackToNavtitleOrHref ( final Element elem ) { final String hrefValue = elem . getAttribute ( ATTRIBUTE_NAME_HREF ) ; final String locktitleValue = elem . getAttribute ( ATTRIBUTE_NAME_LOCKTITLE ) ; return ( ( ATTRIBUTE_NAME_LOCKTITLE_VALUE_YES . equals ( locktitleValue ) ) || ( "" . equals ( hrefValue ) ) || ! ( isLocalDita ( elem ) ) ) ; } | Return true when keyref text resolution should use navtitle as a final fallback . |
25,533 | private void domToSax ( final Element elem , final boolean retainElements , final boolean swapMapClass ) throws SAXException { if ( retainElements ) { final AttributesImpl atts = new AttributesImpl ( ) ; final NamedNodeMap attrs = elem . getAttributes ( ) ; for ( int i = 0 ; i < attrs . getLength ( ) ; i ++ ) { final Attr a = ( Attr ) attrs . item ( i ) ; if ( a . getNodeName ( ) . equals ( ATTRIBUTE_NAME_CLASS ) && swapMapClass ) { XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_CLASS , changeclassValue ( a . getNodeValue ( ) ) ) ; } else { XMLUtils . addOrSetAttribute ( atts , a ) ; } } getContentHandler ( ) . startElement ( NULL_NS_URI , elem . getNodeName ( ) , elem . getNodeName ( ) , atts ) ; } final NodeList nodeList = elem . getChildNodes ( ) ; for ( int i = 0 ; i < nodeList . getLength ( ) ; i ++ ) { final Node node = nodeList . item ( i ) ; if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { final Element e = ( Element ) node ; if ( TOPIC_TM . matches ( e ) || TOPIC_TEXT . matches ( e ) ) { domToSax ( e , true , swapMapClass ) ; } else { domToSax ( e , retainElements , swapMapClass ) ; } } else if ( node . getNodeType ( ) == Node . TEXT_NODE ) { final char [ ] ch = node . getNodeValue ( ) . toCharArray ( ) ; getContentHandler ( ) . characters ( ch , 0 , ch . length ) ; } } if ( retainElements ) { getContentHandler ( ) . endElement ( NULL_NS_URI , elem . getNodeName ( ) , elem . getNodeName ( ) ) ; } } | Serialize DOM node into a SAX stream . |
25,534 | private String changeclassValue ( final String classValue ) { final DitaClass cls = new DitaClass ( classValue ) ; if ( cls . equals ( MAP_LINKTEXT ) ) { return TOPIC_LINKTEXT . toString ( ) ; } else if ( cls . equals ( MAP_SEARCHTITLE ) ) { return TOPIC_SEARCHTITLE . toString ( ) ; } else if ( cls . equals ( MAP_SHORTDESC ) ) { return TOPIC_SHORTDESC . toString ( ) ; } else { return cls . toString ( ) ; } } | Change map type to topic type . |
25,535 | private static URI normalizeHrefValue ( final URI keyName , final String tail ) { if ( keyName . getFragment ( ) == null ) { return toURI ( keyName + tail . replaceAll ( SLASH , SHARP ) ) ; } return toURI ( keyName + tail ) ; } | change elementId into topicId if there is no topicId in key definition . |
25,536 | private static URI normalizeHrefValue ( final URI fileName , final String tail , final String topicId ) { if ( fileName . getFragment ( ) == null && ! "" . equals ( tail ) ) { return setFragment ( fileName , topicId + tail ) ; } return toURI ( fileName + tail ) ; } | Insert topic id into href |
25,537 | private Range getRange ( final URI uri ) { int start = 0 ; int end = Integer . MAX_VALUE ; String startId = null ; String endId = null ; final String fragment = uri . getFragment ( ) ; if ( fragment != null ) { final Matcher m = Pattern . compile ( "^line=(?:(\\d+)|(\\d+)?,(\\d+)?)$" ) . matcher ( fragment ) ; if ( m . matches ( ) ) { if ( m . group ( 1 ) != null ) { start = Integer . parseInt ( m . group ( 1 ) ) ; end = start ; } else { if ( m . group ( 2 ) != null ) { start = Integer . parseInt ( m . group ( 2 ) ) ; } if ( m . group ( 3 ) != null ) { end = Integer . parseInt ( m . group ( 3 ) ) - 1 ; } } return new LineNumberRange ( start , end ) . handler ( this ) ; } else { final Matcher mc = Pattern . compile ( "^line-range\\((\\d+)(?:,\\s*(\\d+))?\\)$" ) . matcher ( fragment ) ; if ( mc . matches ( ) ) { start = Integer . parseInt ( mc . group ( 1 ) ) - 1 ; if ( mc . group ( 2 ) != null ) { end = Integer . parseInt ( mc . group ( 2 ) ) - 1 ; } return new LineNumberRange ( start , end ) . handler ( this ) ; } else { final Matcher mi = Pattern . compile ( "^token=([^,\\s)]*)(?:,\\s*([^,\\s)]+))?$" ) . matcher ( fragment ) ; if ( mi . matches ( ) ) { if ( mi . group ( 1 ) != null && mi . group ( 1 ) . length ( ) != 0 ) { startId = mi . group ( 1 ) ; } if ( mi . group ( 2 ) != null ) { endId = mi . group ( 2 ) ; } return new AnchorRange ( startId , endId ) . handler ( this ) ; } } } } return new AllRange ( ) . handler ( this ) ; } | Factory method for Range implementation |
25,538 | private Charset getCharset ( final String value ) { Charset c = null ; if ( value != null ) { final String [ ] tokens = value . trim ( ) . split ( "[;=]" ) ; if ( tokens . length >= 3 && tokens [ 1 ] . trim ( ) . equals ( "charset" ) ) { try { c = Charset . forName ( tokens [ 2 ] . trim ( ) ) ; } catch ( final RuntimeException e ) { logger . error ( MessageUtils . getMessage ( "DOTJ052E" , tokens [ 2 ] . trim ( ) ) . toString ( ) ) ; } } } if ( c == null ) { final String defaultCharset = Configuration . configuration . get ( "default.coderef-charset" ) ; if ( defaultCharset != null ) { c = Charset . forName ( defaultCharset ) ; } else { c = Charset . defaultCharset ( ) ; } } return c ; } | Get code file charset . |
25,539 | public boolean needExclude ( final Attributes atts , final QName [ ] [ ] extProps ) { if ( filterMap . isEmpty ( ) ) { return false ; } for ( final QName attr : filterAttributes ) { final String value = atts . getValue ( attr . getNamespaceURI ( ) , attr . getLocalPart ( ) ) ; if ( value != null ) { final Map < QName , List < String > > groups = getGroups ( value ) ; for ( Map . Entry < QName , List < String > > group : groups . entrySet ( ) ) { final QName [ ] propList = group . getKey ( ) != null ? new QName [ ] { attr , group . getKey ( ) } : new QName [ ] { attr } ; if ( extCheckExclude ( propList , group . getValue ( ) ) ) { return true ; } } } } if ( extProps != null && extProps . length != 0 ) { for ( final QName [ ] propList : extProps ) { int propListIndex = propList . length - 1 ; final QName propName = propList [ propListIndex ] ; String propValue = atts . getValue ( propName . getNamespaceURI ( ) , propName . getLocalPart ( ) ) ; while ( ( propValue == null || propValue . trim ( ) . isEmpty ( ) ) && propListIndex > 0 ) { propListIndex -- ; final QName current = propList [ propListIndex ] ; propValue = getLabelValue ( propName , atts . getValue ( current . getNamespaceURI ( ) , current . getLocalPart ( ) ) ) ; } if ( propValue != null && extCheckExclude ( propList , Arrays . asList ( propValue . split ( "\\s+" ) ) ) ) { return true ; } } } return false ; } | Check if the given Attributes need to be excluded . |
25,540 | private String getLabelValue ( final QName propName , final String attrPropsValue ) { if ( attrPropsValue != null ) { int propStart = - 1 ; if ( attrPropsValue . startsWith ( propName + "(" ) || attrPropsValue . contains ( " " + propName + "(" ) ) { propStart = attrPropsValue . indexOf ( propName + "(" ) ; } if ( propStart != - 1 ) { propStart = propStart + propName . toString ( ) . length ( ) + 1 ; } final int propEnd = attrPropsValue . indexOf ( ")" , propStart ) ; if ( propStart != - 1 && propEnd != - 1 ) { return attrPropsValue . substring ( propStart , propEnd ) . trim ( ) ; } } return null ; } | Get labelled props value . |
25,541 | private void checkRuleMapping ( final QName attName , final List < String > attValue ) { if ( attValue == null || attValue . isEmpty ( ) ) { return ; } for ( final String attSubValue : attValue ) { final FilterKey filterKey = new FilterKey ( attName , attSubValue ) ; final Action filterAction = filterMap . get ( filterKey ) ; if ( filterAction == null && logMissingAction ) { if ( ! alreadyShowed ( filterKey ) ) { logger . info ( MessageUtils . getMessage ( "DOTJ031I" , filterKey . toString ( ) ) . toString ( ) ) ; } } } } | Check if attribute value has mapping in filter configuration and throw messages . |
25,542 | private FilterUtils refine ( final Map < QName , Map < String , Set < Element > > > bindingMap ) { if ( bindingMap != null && ! bindingMap . isEmpty ( ) ) { final Map < FilterKey , Action > buf = new HashMap < > ( filterMap ) ; for ( final Map . Entry < FilterKey , Action > e : filterMap . entrySet ( ) ) { refineAction ( e . getValue ( ) , e . getKey ( ) , bindingMap , buf ) ; } final FilterUtils filterUtils = new FilterUtils ( buf , foregroundConflictColor , backgroundConflictColor ) ; filterUtils . setLogger ( logger ) ; filterUtils . logMissingAction = logMissingAction ; return filterUtils ; } else { return this ; } } | Refine filter with subject scheme . |
25,543 | public static boolean isFormatDita ( final String attrFormat ) { if ( attrFormat == null || attrFormat . equals ( ATTR_FORMAT_VALUE_DITA ) ) { return true ; } for ( final String f : ditaFormat ) { if ( f . equals ( attrFormat ) ) { return true ; } } return false ; } | Check if format is DITA topic . |
25,544 | public void buildFinished ( final BuildEvent event ) { final Throwable error = event . getException ( ) ; final StringBuilder message = new StringBuilder ( ) ; if ( error == null ) { } else { message . append ( "Error: " ) ; throwableMessage ( message , error , Project . MSG_VERBOSE <= msgOutputLevel ) ; } final String msg = message . toString ( ) ; if ( error == null && ! msg . trim ( ) . isEmpty ( ) ) { printMessage ( msg , out , Project . MSG_VERBOSE ) ; } else if ( ! msg . isEmpty ( ) ) { printMessage ( msg , err , Project . MSG_ERR ) ; } log ( msg ) ; } | Prints whether the build succeeded or failed any errors the occurred during the build and how long the build took . |
25,545 | public void targetStarted ( final BuildEvent event ) { if ( Project . MSG_INFO <= msgOutputLevel && ! event . getTarget ( ) . getName ( ) . equals ( "" ) ) { final String msg = StringUtils . LINE_SEP + event . getTarget ( ) . getName ( ) + ":" ; printMessage ( msg , out , event . getPriority ( ) ) ; log ( msg ) ; } } | Logs a message to say that the target has started if this logger allows information - level messages . |
25,546 | public void messageLogged ( final BuildEvent event ) { final int priority = event . getPriority ( ) ; if ( priority <= msgOutputLevel ) { final StringBuilder message = new StringBuilder ( ) ; if ( event . getTask ( ) != null && ! emacsMode ) { final String name = event . getTask ( ) . getTaskName ( ) ; String label = "[" + name + "] " ; final int size = LEFT_COLUMN_SIZE - label . length ( ) ; final StringBuilder tmp = new StringBuilder ( ) ; for ( int i = 0 ; i < size ; i ++ ) { tmp . append ( " " ) ; } tmp . append ( label ) ; label = tmp . toString ( ) ; BufferedReader r = null ; try { r = new BufferedReader ( new StringReader ( event . getMessage ( ) ) ) ; String line = r . readLine ( ) ; boolean first = true ; do { if ( first ) { if ( line == null ) { message . append ( label ) ; break ; } } else { message . append ( StringUtils . LINE_SEP ) ; } first = false ; message . append ( label ) . append ( line ) ; line = r . readLine ( ) ; } while ( line != null ) ; } catch ( final IOException e ) { message . append ( label ) . append ( event . getMessage ( ) ) ; } finally { if ( r != null ) { FileUtils . close ( r ) ; } } } else { message . append ( event . getMessage ( ) ) ; } final Throwable ex = event . getException ( ) ; if ( Project . MSG_DEBUG <= msgOutputLevel && ex != null ) { message . append ( StringUtils . getStackTrace ( ex ) ) ; } final String msg = message . toString ( ) ; if ( priority != Project . MSG_ERR ) { printMessage ( msg , out , priority ) ; } else { printMessage ( msg , err , priority ) ; } log ( msg ) ; } } | Logs a message if the priority is suitable . In non - emacs mode task level messages are prefixed by the task name which is right - justified . |
25,547 | private void printMessage ( final String message , final PrintStream stream , final int priority ) { if ( useColor && priority == Project . MSG_ERR ) { stream . print ( ANSI_RED ) ; stream . print ( message ) ; stream . println ( ANSI_RESET ) ; } else { stream . println ( message ) ; } } | Prints a message to a PrintStream . |
25,548 | protected String getTimestamp ( ) { final Date date = new Date ( System . currentTimeMillis ( ) ) ; final DateFormat formatter = DateFormat . getDateTimeInstance ( DateFormat . SHORT , DateFormat . SHORT ) ; return formatter . format ( date ) ; } | Get the current time . |
25,549 | protected String extractProjectName ( final BuildEvent event ) { final Project project = event . getProject ( ) ; return ( project != null ) ? project . getName ( ) : null ; } | Get the project name or null |
25,550 | public void setup ( final Map < URI , URI > conflictTable ) { for ( final Map . Entry < URI , URI > e : changeTable . entrySet ( ) ) { assert e . getKey ( ) . isAbsolute ( ) ; assert e . getValue ( ) . isAbsolute ( ) ; } this . conflictTable = conflictTable ; } | Set up class . |
25,551 | private boolean isLocalDita ( final Attributes atts ) { final String classValue = atts . getValue ( ATTRIBUTE_NAME_CLASS ) ; if ( classValue == null || ( TOPIC_IMAGE . matches ( classValue ) ) ) { return false ; } String scopeValue = atts . getValue ( ATTRIBUTE_NAME_SCOPE ) ; if ( scopeValue == null ) { scopeValue = ATTR_SCOPE_VALUE_LOCAL ; } String formatValue = atts . getValue ( ATTRIBUTE_NAME_FORMAT ) ; if ( formatValue == null ) { formatValue = ATTR_FORMAT_VALUE_DITA ; } return scopeValue . equals ( ATTR_SCOPE_VALUE_LOCAL ) && formatValue . equals ( ATTR_FORMAT_VALUE_DITA ) ; } | Check whether the attributes contains references |
25,552 | private String getElementID ( final String relativePath ) { final String fragment = getFragment ( relativePath ) ; if ( fragment != null ) { if ( fragment . lastIndexOf ( SLASH ) != - 1 ) { return fragment . substring ( fragment . lastIndexOf ( SLASH ) + 1 ) ; } else { return fragment ; } } return null ; } | Retrieve the element ID from the path . If there is no element ID return topic ID . |
25,553 | public static DITAOTCollator getInstance ( final Locale locale ) { if ( locale == null ) { throw new NullPointerException ( "Locale may not be null" ) ; } DITAOTCollator instance ; instance = cache . computeIfAbsent ( locale , DITAOTCollator :: new ) ; return instance ; } | Return the DITAOTCollator instance specifying Locale . |
25,554 | public int compare ( final Object source , final Object target ) { try { return ( Integer ) compareMethod . invoke ( collatorInstance , source , target ) ; } catch ( final Exception e ) { throw new RuntimeException ( e . getMessage ( ) , e ) ; } } | Comparing method required to compare . |
25,555 | public IndexPreprocessResult process ( final Document theInput ) throws ProcessException { final DocumentBuilder documentBuilder = XMLUtils . getDocumentBuilder ( ) ; final Document doc = documentBuilder . newDocument ( ) ; final Node rootElement = theInput . getDocumentElement ( ) ; final ArrayList < IndexEntry > indexes = new ArrayList < IndexEntry > ( ) ; final IndexEntryFoundListener listener = new IndexEntryFoundListener ( ) { public void foundEntry ( final IndexEntry theEntry ) { indexes . add ( theEntry ) ; } } ; final Node node = processCurrNode ( rootElement , doc , listener ) [ 0 ] ; doc . appendChild ( node ) ; doc . getDocumentElement ( ) . setAttribute ( XMLNS_ATTRIBUTE + ":" + this . prefix , this . namespace_url ) ; return new IndexPreprocessResult ( doc , ( IndexEntry [ ] ) indexes . toArray ( new IndexEntry [ 0 ] ) ) ; } | Process index terms . |
25,556 | private Node [ ] processCurrNode ( final Node theNode , final Document theTargetDocument , final IndexEntryFoundListener theIndexEntryFoundListener ) { final NodeList childNodes = theNode . getChildNodes ( ) ; if ( checkElementName ( theNode ) && ! excludedDraftSection . peek ( ) ) { return processIndexNode ( theNode , theTargetDocument , theIndexEntryFoundListener ) ; } else { final Node result = theTargetDocument . importNode ( theNode , false ) ; if ( ! includeDraft && checkDraftNode ( theNode ) ) { excludedDraftSection . add ( true ) ; } for ( int i = 0 ; i < childNodes . getLength ( ) ; i ++ ) { final Node [ ] processedNodes = processCurrNode ( childNodes . item ( i ) , theTargetDocument , theIndexEntryFoundListener ) ; for ( final Node node : processedNodes ) { result . appendChild ( node ) ; } } if ( ! includeDraft && checkDraftNode ( theNode ) ) { excludedDraftSection . pop ( ) ; } return new Node [ ] { result } ; } } | Processes curr node . Copies node to the target document if its is not a text node of index entry element . Otherwise it process it and creates nodes with prefix in given namespace_url from the parsed index entry text . |
25,557 | private boolean checkElementName ( final Node node ) { return TOPIC_INDEXTERM . matches ( node ) || INDEXING_D_INDEX_SORT_AS . matches ( node ) || INDEXING_D_INDEX_SEE . matches ( node ) || INDEXING_D_INDEX_SEE_ALSO . matches ( node ) ; } | Check if node is an index term element or specialization of one . |
25,558 | private Node [ ] processIndexString ( final String theIndexString , final List < Node > contents , final Document theTargetDocument , final IndexEntryFoundListener theIndexEntryFoundListener ) { final IndexEntry [ ] indexEntries = IndexStringProcessor . processIndexString ( theIndexString , contents ) ; for ( final IndexEntry indexEntrie : indexEntries ) { theIndexEntryFoundListener . foundEntry ( indexEntrie ) ; } return transformToNodes ( indexEntries , theTargetDocument , null ) ; } | Processes index string and creates nodes with prefix in given namespace_url from the parsed index entry text . |
25,559 | private Element createElement ( final Document theTargetDocument , final String theName ) { final Element indexEntryNode = theTargetDocument . createElementNS ( this . namespace_url , theName ) ; indexEntryNode . setPrefix ( this . prefix ) ; return indexEntryNode ; } | Creates element with prefix in namespace_url with given name for the target document |
25,560 | public Set < URI > getNonTopicrefReferenceSet ( ) { final Set < URI > res = new HashSet < > ( nonTopicrefReferenceSet ) ; res . removeAll ( normalProcessingRoleSet ) ; res . removeAll ( resourceOnlySet ) ; return res ; } | List of files referenced by something other than topicref |
25,561 | public Set < Reference > getNonCopytoResult ( ) { final Set < Reference > nonCopytoSet = new LinkedHashSet < > ( 128 ) ; nonCopytoSet . addAll ( nonConrefCopytoTargets ) ; for ( final URI f : conrefTargets ) { nonCopytoSet . add ( new Reference ( stripFragment ( f ) , currentFileFormat ( ) ) ) ; } for ( final URI f : copytoMap . values ( ) ) { nonCopytoSet . add ( new Reference ( stripFragment ( f ) ) ) ; } for ( final URI f : ignoredCopytoSourceSet ) { nonCopytoSet . add ( new Reference ( stripFragment ( f ) ) ) ; } for ( final URI filename : coderefTargetSet ) { nonCopytoSet . add ( new Reference ( stripFragment ( filename ) ) ) ; } return nonCopytoSet ; } | Get all targets except copy - to . |
25,562 | public Set < URI > getNonConrefCopytoTargets ( ) { final Set < URI > res = new HashSet < > ( nonConrefCopytoTargets . size ( ) ) ; for ( final Reference r : nonConrefCopytoTargets ) { res . add ( r . filename ) ; } return res ; } | Get non - conref and non - copyto targets . |
25,563 | public static boolean canFollow ( URI href ) { if ( href != null && href . getScheme ( ) != null && href . getScheme ( ) . equals ( "mailto" ) ) { return false ; } return true ; } | Make educated guess in advance whether URI can be resolved to a file . |
25,564 | private boolean isOutFile ( final URI toCheckPath ) { final String path = toCheckPath . getPath ( ) ; return ! ( path != null && path . startsWith ( rootDir . getPath ( ) ) ) ; } | Check if path walks up in parent directories |
25,565 | public void generate ( final File fileName ) { final File outputFile = removeTemplatePrefix ( fileName ) ; templateFile = fileName ; try ( final InputStream in = new BufferedInputStream ( new FileInputStream ( fileName ) ) ; final OutputStream out = new BufferedOutputStream ( new FileOutputStream ( outputFile ) ) ) { final Transformer transformer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; final SAXParserFactory parserFactory = SAXParserFactory . newInstance ( ) ; parserFactory . setNamespaceAware ( true ) ; XMLReader reader = parserFactory . newSAXParser ( ) . getXMLReader ( ) ; this . setContentHandler ( null ) ; this . setParent ( reader ) ; reader = this ; final Source source = new SAXSource ( reader , new InputSource ( in ) ) ; source . setSystemId ( fileName . toURI ( ) . toString ( ) ) ; final Result result = new StreamResult ( out ) ; transformer . transform ( source , result ) ; } catch ( final RuntimeException e ) { throw e ; } catch ( final Exception e ) { logger . error ( "Failed to transform " + fileName + ": " + e . getMessage ( ) , e ) ; } } | Generator the output file . |
25,566 | public void update ( InputSource in ) throws SAXException { defaultValuesCollector = null ; PropertyMapBuilder builder = new PropertyMapBuilder ( ) ; builder . put ( ValidateProperty . RESOLVER , resolver ) ; builder . put ( ValidateProperty . ERROR_HANDLER , eh ) ; PropertyMap properties = builder . toPropertyMap ( ) ; try { SchemaWrapper sw = ( SchemaWrapper ) getSchemaReader ( ) . createSchema ( in , properties ) ; Pattern start = sw . getStart ( ) ; defaultValuesCollector = new DefaultValuesCollector ( start ) ; } catch ( Exception e ) { eh . warning ( new SAXParseException ( "Error loading defaults: " + e . getMessage ( ) , null , e ) ) ; } catch ( StackOverflowError e ) { eh . warning ( new SAXParseException ( "Error loading defaults: " + e . getMessage ( ) , null , null ) ) ; } } | Updates the annotation model . |
25,567 | public List < Attribute > getDefaultAttributes ( String localName , String namespace ) { if ( defaultValuesCollector != null ) { return defaultValuesCollector . getDefaultAttributes ( localName , namespace ) ; } return null ; } | Get the default attributes for an element . |
25,568 | private void handleID ( final AttributesImpl atts ) { String idValue = atts . getValue ( ATTRIBUTE_NAME_ID ) ; if ( idValue != null ) { XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_OID , idValue ) ; final URI value = setFragment ( dirPath . toURI ( ) . resolve ( toURI ( filePath ) ) , idValue ) ; if ( util . findId ( value ) ) { idValue = util . getIdValue ( value ) ; } else { idValue = util . addId ( value ) ; } XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_ID , idValue ) ; } } | Get new value for topic id attribute . |
25,569 | private URI handleLocalDita ( final URI href , final AttributesImpl atts ) { final URI attValue = href ; final int sharpIndex = attValue . toString ( ) . indexOf ( SHARP ) ; URI pathFromMap ; URI retAttValue ; if ( sharpIndex != - 1 ) { if ( sharpIndex == 0 ) { pathFromMap = toURI ( filePath ) ; } else { pathFromMap = toURI ( filePath ) . resolve ( attValue . toString ( ) . substring ( 0 , sharpIndex ) ) ; } XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_OHREF , toURI ( pathFromMap + attValue . toString ( ) . substring ( sharpIndex ) ) . toString ( ) ) ; final String topicID = getTopicID ( attValue . getFragment ( ) ) ; final int index = attValue . toString ( ) . indexOf ( SLASH , sharpIndex ) ; final String elementId = index != - 1 ? attValue . toString ( ) . substring ( index ) : "" ; final URI pathWithTopicID = setFragment ( dirPath . toURI ( ) . resolve ( pathFromMap ) , topicID ) ; if ( util . findId ( pathWithTopicID ) ) { retAttValue = toURI ( SHARP + util . getIdValue ( pathWithTopicID ) + elementId ) ; } else { retAttValue = toURI ( SHARP + util . addId ( pathWithTopicID ) + elementId ) ; } } else { pathFromMap = toURI ( filePath ) . resolve ( attValue . toString ( ) ) ; URI absolutePath = dirPath . toURI ( ) . resolve ( pathFromMap ) ; XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_OHREF , pathFromMap . toString ( ) ) ; if ( util . findId ( absolutePath ) ) { retAttValue = toURI ( SHARP + util . getIdValue ( absolutePath ) ) ; } else { final String fileId = util . getFirstTopicId ( absolutePath , false ) ; final URI key = setFragment ( absolutePath , fileId ) ; if ( util . findId ( key ) ) { util . addId ( absolutePath , util . getIdValue ( key ) ) ; retAttValue = toURI ( SHARP + util . getIdValue ( key ) ) ; } else { retAttValue = toURI ( SHARP + util . addId ( absolutePath ) ) ; util . addId ( key , util . getIdValue ( absolutePath ) ) ; } } } return retAttValue ; } | Rewrite local DITA href value . |
25,570 | public void parse ( final String filename , final File dir ) { filePath = stripFragment ( filename ) ; dirPath = dir ; try { final File f = new File ( dir , filePath ) ; reader . setErrorHandler ( new DITAOTXMLErrorHandler ( f . getAbsolutePath ( ) , logger ) ) ; logger . info ( "Processing " + f . getAbsolutePath ( ) ) ; reader . parse ( f . toURI ( ) . toString ( ) ) ; } catch ( final RuntimeException e ) { throw e ; } catch ( final Exception e ) { throw new RuntimeException ( "Failed to parse " + filename + ": " + e . getMessage ( ) , e ) ; } } | Parse the file to update id . |
25,571 | private void handleHref ( final String classValue , final AttributesImpl atts ) { final URI attValue = toURI ( atts . getValue ( ATTRIBUTE_NAME_HREF ) ) ; if ( attValue != null ) { final String scopeValue = atts . getValue ( ATTRIBUTE_NAME_SCOPE ) ; if ( ( scopeValue == null || ATTR_SCOPE_VALUE_LOCAL . equals ( scopeValue ) ) && attValue . getScheme ( ) == null ) { final String formatValue = atts . getValue ( ATTRIBUTE_NAME_FORMAT ) ; if ( ( TOPIC_XREF . matches ( classValue ) || TOPIC_LINK . matches ( classValue ) || TOPIC_LQ . matches ( classValue ) || TOPIC_TERM . matches ( classValue ) || TOPIC_KEYWORD . matches ( classValue ) || TOPIC_CITE . matches ( classValue ) || TOPIC_PH . matches ( classValue ) || TOPIC_DT . matches ( classValue ) ) && ( formatValue == null || ATTR_FORMAT_VALUE_DITA . equals ( formatValue ) ) ) { XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_HREF , handleLocalDita ( attValue , atts ) . toString ( ) ) ; } else { XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_HREF , handleLocalHref ( attValue ) . toString ( ) ) ; } } } } | Rewrite href attribute . |
25,572 | private URI handleLocalHref ( final URI attValue ) { final URI current = new File ( dirPath , filePath ) . toURI ( ) . normalize ( ) ; final URI reference = current . resolve ( attValue ) ; final URI merge = output . toURI ( ) ; return getRelativePath ( merge , reference ) ; } | Rewrite local non - DITA href value . |
25,573 | public static void start ( final String [ ] args , final Properties additionalUserProperties , final ClassLoader coreLoader ) { final Main m = new Main ( ) ; m . startAnt ( args , additionalUserProperties , coreLoader ) ; } | Creates a new instance of this class using the arguments specified gives it any extra user properties which have been specified and then runs the build using the classloader provided . |
25,574 | private void handleLogfile ( ) { if ( args . logFile != null ) { FileUtils . close ( out ) ; FileUtils . close ( err ) ; } } | Close logfiles if we have been writing to them . |
25,575 | protected void addBuildListeners ( final Project project ) { project . addBuildListener ( createLogger ( ) ) ; final int count = args . listeners . size ( ) ; for ( int i = 0 ; i < count ; i ++ ) { final String className = args . listeners . elementAt ( i ) ; final BuildListener listener = ClasspathUtils . newInstance ( className , Main . class . getClassLoader ( ) , BuildListener . class ) ; project . setProjectReference ( listener ) ; project . addBuildListener ( listener ) ; } } | Adds the listeners specified in the command line arguments along with the default listener to the specified project . |
25,576 | private void addInputHandler ( final Project project ) throws BuildException { final InputHandler handler ; if ( args . inputHandlerClassname == null ) { handler = new DefaultInputHandler ( ) ; } else { handler = ClasspathUtils . newInstance ( args . inputHandlerClassname , Main . class . getClassLoader ( ) , InputHandler . class ) ; project . setProjectReference ( handler ) ; } project . setInputHandler ( handler ) ; } | Creates the InputHandler and adds it to the project . |
25,577 | private BuildLogger createLogger ( ) { BuildLogger logger ; if ( args . loggerClassname != null ) { try { logger = ClasspathUtils . newInstance ( args . loggerClassname , Main . class . getClassLoader ( ) , BuildLogger . class ) ; } catch ( final BuildException e ) { printErrorMessage ( "The specified logger class " + args . loggerClassname + " could not be used because " + e . getMessage ( ) ) ; throw new RuntimeException ( ) ; } } else { logger = new DefaultLogger ( ) ; ( ( DefaultLogger ) logger ) . useColor ( args . useColor ) ; } logger . setMessageOutputLevel ( args . msgOutputLevel ) ; logger . setOutputPrintStream ( out ) ; logger . setErrorPrintStream ( err ) ; logger . setEmacsMode ( args . emacsMode ) ; return logger ; } | Creates the default build logger for sending build events to the ant log . |
25,578 | private void configureSaxonExtensions ( SaxonTransformerFactory tfi ) { final net . sf . saxon . Configuration conf = tfi . getConfiguration ( ) ; for ( ExtensionFunctionDefinition def : ServiceLoader . load ( ExtensionFunctionDefinition . class ) ) { try { conf . registerExtensionFunction ( def . getClass ( ) . newInstance ( ) ) ; } catch ( InstantiationException e ) { throw new RuntimeException ( "Failed to register " + def . getFunctionQName ( ) . getDisplayName ( ) + ". Cannot create instance of " + def . getClass ( ) . getName ( ) + ": " + e . getMessage ( ) , e ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( e ) ; } } } | Registers Saxon full integrated function definitions . The intgrated function should be an instance of net . sf . saxon . lib . ExtensionFunctionDefinition abstract class . |
25,579 | public static void writeKeydef ( final File keydefFile , final Collection < KeyDef > keydefs ) throws DITAOTException { XMLStreamWriter keydef = null ; try ( OutputStream out = new FileOutputStream ( keydefFile ) ) { keydef = XMLOutputFactory . newInstance ( ) . createXMLStreamWriter ( out , "UTF-8" ) ; keydef . writeStartDocument ( ) ; keydef . writeStartElement ( ELEMENT_STUB ) ; for ( final KeyDef k : keydefs ) { keydef . writeStartElement ( ELEMENT_KEYDEF ) ; keydef . writeAttribute ( ATTRIBUTE_KEYS , k . keys ) ; if ( k . href != null ) { keydef . writeAttribute ( ATTRIBUTE_HREF , k . href . toString ( ) ) ; } if ( k . scope != null ) { keydef . writeAttribute ( ATTRIBUTE_SCOPE , k . scope ) ; } if ( k . format != null ) { keydef . writeAttribute ( ATTRIBUTE_FORMAT , k . format ) ; } if ( k . source != null ) { keydef . writeAttribute ( ATTRIBUTE_SOURCE , k . source . toString ( ) ) ; } keydef . writeEndElement ( ) ; } keydef . writeEndDocument ( ) ; } catch ( final XMLStreamException | IOException e ) { throw new DITAOTException ( "Failed to write key definition file " + keydefFile + ": " + e . getMessage ( ) , e ) ; } finally { if ( keydef != null ) { try { keydef . close ( ) ; } catch ( final XMLStreamException e ) { } } } } | Write key definition XML configuration file |
25,580 | private List < Element > getTopicrefs ( final Element root ) { final List < Element > res = new ArrayList < > ( ) ; final NodeList all = root . getElementsByTagName ( "*" ) ; for ( int i = 0 ; i < all . getLength ( ) ; i ++ ) { final Element elem = ( Element ) all . item ( i ) ; if ( MAP_TOPICREF . matches ( elem ) && isDitaFormat ( elem . getAttributeNode ( ATTRIBUTE_NAME_FORMAT ) ) && ! elem . getAttribute ( ATTRIBUTE_NAME_SCOPE ) . equals ( ATTR_SCOPE_VALUE_EXTERNAL ) ) { res . add ( elem ) ; } } return res ; } | Get all topicrefs |
25,581 | private void generateCopies ( final Element topicref , final List < FilterUtils > filters ) { final List < FilterUtils > fs = combineFilterUtils ( topicref , filters ) ; final String copyTo = topicref . getAttribute ( BRANCH_COPY_TO ) ; if ( ! copyTo . isEmpty ( ) ) { final URI dstUri = map . resolve ( copyTo ) ; final URI dstAbsUri = job . tempDirURI . resolve ( dstUri ) ; final String href = topicref . getAttribute ( ATTRIBUTE_NAME_HREF ) ; final URI srcUri = map . resolve ( href ) ; final URI srcAbsUri = job . tempDirURI . resolve ( srcUri ) ; final FileInfo srcFileInfo = job . getFileInfo ( srcUri ) ; if ( srcFileInfo != null ) { logger . info ( "Filtering " + srcAbsUri + " to " + dstAbsUri ) ; final ProfilingFilter writer = new ProfilingFilter ( ) ; writer . setLogger ( logger ) ; writer . setJob ( job ) ; writer . setFilterUtils ( fs ) ; writer . setCurrentFile ( dstAbsUri ) ; final List < XMLFilter > pipe = singletonList ( writer ) ; final File dstDirUri = new File ( dstAbsUri . resolve ( "." ) ) ; if ( ! dstDirUri . exists ( ) && ! dstDirUri . mkdirs ( ) ) { logger . error ( "Failed to create directory " + dstDirUri ) ; } try { xmlUtils . transform ( srcAbsUri , dstAbsUri , pipe ) ; } catch ( final DITAOTException e ) { logger . error ( "Failed to filter " + srcAbsUri + " to " + dstAbsUri + ": " + e . getMessage ( ) , e ) ; } topicref . setAttribute ( ATTRIBUTE_NAME_HREF , copyTo ) ; topicref . removeAttribute ( BRANCH_COPY_TO ) ; topicref . setAttribute ( SKIP_FILTER , Boolean . TRUE . toString ( ) ) ; } } for ( final Element child : getChildElements ( topicref , MAP_TOPICREF ) ) { if ( DITAVAREF_D_DITAVALREF . matches ( child ) ) { continue ; } generateCopies ( child , fs ) ; } } | Copy and filter topics for branches . These topics have a new name and will be added to job configuration . |
25,582 | private void filterTopics ( final Element topicref , final List < FilterUtils > filters ) { final List < FilterUtils > fs = combineFilterUtils ( topicref , filters ) ; final String href = topicref . getAttribute ( ATTRIBUTE_NAME_HREF ) ; final Attr skipFilter = topicref . getAttributeNode ( SKIP_FILTER ) ; final URI srcAbsUri = job . tempDirURI . resolve ( map . resolve ( href ) ) ; if ( ! fs . isEmpty ( ) && skipFilter == null && ! filtered . contains ( srcAbsUri ) && ! href . isEmpty ( ) && ! ATTR_SCOPE_VALUE_EXTERNAL . equals ( topicref . getAttribute ( ATTRIBUTE_NAME_SCOPE ) ) && ! ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY . equals ( topicref . getAttribute ( ATTRIBUTE_NAME_PROCESSING_ROLE ) ) && isDitaFormat ( topicref . getAttributeNode ( ATTRIBUTE_NAME_FORMAT ) ) ) { final ProfilingFilter writer = new ProfilingFilter ( ) ; writer . setLogger ( logger ) ; writer . setJob ( job ) ; writer . setFilterUtils ( fs ) ; writer . setCurrentFile ( srcAbsUri ) ; final List < XMLFilter > pipe = singletonList ( writer ) ; logger . info ( "Filtering " + srcAbsUri ) ; try { xmlUtils . transform ( srcAbsUri , pipe ) ; } catch ( final DITAOTException e ) { logger . error ( "Failed to filter " + srcAbsUri + ": " + e . getMessage ( ) , e ) ; } filtered . add ( srcAbsUri ) ; } if ( skipFilter != null ) { topicref . removeAttributeNode ( skipFilter ) ; } for ( final Element child : getChildElements ( topicref , MAP_TOPICREF ) ) { if ( DITAVAREF_D_DITAVALREF . matches ( child ) ) { continue ; } filterTopics ( child , fs ) ; } } | Modify and filter topics for branches . These files use an existing file name . |
25,583 | private FilterUtils getFilterUtils ( final Element ditavalRef ) { if ( ditavalRef . getAttribute ( ATTRIBUTE_NAME_HREF ) . isEmpty ( ) ) { return null ; } final URI href = toURI ( ditavalRef . getAttribute ( ATTRIBUTE_NAME_HREF ) ) ; final URI tmp = currentFile . resolve ( href ) ; final FileInfo fi = job . getFileInfo ( tmp ) ; final URI ditaval = fi . src ; FilterUtils f = filterCache . get ( ditaval ) ; if ( f == null ) { ditaValReader . filterReset ( ) ; logger . info ( "Reading " + ditaval ) ; ditaValReader . read ( ditaval ) ; Map < FilterUtils . FilterKey , FilterUtils . Action > filterMap = ditaValReader . getFilterMap ( ) ; f = new FilterUtils ( filterMap , ditaValReader . getForegroundConflictColor ( ) , ditaValReader . getBackgroundConflictColor ( ) ) ; f . setLogger ( logger ) ; filterCache . put ( ditaval , f ) ; } return f ; } | Read and cache filter . |
25,584 | private void handleKeysAttr ( final Attributes atts ) { final String attrValue = atts . getValue ( ATTRIBUTE_NAME_KEYS ) ; if ( attrValue != null ) { URI target = toURI ( atts . getValue ( ATTRIBUTE_NAME_HREF ) ) ; final URI copyTo = toURI ( atts . getValue ( ATTRIBUTE_NAME_COPY_TO ) ) ; if ( copyTo != null ) { target = copyTo ; } final String keyRef = atts . getValue ( ATTRIBUTE_NAME_KEYREF ) ; for ( final String key : attrValue . trim ( ) . split ( "\\s+" ) ) { if ( ! keysDefMap . containsKey ( key ) ) { if ( target != null && ! target . toString ( ) . isEmpty ( ) ) { final String attrScope = atts . getValue ( ATTRIBUTE_NAME_SCOPE ) ; final String attrFormat = atts . getValue ( ATTRIBUTE_NAME_FORMAT ) ; if ( attrScope != null && ( attrScope . equals ( ATTR_SCOPE_VALUE_EXTERNAL ) || attrScope . equals ( ATTR_SCOPE_VALUE_PEER ) ) ) { keysDefMap . put ( key , new KeyDef ( key , target , attrScope , attrFormat , null , null ) ) ; } else { String tail = null ; if ( target . getFragment ( ) != null ) { tail = target . getFragment ( ) ; target = stripFragment ( target ) ; } if ( ! target . isAbsolute ( ) ) { target = currentDir . resolve ( target ) ; } keysDefMap . put ( key , new KeyDef ( key , setFragment ( target , tail ) , ATTR_SCOPE_VALUE_LOCAL , attrFormat , null , null ) ) ; } } else if ( ! StringUtils . isEmptyString ( keyRef ) ) { keysRefMap . put ( key , keyRef ) ; } else { keysDefMap . put ( key , new KeyDef ( key , null , null , null , null , null ) ) ; } } else { logger . info ( MessageUtils . getMessage ( "DOTJ045I" , key ) . toString ( ) ) ; } } } } | Parse the keys attributes . |
25,585 | private List < String > getKeysList ( final String key , final Map < String , String > keysRefMap ) { final List < String > list = new ArrayList < > ( ) ; for ( Entry < String , String > entry : keysRefMap . entrySet ( ) ) { if ( entry . getValue ( ) . equals ( key ) ) { final String entryKey = entry . getKey ( ) ; list . add ( entryKey ) ; if ( keysRefMap . containsValue ( entryKey ) ) { final List < String > tempList = getKeysList ( entryKey , keysRefMap ) ; list . addAll ( tempList ) ; } } } return list ; } | Get multi - level keys list |
25,586 | private void checkMultiLevelKeys ( final Map < String , KeyDef > keysDefMap , final Map < String , String > keysRefMap ) { String key ; KeyDef value ; final Map < String , KeyDef > tempMap = new HashMap < > ( ) ; for ( Entry < String , KeyDef > entry : keysDefMap . entrySet ( ) ) { key = entry . getKey ( ) ; value = entry . getValue ( ) ; if ( keysRefMap . containsValue ( key ) ) { final List < String > keysList = getKeysList ( key , keysRefMap ) ; for ( final String multikey : keysList ) { tempMap . put ( multikey , value ) ; } } } keysDefMap . putAll ( tempMap ) ; } | Update keysDefMap for multi - level keys |
25,587 | public void setValidateMap ( final Map < QName , Map < String , Set < String > > > validateMap ) { this . validateMap = validateMap ; } | Set valid attribute values . |
25,588 | private void validateAttributeValues ( final String qName , final Attributes atts ) { if ( validateMap . isEmpty ( ) ) { return ; } for ( int i = 0 ; i < atts . getLength ( ) ; i ++ ) { final QName attrName = new QName ( atts . getURI ( i ) , atts . getLocalName ( i ) ) ; final Map < String , Set < String > > valueMap = validateMap . get ( attrName ) ; if ( valueMap != null ) { Set < String > valueSet = valueMap . get ( qName ) ; if ( valueSet == null ) { valueSet = valueMap . get ( "*" ) ; } if ( valueSet != null ) { final String attrValue = atts . getValue ( i ) ; final String [ ] keylist = attrValue . trim ( ) . split ( "\\s+" ) ; for ( final String s : keylist ) { if ( ! StringUtils . isEmptyString ( s ) && ! valueSet . contains ( s ) ) { logger . warn ( MessageUtils . getMessage ( "DOTJ049W" , attrName . toString ( ) , qName , attrValue , StringUtils . join ( valueSet , COMMA ) ) . toString ( ) ) ; } } } } } } | Validate attribute values |
25,589 | private void validateAttributeGeneralization ( final Attributes atts ) { final QName [ ] [ ] d = domains . peekFirst ( ) ; if ( d != null ) { for ( final QName [ ] spec : d ) { for ( int i = spec . length - 1 ; i > - 1 ; i -- ) { if ( atts . getValue ( spec [ i ] . getNamespaceURI ( ) , spec [ i ] . getLocalPart ( ) ) != null ) { for ( int j = i - 1 ; j > - 1 ; j -- ) { if ( atts . getValue ( spec [ j ] . getNamespaceURI ( ) , spec [ j ] . getLocalPart ( ) ) != null ) { logger . error ( MessageUtils . getMessage ( "DOTJ058E" , spec [ j ] . toString ( ) , spec [ i ] . toString ( ) ) . toString ( ) ) ; } } } } } } } | Validate attribute generalization . A single element may not contain both generalized and specialized values for the same attribute . |
25,590 | public String addId ( final URI id ) { if ( id == null ) { return null ; } final URI localId = id . normalize ( ) ; index ++ ; final String newId = PREFIX + Integer . toString ( index ) ; idMap . put ( localId , newId ) ; return newId ; } | Add topic id to the idMap . |
25,591 | public void addId ( final URI id , final String value ) { if ( id != null && value != null ) { final URI localId = id . normalize ( ) ; final String localValue = value . trim ( ) ; idMap . put ( localId , localValue ) ; } } | Add topic id - value pairs to idMap . |
25,592 | public String getIdValue ( final URI id ) { if ( id == null ) { return null ; } final URI localId = id . normalize ( ) ; return idMap . get ( localId ) ; } | Return the value corresponding to the id . |
25,593 | public boolean isVisited ( final URI path ) { final URI localPath = stripFragment ( path ) . normalize ( ) ; return visitSet . contains ( localPath ) ; } | Return if this path has been visited before . |
25,594 | public void visit ( final URI path ) { final URI localPath = stripFragment ( path ) . normalize ( ) ; visitSet . add ( localPath ) ; } | Add topic to set of visited topics . |
25,595 | public String getFirstTopicId ( final URI file , final boolean useCatalog ) { assert file . isAbsolute ( ) ; if ( ! ( new File ( file ) . exists ( ) ) ) { return null ; } final StringBuilder firstTopicId = new StringBuilder ( ) ; final TopicIdParser parser = new TopicIdParser ( firstTopicId ) ; try { final XMLReader reader = XMLUtils . getXMLReader ( ) ; reader . setContentHandler ( parser ) ; if ( useCatalog ) { reader . setEntityResolver ( CatalogUtils . getCatalogResolver ( ) ) ; } reader . parse ( file . toString ( ) ) ; } catch ( final Exception e ) { logger . error ( e . getMessage ( ) , e ) ; } return firstTopicId . toString ( ) ; } | Get the first topic id . |
25,596 | private boolean checkMatch ( ) { if ( matchList == null ) { return true ; } final int matchSize = matchList . size ( ) ; final int ancestorSize = topicIdList . size ( ) ; final List < String > tail = topicIdList . subList ( ancestorSize - matchSize , ancestorSize ) ; return matchList . equals ( tail ) ; } | check whether the hierarchy of current node match the matchList |
25,597 | private void writeStartElement ( final String qName , final Attributes atts ) throws IOException { final int attsLen = atts . getLength ( ) ; output . write ( LESS_THAN + qName ) ; for ( int i = 0 ; i < attsLen ; i ++ ) { final String attQName = atts . getQName ( i ) ; final String attValue = escapeXML ( atts . getValue ( i ) ) ; output . write ( STRING_BLANK + attQName + EQUAL + QUOTATION + attValue + QUOTATION ) ; } output . write ( GREATER_THAN ) ; } | SAX serializer methods |
25,598 | private String readExtensions ( final String featureName ) { final Set < String > exts = new HashSet < > ( ) ; if ( featureTable . containsKey ( featureName ) ) { for ( final Value ext : featureTable . get ( featureName ) ) { final String e = ext . value . trim ( ) ; if ( e . length ( ) != 0 ) { exts . add ( e ) ; } } } return StringUtils . join ( exts , CONF_LIST_SEPARATOR ) ; } | Read plug - in feature . |
25,599 | private boolean loadPlugin ( final String plugin ) { if ( checkPlugin ( plugin ) ) { final Features pluginFeatures = pluginTable . get ( plugin ) ; final Map < String , List < String > > featureSet = pluginFeatures . getAllFeatures ( ) ; for ( final Map . Entry < String , List < String > > currentFeature : featureSet . entrySet ( ) ) { final String key = currentFeature . getKey ( ) ; final List < Value > values = currentFeature . getValue ( ) . stream ( ) . map ( val -> new Value ( plugin , val ) ) . collect ( Collectors . toList ( ) ) ; if ( ! extensionPoints . contains ( key ) ) { final String msg = "Plug-in " + plugin + " uses an undefined extension point " + key ; throw new RuntimeException ( msg ) ; } if ( featureTable . containsKey ( key ) ) { final List < Value > value = featureTable . get ( key ) ; value . addAll ( values ) ; featureTable . put ( key , value ) ; } else { List < Value > currentFeatureValue = values ; featureTable . put ( key , currentFeatureValue != null ? new ArrayList < > ( currentFeatureValue ) : null ) ; } } for ( final Value templateName : pluginFeatures . getAllTemplates ( ) ) { final String template = new File ( pluginFeatures . getPluginDir ( ) . toURI ( ) . resolve ( templateName . value ) ) . getAbsolutePath ( ) ; final String templatePath = FileUtils . getRelativeUnixPath ( ditaDir + File . separator + "dummy" , template ) ; templateSet . put ( templatePath , templateName ) ; } loadedPlugin . add ( plugin ) ; return true ; } else { return false ; } } | Load the plug - ins and aggregate them by feature and fill into feature table . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.