idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
25,500 | 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 . | 172 | 7 |
25,501 | 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 . | 78 | 9 |
25,502 | @ Override public void buildFinished ( final BuildEvent event ) { final Throwable error = event . getException ( ) ; final StringBuilder message = new StringBuilder ( ) ; if ( error == null ) { // message.append(StringUtils.LINE_SEP); // message.append(getBuildSuccessfulMessage()); } else { // message.append(StringUtils.LINE_SEP); // message.append(getBuildFailedMessage()); // message.append(StringUtils.LINE_SEP); message . append ( "Error: " ) ; throwableMessage ( message , error , Project . MSG_VERBOSE <= msgOutputLevel ) ; } // message.append(StringUtils.LINE_SEP); // message.append("Total time: "); // message.append(formatTime(System.currentTimeMillis() - startTime)); 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 . | 268 | 22 |
25,503 | @ Override 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 . | 97 | 20 |
25,504 | @ Override public void messageLogged ( final BuildEvent event ) { final int priority = event . getPriority ( ) ; // Filter out messages based on priority if ( priority <= msgOutputLevel ) { final StringBuilder message = new StringBuilder ( ) ; if ( event . getTask ( ) != null && ! emacsMode ) { // Print out the name of the task if we're in one 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 ) { // shouldn't be possible message . append ( label ) . append ( event . getMessage ( ) ) ; } finally { if ( r != null ) { FileUtils . close ( r ) ; } } } else { // emacs mode or there is no task 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 . | 480 | 32 |
25,505 | 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 . | 74 | 9 |
25,506 | 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 . | 62 | 5 |
25,507 | protected String extractProjectName ( final BuildEvent event ) { final Project project = event . getProject ( ) ; return ( project != null ) ? project . getName ( ) : null ; } | Get the project name or null | 40 | 6 |
25,508 | 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 . | 75 | 4 |
25,509 | 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 | 184 | 6 |
25,510 | 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 . | 78 | 19 |
25,511 | 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 . | 75 | 13 |
25,512 | @ Override 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 . | 61 | 7 |
25,513 | 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 . | 206 | 4 |
25,514 | 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 . | 244 | 46 |
25,515 | 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 . | 80 | 13 |
25,516 | 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 . | 111 | 21 |
25,517 | 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 | 60 | 16 |
25,518 | 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 | 60 | 10 |
25,519 | 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 . | 199 | 8 |
25,520 | 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 . | 74 | 12 |
25,521 | 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 . | 51 | 14 |
25,522 | 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 | 49 | 8 |
25,523 | 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 . | 276 | 6 |
25,524 | public void update ( InputSource in ) throws SAXException { defaultValuesCollector = null ; PropertyMapBuilder builder = new PropertyMapBuilder ( ) ; //Set the resolver 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 ) { //EXM-24759 Also catch stackoverflow eh . warning ( new SAXParseException ( "Error loading defaults: " + e . getMessage ( ) , null , null ) ) ; } } | Updates the annotation model . | 228 | 6 |
25,525 | 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 . | 49 | 8 |
25,526 | 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 . | 161 | 8 |
25,527 | 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 ) { // href value refer to an id in a topic 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 ) ) { // topicId found retAttValue = toURI ( SHARP + util . getIdValue ( pathWithTopicID ) + elementId ) ; } else { // topicId not found retAttValue = toURI ( SHARP + util . addId ( pathWithTopicID ) + elementId ) ; } } else { // href value refer to a topic 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 . | 605 | 9 |
25,528 | 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 . | 159 | 8 |
25,529 | 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 ) ; // The scope for @href is local if ( ( TOPIC_XREF . matches ( classValue ) || TOPIC_LINK . matches ( classValue ) || TOPIC_LQ . matches ( classValue ) // term, keyword, cite, ph, and dt are resolved as keyref can make them links || 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 ) ) ) { // local xref or link that refers to dita file XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_HREF , handleLocalDita ( attValue , atts ) . toString ( ) ) ; } else { // local @href other than local xref and link that refers to // dita file XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_HREF , handleLocalHref ( attValue ) . toString ( ) ) ; } } } } | Rewrite href attribute . | 401 | 5 |
25,530 | 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 . | 72 | 11 |
25,531 | 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 . | 51 | 33 |
25,532 | private void handleLogfile ( ) { if ( args . logFile != null ) { FileUtils . close ( out ) ; FileUtils . close ( err ) ; } } | Close logfiles if we have been writing to them . | 38 | 11 |
25,533 | @ Override protected void addBuildListeners ( final Project project ) { // Add the default listener 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 . | 127 | 19 |
25,534 | 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 . | 96 | 12 |
25,535 | 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 . | 194 | 15 |
25,536 | 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 . | 168 | 35 |
25,537 | 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 | 377 | 6 |
25,538 | 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 | 170 | 5 |
25,539 | 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 ) { // final FileInfo fi = new FileInfo.Builder(srcFileInfo).uri(dstUri).build(); // TODO: Maybe Job should be updated earlier? // job.add(fi); 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 ) ; // disable filtering again 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 . | 585 | 21 |
25,540 | 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 . | 469 | 16 |
25,541 | 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 . | 262 | 5 |
25,542 | 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 ) ; // Many keys can be defined in a single definition, like // keys="a b c", a, b and c are seperated by blank. 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 ) ) { // store multi-level keys. keysRefMap . put ( key , keyRef ) ; } else { // target is null or empty, it is useful in the future // when consider the content of key definition keysDefMap . put ( key , new KeyDef ( key , null , null , null , null , null ) ) ; } } else { logger . info ( MessageUtils . getMessage ( "DOTJ045I" , key ) . toString ( ) ) ; } } } } | Parse the keys attributes . | 579 | 6 |
25,543 | private List < String > getKeysList ( final String key , final Map < String , String > keysRefMap ) { final List < String > list = new ArrayList <> ( ) ; // Iterate the map to look for multi-level keys for ( Entry < String , String > entry : keysRefMap . entrySet ( ) ) { // Multi-level key found if ( entry . getValue ( ) . equals ( key ) ) { // add key into the list final String entryKey = entry . getKey ( ) ; list . add ( entryKey ) ; // still have multi-level keys if ( keysRefMap . containsValue ( entryKey ) ) { // rescuive point final List < String > tempList = getKeysList ( entryKey , keysRefMap ) ; list . addAll ( tempList ) ; } } } return list ; } | Get multi - level keys list | 181 | 6 |
25,544 | private void checkMultiLevelKeys ( final Map < String , KeyDef > keysDefMap , final Map < String , String > keysRefMap ) { String key ; KeyDef value ; // tempMap storing values to avoid ConcurrentModificationException final Map < String , KeyDef > tempMap = new HashMap <> ( ) ; for ( Entry < String , KeyDef > entry : keysDefMap . entrySet ( ) ) { key = entry . getKey ( ) ; value = entry . getValue ( ) ; // there is multi-level keys exist. if ( keysRefMap . containsValue ( key ) ) { // get multi-level keys final List < String > keysList = getKeysList ( key , keysRefMap ) ; for ( final String multikey : keysList ) { // update tempMap tempMap . put ( multikey , value ) ; } } } // update keysDefMap. keysDefMap . putAll ( tempMap ) ; } | Update keysDefMap for multi - level keys | 204 | 9 |
25,545 | public void setValidateMap ( final Map < QName , Map < String , Set < String > > > validateMap ) { this . validateMap = validateMap ; } | Set valid attribute values . | 36 | 5 |
25,546 | 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 | 295 | 4 |
25,547 | 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 . | 210 | 22 |
25,548 | 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 . | 69 | 8 |
25,549 | 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 . | 62 | 10 |
25,550 | 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 . | 45 | 8 |
25,551 | public boolean isVisited ( final URI path ) { final URI localPath = stripFragment ( path ) . normalize ( ) ; return visitSet . contains ( localPath ) ; } | Return if this path has been visited before . | 39 | 9 |
25,552 | public void visit ( final URI path ) { final URI localPath = stripFragment ( path ) . normalize ( ) ; visitSet . add ( localPath ) ; } | Add topic to set of visited topics . | 36 | 8 |
25,553 | 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 . | 174 | 6 |
25,554 | 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 | 78 | 11 |
25,555 | 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 | 142 | 5 |
25,556 | 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 . | 112 | 6 |
25,557 | 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 { //Make shallow clone to avoid making modifications directly to list inside the current feature. 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 . | 400 | 16 |
25,558 | private boolean checkPlugin ( final String currentPlugin ) { final Features pluginFeatures = pluginTable . get ( currentPlugin ) ; final Iterator < PluginRequirement > iter = pluginFeatures . getRequireListIter ( ) ; // check whether dependcy is satisfied while ( iter . hasNext ( ) ) { boolean anyPluginFound = false ; final PluginRequirement requirement = iter . next ( ) ; final Iterator < String > requiredPluginIter = requirement . getPlugins ( ) ; while ( requiredPluginIter . hasNext ( ) ) { // Iterate over all alternatives in plugin requirement. final String requiredPlugin = requiredPluginIter . next ( ) ; if ( pluginTable . containsKey ( requiredPlugin ) ) { if ( ! loadedPlugin . contains ( requiredPlugin ) ) { // required plug-in is not loaded loadPlugin ( requiredPlugin ) ; } // As soon as any plugin is found, it's OK. anyPluginFound = true ; } } if ( ! anyPluginFound && requirement . getRequired ( ) ) { // not contain any plugin required by current plugin final String msg = MessageUtils . getMessage ( "DOTJ020W" , requirement . toString ( ) , currentPlugin ) . toString ( ) ; throw new RuntimeException ( msg ) ; } } return true ; } | Check whether the plugin can be loaded . | 271 | 8 |
25,559 | private void mergePlugins ( ) { final Element root = pluginsDoc . createElement ( ELEM_PLUGINS ) ; pluginsDoc . appendChild ( root ) ; if ( ! descSet . isEmpty ( ) ) { final URI b = new File ( ditaDir , CONFIG_DIR + File . separator + "plugins.xml" ) . toURI ( ) ; for ( final File descFile : descSet ) { logger . debug ( "Read plug-in configuration " + descFile . getPath ( ) ) ; final Element plugin = parseDesc ( descFile ) ; if ( plugin != null ) { final URI base = getRelativePath ( b , descFile . toURI ( ) ) ; plugin . setAttributeNS ( XML_NS_URI , XML_NS_PREFIX + ":base" , base . toString ( ) ) ; root . appendChild ( pluginsDoc . importNode ( plugin , true ) ) ; } } } } | Merge plugin configuration files . | 203 | 6 |
25,560 | private Element parseDesc ( final File descFile ) { try { parser . setPluginDir ( descFile . getParentFile ( ) ) ; final Element root = parser . parse ( descFile . getAbsoluteFile ( ) ) ; final Features f = parser . getFeatures ( ) ; final String id = f . getPluginId ( ) ; validatePlugin ( f ) ; extensionPoints . addAll ( f . getExtensionPoints ( ) . keySet ( ) ) ; pluginTable . put ( id , f ) ; return root ; } catch ( final RuntimeException e ) { throw e ; } catch ( final SAXParseException e ) { final RuntimeException ex = new RuntimeException ( "Failed to parse " + descFile . getAbsolutePath ( ) + ": " + e . getMessage ( ) , e ) ; throw ex ; } catch ( final Exception e ) { throw new RuntimeException ( e ) ; } } | Parse plugin configuration file | 196 | 5 |
25,561 | private void validatePlugin ( final Features f ) { final String id = f . getPluginId ( ) ; if ( ! ID_PATTERN . matcher ( id ) . matches ( ) ) { final String msg = "Plug-in ID '" + id + "' doesn't follow syntax rules." ; throw new IllegalArgumentException ( msg ) ; } final List < String > version = f . getFeature ( "package.version" ) ; if ( version != null && ! version . isEmpty ( ) && ! VERSION_PATTERN . matcher ( version . get ( 0 ) ) . matches ( ) ) { final String msg = "Plug-in version '" + version . get ( 0 ) + "' doesn't follow syntax rules." ; throw new IllegalArgumentException ( msg ) ; } } | Validate plug - in configuration . | 171 | 7 |
25,562 | static String getValue ( final Map < String , Features > featureTable , final String extension ) { final List < String > buf = new ArrayList <> ( ) ; for ( final Features f : featureTable . values ( ) ) { final List < String > v = f . getFeature ( extension ) ; if ( v != null ) { buf . addAll ( v ) ; } } if ( buf . isEmpty ( ) ) { return null ; } else { return StringUtils . join ( buf , "," ) ; } } | Get all and combine extension values | 112 | 6 |
25,563 | public static < T > List < T > toList ( final NodeList nodes ) { final List < T > res = new ArrayList <> ( nodes . getLength ( ) ) ; for ( int i = 0 ; i < nodes . getLength ( ) ; i ++ ) { res . add ( ( T ) nodes . item ( i ) ) ; } return res ; } | Convert DOM NodeList to List . | 79 | 8 |
25,564 | public static String getPrefix ( final String qname ) { final int sep = qname . indexOf ( ' ' ) ; return sep != - 1 ? qname . substring ( 0 , sep ) : DEFAULT_NS_PREFIX ; } | Get prefix from QName . | 54 | 6 |
25,565 | public static List < Element > getChildElements ( final Element elem , final DitaClass cls , final boolean deep ) { final NodeList children = deep ? elem . getElementsByTagName ( "*" ) : elem . getChildNodes ( ) ; final List < Element > res = new ArrayList <> ( children . getLength ( ) ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { final Node child = children . item ( i ) ; if ( cls . matches ( child ) ) { res . add ( ( Element ) child ) ; } } return res ; } | List descendant elements by DITA class . | 139 | 9 |
25,566 | public static Optional < Element > getChildElement ( final Element elem , final String ns , final String name ) { final NodeList children = elem . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { final Node child = children . item ( i ) ; if ( child . getNodeType ( ) == Node . ELEMENT_NODE ) { if ( Objects . equals ( child . getNamespaceURI ( ) , ns ) && name . equals ( child . getLocalName ( ) ) ) { return Optional . of ( ( Element ) child ) ; } } } return Optional . empty ( ) ; } | Get first child element by element name . | 143 | 8 |
25,567 | public static Optional < Element > getChildElement ( final Element elem , final DitaClass cls ) { final NodeList children = elem . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { final Node child = children . item ( i ) ; if ( cls . matches ( child ) ) { return Optional . of ( ( Element ) child ) ; } } return Optional . empty ( ) ; } | Get first child element by DITA class . | 101 | 10 |
25,568 | public static List < Element > getChildElements ( final Element elem , final String ns , final String name ) { final NodeList children = elem . getChildNodes ( ) ; final List < Element > res = new ArrayList <> ( children . getLength ( ) ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { final Node child = children . item ( i ) ; if ( child . getNodeType ( ) == Node . ELEMENT_NODE ) { if ( Objects . equals ( child . getNamespaceURI ( ) , ns ) && name . equals ( child . getLocalName ( ) ) ) { res . add ( ( Element ) child ) ; } } } return res ; } | List child elements by element name . | 160 | 7 |
25,569 | public static List < Element > getChildElements ( final Element elem , final DitaClass cls ) { return getChildElements ( elem , cls , false ) ; } | List child elements by DITA class . | 40 | 9 |
25,570 | public static List < Element > getChildElements ( final Element elem , final boolean deep ) { final NodeList children = deep ? elem . getElementsByTagName ( "*" ) : elem . getChildNodes ( ) ; final List < Element > res = new ArrayList <> ( children . getLength ( ) ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { final Node child = children . item ( i ) ; if ( child . getNodeType ( ) == Node . ELEMENT_NODE ) { res . add ( ( Element ) child ) ; } } return res ; } | List child elements elements . | 140 | 5 |
25,571 | public static Element getElementNode ( final Element element , final DitaClass classValue ) { final NodeList list = element . getChildNodes ( ) ; for ( int i = 0 ; i < list . getLength ( ) ; i ++ ) { final Node node = list . item ( i ) ; if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { final Element child = ( Element ) node ; if ( classValue . matches ( child ) ) { return child ; } } } return null ; } | Get specific element node from child nodes . | 113 | 8 |
25,572 | public static String getText ( final Node root ) { if ( root == null ) { return "" ; } else { final StringBuilder result = new StringBuilder ( 1024 ) ; if ( root . hasChildNodes ( ) ) { final NodeList list = root . getChildNodes ( ) ; for ( int i = 0 ; i < list . getLength ( ) ; i ++ ) { final Node childNode = list . item ( i ) ; if ( childNode . getNodeType ( ) == Node . ELEMENT_NODE ) { final Element e = ( Element ) childNode ; final String value = e . getAttribute ( ATTRIBUTE_NAME_CLASS ) ; if ( ! excludeList . contains ( value ) ) { final String s = getText ( e ) ; result . append ( s ) ; } } else if ( childNode . getNodeType ( ) == Node . TEXT_NODE ) { result . append ( childNode . getNodeValue ( ) ) ; } } } else if ( root . getNodeType ( ) == Node . TEXT_NODE ) { result . append ( root . getNodeValue ( ) ) ; } return result . toString ( ) ; } } | Get text value of a node . | 254 | 7 |
25,573 | public static Element searchForNode ( final Element root , final String searchKey , final String attrName , final DitaClass classValue ) { if ( root == null ) { return null ; } final Queue < Element > queue = new LinkedList <> ( ) ; queue . offer ( root ) ; while ( ! queue . isEmpty ( ) ) { final Element pe = queue . poll ( ) ; final NodeList pchildrenList = pe . getChildNodes ( ) ; for ( int i = 0 ; i < pchildrenList . getLength ( ) ; i ++ ) { final Node node = pchildrenList . item ( i ) ; if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { queue . offer ( ( Element ) node ) ; } } if ( pe . getAttribute ( ATTRIBUTE_NAME_CLASS ) == null || ! classValue . matches ( pe ) ) { continue ; } final Attr value = pe . getAttributeNode ( attrName ) ; if ( value == null ) { continue ; } if ( searchKey . equals ( value . getValue ( ) ) ) { return pe ; } } return null ; } | Search for the special kind of node by specialized value . Equivalent to XPath | 251 | 16 |
25,574 | public static void addOrSetAttribute ( final AttributesImpl atts , final String uri , final String localName , final String qName , final String type , final String value ) { final int i = atts . getIndex ( qName ) ; if ( i != - 1 ) { atts . setAttribute ( i , uri , localName , qName , type , value ) ; } else { atts . addAttribute ( uri , localName , qName , type , value ) ; } } | Add or set attribute . | 107 | 5 |
25,575 | public static void removeAttribute ( final AttributesImpl atts , final String qName ) { final int i = atts . getIndex ( qName ) ; if ( i != - 1 ) { atts . removeAttribute ( i ) ; } } | Remove an attribute from the list . Do nothing if attribute does not exist . | 51 | 15 |
25,576 | public static String getStringValue ( final Element element ) { final StringBuilder buf = new StringBuilder ( ) ; final NodeList children = element . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { final Node n = children . item ( i ) ; switch ( n . getNodeType ( ) ) { case Node . TEXT_NODE : buf . append ( n . getNodeValue ( ) ) ; break ; case Node . ELEMENT_NODE : buf . append ( getStringValue ( ( Element ) n ) ) ; break ; } } return buf . toString ( ) ; } | Get element node string value . | 139 | 6 |
25,577 | public void transform ( final URI input , final List < XMLFilter > filters ) throws DITAOTException { assert input . isAbsolute ( ) ; if ( ! input . getScheme ( ) . equals ( "file" ) ) { throw new IllegalArgumentException ( "Only file URI scheme supported: " + input ) ; } transform ( new File ( input ) , filters ) ; } | Transform file with XML filters . Only file URIs are supported . | 83 | 13 |
25,578 | public static void close ( final Source input ) throws IOException { if ( input != null && input instanceof StreamSource ) { final StreamSource s = ( StreamSource ) input ; final InputStream i = s . getInputStream ( ) ; if ( i != null ) { i . close ( ) ; } else { final Reader w = s . getReader ( ) ; if ( w != null ) { w . close ( ) ; } } } } | Close source . | 94 | 3 |
25,579 | public static void close ( final Result result ) throws IOException { if ( result != null && result instanceof StreamResult ) { final StreamResult r = ( StreamResult ) result ; final OutputStream o = r . getOutputStream ( ) ; if ( o != null ) { o . close ( ) ; } else { final Writer w = r . getWriter ( ) ; if ( w != null ) { w . close ( ) ; } } } } | Close result . | 94 | 3 |
25,580 | public static XMLReader getXMLReader ( ) throws SAXException { XMLReader reader ; if ( System . getProperty ( SAX_DRIVER_PROPERTY ) != null ) { return XMLReaderFactory . createXMLReader ( ) ; } try { Class . forName ( SAX_DRIVER_DEFAULT_CLASS ) ; reader = XMLReaderFactory . createXMLReader ( SAX_DRIVER_DEFAULT_CLASS ) ; } catch ( final ClassNotFoundException e ) { try { Class . forName ( SAX_DRIVER_SUN_HACK_CLASS ) ; reader = XMLReaderFactory . createXMLReader ( SAX_DRIVER_SUN_HACK_CLASS ) ; } catch ( final ClassNotFoundException ex ) { try { Class . forName ( SAX_DRIVER_CRIMSON_CLASS ) ; reader = XMLReaderFactory . createXMLReader ( SAX_DRIVER_CRIMSON_CLASS ) ; } catch ( final ClassNotFoundException exc ) { reader = XMLReaderFactory . createXMLReader ( ) ; } } } if ( Configuration . DEBUG ) { reader = new DebugXMLReader ( reader ) ; } return reader ; } | Get preferred SAX parser . | 259 | 6 |
25,581 | public static DocumentBuilder getDocumentBuilder ( ) { DocumentBuilder builder ; try { builder = factory . newDocumentBuilder ( ) ; } catch ( final ParserConfigurationException e ) { throw new RuntimeException ( e ) ; } if ( Configuration . DEBUG ) { builder = new DebugDocumentBuilder ( builder ) ; } return builder ; } | Get DOM parser . | 68 | 4 |
25,582 | public static String getCascadeValue ( final Element elem , final String attrName ) { Element current = elem ; while ( current != null ) { final Attr attr = current . getAttributeNode ( attrName ) ; if ( attr != null ) { return attr . getValue ( ) ; } final Node parent = current . getParentNode ( ) ; if ( parent != null && parent . getNodeType ( ) == Node . ELEMENT_NODE ) { current = ( Element ) parent ; } else { break ; } } return null ; } | Get cascaded attribute value . | 121 | 6 |
25,583 | public static Stream < Element > ancestors ( final Element element ) { final Stream . Builder < Element > builder = Stream . builder ( ) ; for ( Node current = element . getParentNode ( ) ; current != null ; current = current . getParentNode ( ) ) { if ( current . getNodeType ( ) == Node . ELEMENT_NODE ) { builder . accept ( ( Element ) current ) ; } } return builder . build ( ) ; } | Stream of element ancestor elements . | 95 | 6 |
25,584 | public AbstractPipelineModule createModule ( final Class < ? extends AbstractPipelineModule > moduleClass ) throws DITAOTException { try { return moduleClass . newInstance ( ) ; } catch ( final Exception e ) { final MessageBean msgBean = MessageUtils . getMessage ( "DOTJ005F" , moduleClass . getName ( ) ) ; final String msg = msgBean . toString ( ) ; throw new DITAOTException ( msgBean , e , msg ) ; } } | Create the ModuleElem class instance according to moduleName . | 113 | 12 |
25,585 | public static synchronized CatalogResolver getCatalogResolver ( ) { if ( catalogResolver == null ) { final CatalogManager manager = new CatalogManager ( ) ; manager . setIgnoreMissingProperties ( true ) ; manager . setUseStaticCatalog ( false ) ; // We'll use a private catalog. manager . setPreferPublic ( true ) ; final File catalogFilePath = new File ( ditaDir , Configuration . pluginResourceDirs . get ( "org.dita.base" ) + File . separator + FILE_NAME_CATALOG ) ; manager . setCatalogFiles ( catalogFilePath . toURI ( ) . toASCIIString ( ) ) ; //manager.setVerbosity(10); catalogResolver = new CatalogResolver ( manager ) ; } return catalogResolver ; } | Get CatalogResolver . | 172 | 5 |
25,586 | public void setup ( final LinkedHashMap < URI , URI > changeTable , final Map < URI , URI > conflictTable , final Element rootTopicref , final ChunkFilenameGenerator chunkFilenameGenerator ) { this . changeTable = changeTable ; this . rootTopicref = rootTopicref ; this . conflictTable = conflictTable ; this . chunkFilenameGenerator = chunkFilenameGenerator ; } | Set up the class . | 84 | 5 |
25,587 | URI generateOutputFile ( final URI ref ) { final FileInfo srcFi = job . getFileInfo ( ref ) ; final URI newSrc = srcFi . src . resolve ( generateFilename ( ) ) ; final URI tmp = tempFileNameScheme . generateTempFileName ( newSrc ) ; if ( job . getFileInfo ( tmp ) == null ) { job . add ( new FileInfo . Builder ( ) . result ( newSrc ) . uri ( tmp ) . build ( ) ) ; } return job . tempDirURI . resolve ( tmp ) ; } | Generate output file . | 122 | 5 |
25,588 | Element createTopicMeta ( final Element topic ) { final Document doc = rootTopicref . getOwnerDocument ( ) ; final Element topicmeta = doc . createElement ( MAP_TOPICMETA . localName ) ; topicmeta . setAttribute ( ATTRIBUTE_NAME_CLASS , MAP_TOPICMETA . toString ( ) ) ; // iterate the node. if ( topic != null ) { final Element title = getElementNode ( topic , TOPIC_TITLE ) ; final Element titlealts = getElementNode ( topic , TOPIC_TITLEALTS ) ; final Element navtitle = titlealts != null ? getElementNode ( titlealts , TOPIC_NAVTITLE ) : null ; final Element shortDesc = getElementNode ( topic , TOPIC_SHORTDESC ) ; final Element navtitleNode = doc . createElement ( TOPIC_NAVTITLE . localName ) ; navtitleNode . setAttribute ( ATTRIBUTE_NAME_CLASS , TOPIC_NAVTITLE . toString ( ) ) ; // append navtitle node if ( navtitle != null ) { final String text = getText ( navtitle ) ; final Text titleText = doc . createTextNode ( text ) ; navtitleNode . appendChild ( titleText ) ; topicmeta . appendChild ( navtitleNode ) ; } else { final String text = getText ( title ) ; final Text titleText = doc . createTextNode ( text ) ; navtitleNode . appendChild ( titleText ) ; topicmeta . appendChild ( navtitleNode ) ; } // append gentext pi final Node pi = doc . createProcessingInstruction ( "ditaot" , "gentext" ) ; topicmeta . appendChild ( pi ) ; // append linktext final Element linkTextNode = doc . createElement ( TOPIC_LINKTEXT . localName ) ; linkTextNode . setAttribute ( ATTRIBUTE_NAME_CLASS , MAP_LINKTEXT . toString ( ) ) ; final String text = getText ( title ) ; final Text textNode = doc . createTextNode ( text ) ; linkTextNode . appendChild ( textNode ) ; topicmeta . appendChild ( linkTextNode ) ; // append genshortdesc pi final Node pii = doc . createProcessingInstruction ( "ditaot" , "genshortdesc" ) ; topicmeta . appendChild ( pii ) ; // append shortdesc final Element shortDescNode = doc . createElement ( TOPIC_SHORTDESC . localName ) ; shortDescNode . setAttribute ( ATTRIBUTE_NAME_CLASS , MAP_SHORTDESC . toString ( ) ) ; final String shortDescText = getText ( shortDesc ) ; final Text shortDescTextNode = doc . createTextNode ( shortDescText ) ; shortDescNode . appendChild ( shortDescTextNode ) ; topicmeta . appendChild ( shortDescNode ) ; } return topicmeta ; } | Create topicmeta node . | 638 | 5 |
25,589 | String getFirstTopicId ( final File ditaTopicFile ) { assert ditaTopicFile . isAbsolute ( ) ; if ( ! ditaTopicFile . isAbsolute ( ) ) { return null ; } final StringBuilder firstTopicId = new StringBuilder ( ) ; final TopicIdParser parser = new TopicIdParser ( firstTopicId ) ; try { final XMLReader reader = getXMLReader ( ) ; reader . setContentHandler ( parser ) ; reader . parse ( ditaTopicFile . toURI ( ) . toString ( ) ) ; } catch ( final RuntimeException e ) { throw e ; } catch ( final Exception e ) { logger . error ( e . getMessage ( ) , e ) ; } if ( firstTopicId . length ( ) == 0 ) { return null ; } return firstTopicId . toString ( ) ; } | Get the first topic id from the given dita file . | 180 | 12 |
25,590 | void writeStartDocument ( final Writer output ) throws SAXException { try { output . write ( XML_HEAD ) ; } catch ( IOException e ) { throw new SAXException ( e ) ; } } | Convenience method to write document start . | 44 | 9 |
25,591 | void writeProcessingInstruction ( final Writer output , final String name , final String value ) throws SAXException { try { output . write ( LESS_THAN ) ; output . write ( QUESTION ) ; output . write ( name ) ; if ( value != null ) { output . write ( STRING_BLANK ) ; output . write ( value ) ; } output . write ( QUESTION ) ; output . write ( GREATER_THAN ) ; } catch ( IOException e ) { throw new SAXException ( e ) ; } } | Convenience method to write a processing instruction . | 116 | 10 |
25,592 | private void insertAfter ( final URI hrefValue , final StringBuffer parentResult , final CharSequence tmpContent ) { int insertpoint = parentResult . lastIndexOf ( "</" ) ; final int end = parentResult . indexOf ( ">" , insertpoint ) ; if ( insertpoint == - 1 || end == - 1 ) { logger . error ( MessageUtils . getMessage ( "DOTJ033E" , hrefValue . toString ( ) ) . toString ( ) ) ; } else { if ( ELEMENT_NAME_DITA . equals ( parentResult . substring ( insertpoint , end ) . trim ( ) ) ) { insertpoint = parentResult . lastIndexOf ( "</" , insertpoint - 1 ) ; } parentResult . insert ( insertpoint , tmpContent ) ; } } | Append XML content into root element | 173 | 7 |
25,593 | private void writeToContentChunk ( final String tmpContent , final URI outputFileName , final boolean needWriteDitaTag ) throws IOException { assert outputFileName . isAbsolute ( ) ; logger . info ( "Writing " + outputFileName ) ; try ( OutputStreamWriter ditaFileOutput = new OutputStreamWriter ( new FileOutputStream ( new File ( outputFileName ) ) , StandardCharsets . UTF_8 ) ) { if ( outputFileName . equals ( changeTable . get ( outputFileName ) ) ) { // if the output file is newly generated file // write the xml header and workdir PI into new file writeStartDocument ( ditaFileOutput ) ; final URI workDir = outputFileName . resolve ( "." ) ; if ( ! OS_NAME . toLowerCase ( ) . contains ( OS_NAME_WINDOWS ) ) { writeProcessingInstruction ( ditaFileOutput , PI_WORKDIR_TARGET , new File ( workDir ) . getAbsolutePath ( ) ) ; } else { writeProcessingInstruction ( ditaFileOutput , PI_WORKDIR_TARGET , UNIX_SEPARATOR + new File ( workDir ) . getAbsolutePath ( ) ) ; } writeProcessingInstruction ( ditaFileOutput , PI_WORKDIR_TARGET_URI , workDir . toString ( ) ) ; final File path2rootmap = toFile ( getRelativePath ( outputFileName , job . getInputMap ( ) ) ) . getParentFile ( ) ; writeProcessingInstruction ( ditaFileOutput , PI_PATH2ROOTMAP_TARGET_URI , path2rootmap == null ? "./" : toURI ( path2rootmap ) . toString ( ) ) ; if ( conflictTable . get ( outputFileName ) != null ) { final String relativePath = getRelativeUnixPath ( new File ( currentFile . resolve ( "." ) ) + UNIX_SEPARATOR + FILE_NAME_STUB_DITAMAP , new File ( conflictTable . get ( outputFileName ) ) . getAbsolutePath ( ) ) ; String path2project = getRelativeUnixPath ( relativePath ) ; if ( null == path2project ) { path2project = "" ; } writeProcessingInstruction ( ditaFileOutput , PI_PATH2PROJ_TARGET , path2project ) ; writeProcessingInstruction ( ditaFileOutput , PI_PATH2PROJ_TARGET_URI , path2project . isEmpty ( ) ? "./" : toURI ( path2project ) . toString ( ) ) ; } } if ( needWriteDitaTag ) { final AttributesImpl atts = new AttributesImpl ( ) ; addOrSetAttribute ( atts , ATTRIBUTE_NAMESPACE_PREFIX_DITAARCHVERSION , DITA_NAMESPACE ) ; addOrSetAttribute ( atts , ATTRIBUTE_PREFIX_DITAARCHVERSION + COLON + ATTRIBUTE_NAME_DITAARCHVERSION , "1.3" ) ; writeStartElement ( ditaFileOutput , ELEMENT_NAME_DITA , atts ) ; } // write the final result to the output file ditaFileOutput . write ( tmpContent ) ; if ( needWriteDitaTag ) { writeEndElement ( ditaFileOutput , ELEMENT_NAME_DITA ) ; } ditaFileOutput . flush ( ) ; } catch ( SAXException e ) { throw new IOException ( e ) ; } } | flush the buffer to file after processing is finished | 766 | 9 |
25,594 | public static String getString ( final String key , final Locale msgLocale ) { /*read message resource file.*/ ResourceBundle RESOURCE_BUNDLE = ResourceBundle . getBundle ( BUNDLE_NAME , msgLocale ) ; try { return RESOURCE_BUNDLE . getString ( key ) ; } catch ( final MissingResourceException e ) { return key ; } } | get specific message by key and locale . | 88 | 8 |
25,595 | public boolean findTopicId ( final File absolutePathToFile , final String id ) { if ( ! absolutePathToFile . exists ( ) ) { return false ; } try { //load the file final DocumentBuilder builder = XMLUtils . getDocumentBuilder ( ) ; builder . setEntityResolver ( CatalogUtils . getCatalogResolver ( ) ) ; final Document root = builder . parse ( new InputSource ( new FileInputStream ( absolutePathToFile ) ) ) ; //get root element final Element doc = root . getDocumentElement ( ) ; //do BFS final Queue < Element > queue = new LinkedList <> ( ) ; queue . offer ( doc ) ; while ( ! queue . isEmpty ( ) ) { final Element pe = queue . poll ( ) ; final NodeList pchildrenList = pe . getChildNodes ( ) ; for ( int i = 0 ; i < pchildrenList . getLength ( ) ; i ++ ) { final Node node = pchildrenList . item ( i ) ; if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { queue . offer ( ( Element ) node ) ; } } final String classValue = pe . getAttribute ( ATTRIBUTE_NAME_CLASS ) ; if ( classValue != null && TOPIC_TOPIC . matches ( classValue ) ) { //topic id found if ( pe . getAttribute ( ATTRIBUTE_NAME_ID ) . equals ( id ) ) { return true ; } } } return false ; } catch ( final RuntimeException e ) { throw e ; } catch ( final Exception e ) { logger . error ( "Failed to read document: " + e . getMessage ( ) , e ) ; } return false ; } | Find whether an id is refer to a topic in a dita file . | 371 | 15 |
25,596 | private Element searchForKey ( final Element root , final String key , final String tagName ) { if ( root == null || StringUtils . isEmptyString ( key ) ) { return null ; } final Queue < Element > queue = new LinkedList <> ( ) ; queue . offer ( root ) ; while ( ! queue . isEmpty ( ) ) { final Element pe = queue . poll ( ) ; final NodeList pchildrenList = pe . getChildNodes ( ) ; for ( int i = 0 ; i < pchildrenList . getLength ( ) ; i ++ ) { final Node node = pchildrenList . item ( i ) ; if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { queue . offer ( ( Element ) node ) ; } } String value = pe . getNodeName ( ) ; if ( StringUtils . isEmptyString ( value ) || ! value . equals ( tagName ) ) { continue ; } value = pe . getAttribute ( ATTRIBUTE_NAME_NAME ) ; if ( StringUtils . isEmptyString ( value ) ) { continue ; } if ( value . equals ( key ) ) { return pe ; } } return null ; } | Search specific element by key and tagName . | 259 | 9 |
25,597 | public void writeMapToXML ( final Map < String , Set < String > > m ) { final File outputFile = new File ( job . tempDir , FILE_NAME_PLUGIN_XML ) ; if ( m == null ) { return ; } final Properties prop = new Properties ( ) ; for ( Map . Entry < String , Set < String > > entry : m . entrySet ( ) ) { final String key = entry . getKey ( ) ; final String value = StringUtils . join ( entry . getValue ( ) , COMMA ) ; prop . setProperty ( key , value ) ; } //File outputFile = new File(tempDir, filename); final DocumentBuilder db = XMLUtils . getDocumentBuilder ( ) ; final Document doc = db . newDocument ( ) ; final Element properties = ( Element ) doc . appendChild ( doc . createElement ( "properties" ) ) ; final Set < Object > keys = prop . keySet ( ) ; for ( Object key1 : keys ) { final String key = ( String ) key1 ; final Element entry = ( Element ) properties . appendChild ( doc . createElement ( "entry" ) ) ; entry . setAttribute ( "key" , key ) ; entry . appendChild ( doc . createTextNode ( prop . getProperty ( key ) ) ) ; } final TransformerFactory tf = TransformerFactory . newInstance ( ) ; Transformer t ; try { t = withLogger ( tf . newTransformer ( ) , logger ) ; t . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; t . setOutputProperty ( OutputKeys . METHOD , "xml" ) ; t . setOutputProperty ( OutputKeys . ENCODING , "UTF-8" ) ; } catch ( final TransformerConfigurationException tce ) { throw new RuntimeException ( tce ) ; } final DOMSource doms = new DOMSource ( doc ) ; OutputStream out = null ; try { out = new FileOutputStream ( outputFile ) ; final StreamResult sr = new StreamResult ( out ) ; t . transform ( doms , sr ) ; } catch ( final Exception e ) { logger . error ( "Failed to process map: " + e . getMessage ( ) , e ) ; } finally { if ( out != null ) { try { out . close ( ) ; } catch ( final IOException e ) { logger . error ( "Failed to close output stream: " + e . getMessage ( ) ) ; } } } } | Write map into xml file . | 536 | 6 |
25,598 | SubjectScheme getSubjectScheme ( final Element root ) { subjectSchemeReader . reset ( ) ; logger . debug ( "Loading subject schemes" ) ; final List < Element > subjectSchemes = toList ( root . getElementsByTagName ( "*" ) ) ; subjectSchemes . stream ( ) . filter ( SUBJECTSCHEME_ENUMERATIONDEF :: matches ) . forEach ( enumerationDef -> { final Element schemeRoot = ancestors ( enumerationDef ) . filter ( SUBMAP :: matches ) . findFirst ( ) . orElse ( root ) ; subjectSchemeReader . processEnumerationDef ( schemeRoot , enumerationDef ) ; } ) ; return subjectSchemeReader . getSubjectSchemeMap ( ) ; } | Read subject scheme definitions . | 163 | 5 |
25,599 | List < FilterUtils > combineFilterUtils ( final Element topicref , final List < FilterUtils > filters , final SubjectScheme subjectSchemeMap ) { return getChildElement ( topicref , DITAVAREF_D_DITAVALREF ) . map ( ditavalRef -> getFilterUtils ( ditavalRef ) . refine ( subjectSchemeMap ) ) . map ( f -> { final List < FilterUtils > fs = new ArrayList <> ( filters . size ( ) + 1 ) ; fs . addAll ( filters ) ; fs . add ( f ) ; return fs ; } ) . orElse ( filters ) ; } | Combine referenced DITAVAL to existing list and refine with subject scheme . | 141 | 16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.