blob: 27dfd7ea637e50243caca3d2d94a1bb790aac7e7 [file] [log] [blame]
Stuart McCullochb657c2f2008-01-25 08:10:25 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.apache.felix.obr.plugin;
20
21
22import java.io.File;
23import java.io.FileNotFoundException;
24import java.io.FileOutputStream;
25import java.io.IOException;
26import java.net.URI;
27import java.text.SimpleDateFormat;
28import java.util.Date;
29import java.util.Properties;
30
31import javax.xml.parsers.DocumentBuilder;
32import javax.xml.parsers.DocumentBuilderFactory;
33import javax.xml.parsers.ParserConfigurationException;
34import javax.xml.transform.Result;
35import javax.xml.transform.Transformer;
36import javax.xml.transform.TransformerConfigurationException;
37import javax.xml.transform.TransformerException;
38import javax.xml.transform.TransformerFactory;
39import javax.xml.transform.dom.DOMSource;
40import javax.xml.transform.stream.StreamResult;
41
42import org.apache.maven.plugin.MojoExecutionException;
43import org.apache.maven.plugin.logging.Log;
44import org.apache.maven.project.MavenProject;
45import org.w3c.dom.Document;
46import org.w3c.dom.Element;
47import org.w3c.dom.NamedNodeMap;
48import org.w3c.dom.Node;
49import org.w3c.dom.NodeList;
50import org.xml.sax.SAXException;
51
52
53/**
54 * this class parse the old repository.xml file build the bundle resource description and update the repository.
55 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
56 */
Stuart McCullochb657c2f2008-01-25 08:10:25 +000057public class ObrUpdate
58{
59 /**
60 * generate the date format to insert it in repository descriptor file.
61 */
62 static SimpleDateFormat m_format = new SimpleDateFormat( "yyyyMMddHHmmss.SSS" );
63
64 /**
65 * logger for this plugin.
66 */
67 private Log m_logger;
68
69 /**
70 * name and path to the repository descriptor file.
71 */
Stuart McCullochb721aae2008-01-27 08:16:22 +000072 private URI m_repositoryXml;
Stuart McCullochb657c2f2008-01-25 08:10:25 +000073
74 /**
75 * name and path to the obr.xml file.
76 */
Stuart McCulloch80a87342008-01-27 11:04:46 +000077 private URI m_obrXml;
Stuart McCullochb657c2f2008-01-25 08:10:25 +000078
79 /**
80 * name and path to the bundle jar file.
81 */
Stuart McCulloch37a882e2008-01-28 08:26:29 +000082 private URI m_bundleJar;
Stuart McCullochb657c2f2008-01-25 08:10:25 +000083
84 /**
85 * maven project description.
86 */
87 private MavenProject m_project;
88
89 /**
90 * user configuration information.
91 */
92 private Config m_userConfig;
93
94 /**
95 * used to build another xml document.
96 */
Stuart McCullochb721aae2008-01-27 08:16:22 +000097 private DocumentBuilder m_documentBuilder;
Stuart McCullochb657c2f2008-01-25 08:10:25 +000098
99 /**
100 * root on parent document.
101 */
Stuart McCullochb721aae2008-01-27 08:16:22 +0000102 private Document m_repositoryDoc;
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000103
104 /**
105 * used to store bundle information.
106 */
107 private ResourcesBundle m_resourceBundle;
108
109 /**
Stuart McCulloch80a87342008-01-27 11:04:46 +0000110 * base URI used to relativize bundle URIs.
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000111 */
Stuart McCulloch80a87342008-01-27 11:04:46 +0000112 private URI m_baseURI;
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000113
114
115 /**
116 * initialize information.
Stuart McCullochb721aae2008-01-27 08:16:22 +0000117 * @param repositoryXml path to the repository descriptor file
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000118 * @param obrXml path and filename to the obr.xml file
119 * @param project maven project description
Stuart McCulloch37a882e2008-01-28 08:26:29 +0000120 * @param bundleJar path to the bundle jar file
Stuart McCullochb721aae2008-01-27 08:16:22 +0000121 * @param mavenRepositoryPath path to the local maven repository
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000122 * @param userConfig user information
Stuart McCullochb721aae2008-01-27 08:16:22 +0000123 * @param logger plugin logger
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000124 */
Stuart McCulloch37a882e2008-01-28 08:26:29 +0000125 public ObrUpdate( URI repositoryXml, URI obrXml, MavenProject project, URI bundleJar, String mavenRepositoryPath,
126 Config userConfig, Log logger )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000127 {
Stuart McCulloch37a882e2008-01-28 08:26:29 +0000128 m_bundleJar = bundleJar;
129 m_repositoryXml = repositoryXml;
Stuart McCulloch473e9942008-01-28 05:23:50 +0000130 m_obrXml = obrXml;
Stuart McCullochbb9bd382008-01-25 08:14:10 +0000131 m_project = project;
Stuart McCullochb721aae2008-01-27 08:16:22 +0000132 m_logger = logger;
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000133
Stuart McCullochbb9bd382008-01-25 08:14:10 +0000134 m_userConfig = userConfig;
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000135
Stuart McCullochb721aae2008-01-27 08:16:22 +0000136 m_resourceBundle = new ResourcesBundle( logger );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000137
Stuart McCullocha132a142008-02-05 11:18:20 +0000138 if ( userConfig.isRemoteFile() )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000139 {
Stuart McCulloch80a87342008-01-27 11:04:46 +0000140 m_baseURI = ObrUtils.toFileURI( mavenRepositoryPath );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000141 }
142 else
143 {
Stuart McCulloch80a87342008-01-27 11:04:46 +0000144 m_baseURI = m_repositoryXml;
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000145 }
146 }
147
148
149 /**
150 * update the repository descriptor file. parse the old repository descriptor file, get the old reference of the bundle or determine the id for a new bundle, extract information from bindex set the new information in descriptor file and save it.
151 * @throws MojoExecutionException if the plugin failed
152 */
153 public void updateRepository() throws MojoExecutionException
154 {
Stuart McCulloch37a882e2008-01-28 08:26:29 +0000155 m_logger.debug( " (f) repositoryXml = " + m_repositoryXml );
156 m_logger.debug( " (f) bundleJar = " + m_bundleJar );
157 m_logger.debug( " (f) obrXml = " + m_obrXml );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000158
Stuart McCullochb721aae2008-01-27 08:16:22 +0000159 m_documentBuilder = initDocumentBuilder();
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000160
Stuart McCullochb721aae2008-01-27 08:16:22 +0000161 if ( m_documentBuilder == null )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000162 {
163 return;
164 }
165
166 // get the file size
Stuart McCulloch37a882e2008-01-28 08:26:29 +0000167 File bundleFile = new File( m_bundleJar );
Stuart McCullochb721aae2008-01-27 08:16:22 +0000168 if ( bundleFile.exists() )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000169 {
Stuart McCullocha132a142008-02-05 11:18:20 +0000170 URI resourceURI = m_userConfig.getRemoteBundle();
171 if ( null == resourceURI )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000172 {
Stuart McCullocha132a142008-02-05 11:18:20 +0000173 resourceURI = m_bundleJar;
174 if ( m_userConfig.isPathRelative() )
175 {
176 resourceURI = ObrUtils.getRelativeURI( m_baseURI, resourceURI );
177 }
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000178 }
Stuart McCulloch80a87342008-01-27 11:04:46 +0000179
180 m_resourceBundle.setSize( String.valueOf( bundleFile.length() ) );
Stuart McCulloch37a882e2008-01-28 08:26:29 +0000181 m_resourceBundle.setUri( resourceURI.toASCIIString() );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000182 }
183 else
184 {
Stuart McCulloch37a882e2008-01-28 08:26:29 +0000185 m_logger.error( "file doesn't exist: " + m_bundleJar );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000186 return;
187 }
188
189 // parse repository
190 if ( parseRepositoryXml() == -1 )
191 {
192 return;
193 }
194
195 // parse the obr.xml file
196 if ( m_obrXml != null )
197 {
Stuart McCulloch2deb0522008-02-05 04:11:10 +0000198 m_logger.info( "Adding " + m_obrXml );
199
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000200 // URL url = getClass().getResource("/SchemaObr.xsd");
201 // TODO validate obr.xml file
202
Stuart McCullochb721aae2008-01-27 08:16:22 +0000203 Document obrXmlDoc = parseFile( m_obrXml, m_documentBuilder );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000204 if ( obrXmlDoc == null )
205 {
206 return;
207 }
Stuart McCulloch2deb0522008-02-05 04:11:10 +0000208
Stuart McCullochebfe1252008-02-04 08:32:32 +0000209 Node obrXmlRoot = obrXmlDoc.getDocumentElement();
Stuart McCulloch2deb0522008-02-05 04:11:10 +0000210
211 // add contents to resource bundle
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000212 sortObrXml( obrXmlRoot );
213 }
214
Stuart McCullochb721aae2008-01-27 08:16:22 +0000215 ExtractBindexInfo bindexExtractor;
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000216 try
217 {
Stuart McCullochb721aae2008-01-27 08:16:22 +0000218 // use bindex to extract bundle information
Stuart McCulloch37a882e2008-01-28 08:26:29 +0000219 bindexExtractor = new ExtractBindexInfo( m_repositoryXml, m_bundleJar.getPath() );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000220 }
221 catch ( MojoExecutionException e )
222 {
223 m_logger.error( "unable to build Bindex informations" );
224 e.printStackTrace();
Stuart McCulloch2deb0522008-02-05 04:11:10 +0000225
Stuart McCullocha132a142008-02-05 11:18:20 +0000226 throw new MojoExecutionException( "BindexException" );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000227 }
228
Stuart McCullochb721aae2008-01-27 08:16:22 +0000229 m_resourceBundle.construct( m_project, bindexExtractor );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000230
Stuart McCullochb721aae2008-01-27 08:16:22 +0000231 Element rootElement = m_repositoryDoc.getDocumentElement();
232 if ( !walkOnTree( rootElement ) )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000233 {
234 // the correct resource node was not found, we must create it
235 // we compute the new id
236 String id = m_resourceBundle.getId();
Stuart McCullochb721aae2008-01-27 08:16:22 +0000237 searchRepository( rootElement, id );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000238 }
239
240 // the repository.xml file have been modified, so we save it
241 m_logger.info( "Writing OBR metadata" );
Stuart McCullochb721aae2008-01-27 08:16:22 +0000242 writeToFile( m_repositoryXml, rootElement );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000243 }
244
245
246 /**
247 * init the document builder from xerces.
248 * @return DocumentBuilder ready to create new document
249 */
Stuart McCullochb721aae2008-01-27 08:16:22 +0000250 private DocumentBuilder initDocumentBuilder()
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000251 {
Stuart McCullochb721aae2008-01-27 08:16:22 +0000252 DocumentBuilder documentBuilder = null;
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000253 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
254 try
255 {
Stuart McCullochb721aae2008-01-27 08:16:22 +0000256 documentBuilder = factory.newDocumentBuilder();
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000257 }
258 catch ( ParserConfigurationException e )
259 {
260 m_logger.error( "unable to create a new xml document" );
261 e.printStackTrace();
262 }
Stuart McCullochb721aae2008-01-27 08:16:22 +0000263 return documentBuilder;
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000264
265 }
266
267
268 /**
269 * Parse the repository descriptor file.
270 *
271 * @return 0 if the bundle is already in the descriptor, else -1
272 * @throws MojoExecutionException if the plugin failed
273 */
274 private int parseRepositoryXml() throws MojoExecutionException
275 {
276
Stuart McCullochb721aae2008-01-27 08:16:22 +0000277 File fout = new File( m_repositoryXml );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000278 if ( !fout.exists() )
279 {
Stuart McCullochb721aae2008-01-27 08:16:22 +0000280 Document doc = m_documentBuilder.newDocument();
Stuart McCulloch80a87342008-01-27 11:04:46 +0000281
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000282 // create xml tree
283 Date d = new Date();
284 d.setTime( System.currentTimeMillis() );
285 Element root = doc.createElement( "repository" );
286 root.setAttribute( "lastmodified", m_format.format( d ) );
287 root.setAttribute( "name", "MyRepository" );
288 try
289 {
Stuart McCullochb721aae2008-01-27 08:16:22 +0000290 writeToFile( m_repositoryXml, root );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000291 }
292 catch ( MojoExecutionException e )
293 {
294 e.printStackTrace();
Stuart McCullocha132a142008-02-05 11:18:20 +0000295 throw new MojoExecutionException( "IOException" );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000296 }
297 }
298
299 // now we parse the repository.xml file
Stuart McCulloch80a87342008-01-27 11:04:46 +0000300 m_repositoryDoc = parseFile( m_repositoryXml, m_documentBuilder );
Stuart McCullochb721aae2008-01-27 08:16:22 +0000301 if ( m_repositoryDoc == null )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000302 {
303 return -1;
304 }
305
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000306 return 0;
307 }
308
309
310 /**
311 * transform a xml file to a xerces Document.
312 * @param filename path to the xml file
Stuart McCullochb721aae2008-01-27 08:16:22 +0000313 * @param documentBuilder DocumentBuilder get from xerces
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000314 * @return Document which describe this file
315 */
Stuart McCulloch80a87342008-01-27 11:04:46 +0000316 private Document parseFile( URI filename, DocumentBuilder documentBuilder )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000317 {
Stuart McCullochb721aae2008-01-27 08:16:22 +0000318 if ( documentBuilder == null )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000319 {
320 return null;
321 }
322 // The document is the root of the DOM tree.
323 m_logger.info( "Parsing " + filename );
324 Document doc = null;
325 try
326 {
Stuart McCullochb721aae2008-01-27 08:16:22 +0000327 doc = documentBuilder.parse( new File( filename ) );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000328 }
329 catch ( SAXException e )
330 {
331 e.printStackTrace();
332 return null;
333 }
334 catch ( IOException e )
335 {
336 m_logger.error( "cannot open file: " + filename );
337 e.printStackTrace();
338 return null;
339 }
340 return doc;
341 }
342
343
344 /**
345 * put the information from obr.xml into ressourceBundle object.
346 * @param node Node to the OBR.xml file
347 */
348 private void sortObrXml( Node node )
349 {
350 if ( node.getNodeName().compareTo( "require" ) == 0 )
351 {
352 Require newRequireNode = new Require();
353 NamedNodeMap list = node.getAttributes();
354 try
355 {
356 newRequireNode.setExtend( list.getNamedItem( "extend" ).getNodeValue() );
357 newRequireNode.setMultiple( list.getNamedItem( "multiple" ).getNodeValue() );
358 newRequireNode.setOptional( list.getNamedItem( "optional" ).getNodeValue() );
359 newRequireNode.setFilter( list.getNamedItem( "filter" ).getNodeValue() );
360 newRequireNode.setName( list.getNamedItem( "name" ).getNodeValue() );
361 }
362 catch ( NullPointerException e )
363 {
364 m_logger
365 .error( "the obr.xml file seems to be invalid in a \"require\" tag (one or more attributes are missing)" );
366 // e.printStackTrace();
367 }
368 newRequireNode.setValue( XmlHelper.getTextContent( node ) );
369 m_resourceBundle.addRequire( newRequireNode );
370 }
371 else if ( node.getNodeName().compareTo( "capability" ) == 0 )
372 {
373 Capability newCapability = new Capability();
374 try
375 {
376 newCapability.setName( node.getAttributes().getNamedItem( "name" ).getNodeValue() );
377 }
378 catch ( NullPointerException e )
379 {
380 m_logger.error( "attribute \"name\" is missing in obr.xml in a \"capability\" tag" );
381 e.printStackTrace();
382 }
383 NodeList list = node.getChildNodes();
384 for ( int i = 0; i < list.getLength(); i++ )
385 {
386 PElement p = new PElement();
387 Node n = list.item( i );
388 Node item = null;
389 // System.err.println(n.getNodeName());
390 if ( n.getNodeName().compareTo( "p" ) == 0 )
391 {
392
393 p.setN( n.getAttributes().getNamedItem( "n" ).getNodeValue() );
394 item = n.getAttributes().getNamedItem( "t" );
395 if ( item != null )
396 {
397 p.setT( item.getNodeValue() );
398 }
399 item = n.getAttributes().getNamedItem( "v" );
400 if ( item != null )
401 {
402 p.setV( item.getNodeValue() );
403 }
404
405 newCapability.addP( p );
406 }
407 }
408 m_resourceBundle.addCapability( newCapability );
409 }
410 else if ( node.getNodeName().compareTo( "category" ) == 0 )
411 {
412 Category newCategory = new Category();
413 newCategory.setId( node.getAttributes().getNamedItem( "id" ).getNodeValue() );
414 m_resourceBundle.addCategory( newCategory );
415 }
416 else
417 {
418 NodeList list = node.getChildNodes();
419 for ( int i = 0; i < list.getLength(); i++ )
420 {
421 sortObrXml( list.item( i ) );
422 }
423 }
424 }
425
426
427 /**
428 * write a Node in a xml file.
429 * @param outputFilename URI to the output file
430 * @param treeToBeWrite Node root of the tree to be write in file
431 * @throws MojoExecutionException if the plugin failed
432 */
433 private void writeToFile( URI outputFilename, Node treeToBeWrite ) throws MojoExecutionException
434 {
435 // init the transformer
436 Transformer transformer = null;
437 TransformerFactory tfabrique = TransformerFactory.newInstance();
438 try
439 {
440 transformer = tfabrique.newTransformer();
441 }
442 catch ( TransformerConfigurationException e )
443 {
444 m_logger.error( "Unable to write to file: " + outputFilename.toString() );
445 e.printStackTrace();
446 throw new MojoExecutionException( "TransformerConfigurationException" );
447 }
448 Properties proprietes = new Properties();
449 proprietes.put( "method", "xml" );
450 proprietes.put( "version", "1.0" );
451 proprietes.put( "encoding", "ISO-8859-1" );
452 proprietes.put( "standalone", "yes" );
453 proprietes.put( "indent", "yes" );
454 proprietes.put( "omit-xml-declaration", "no" );
455 transformer.setOutputProperties( proprietes );
456
457 DOMSource input = new DOMSource( treeToBeWrite );
458
459 File fichier = new File( outputFilename );
Stuart McCulloch80a87342008-01-27 11:04:46 +0000460 fichier.getParentFile().mkdirs();
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000461 FileOutputStream flux = null;
462 try
463 {
464 flux = new FileOutputStream( fichier );
465 }
466 catch ( FileNotFoundException e )
467 {
468 m_logger.error( "Unable to write to file: " + fichier.getName() );
469 e.printStackTrace();
470 throw new MojoExecutionException( "FileNotFoundException" );
471 }
472 Result output = new StreamResult( flux );
473 try
474 {
475 transformer.transform( input, output );
476 }
477 catch ( TransformerException e )
478 {
479 e.printStackTrace();
480 throw new MojoExecutionException( "TransformerException" );
481 }
482
483 try
484 {
485 flux.flush();
486 flux.close();
487 }
488 catch ( IOException e )
489 {
490 e.printStackTrace();
491 throw new MojoExecutionException( "IOException" );
492 }
493
494 }
495
496
497 /**
498 * walk on the tree until the targeted node was found.
499 * @param node targeted node
500 * @return true if the requiered node was found else false.
501 */
502 private boolean walkOnTree( Node node )
503 {
504
505 if ( node.getNodeName().compareTo( "resource" ) == 0 )
506 {
507 return resource( node );
508 }
Stuart McCullochebfe1252008-02-04 08:32:32 +0000509
510 // look at the repository node (first in the file)
511 if ( node.getNodeName().compareTo( "repository" ) == 0 )
512 {
513 Date d = new Date();
514 d.setTime( System.currentTimeMillis() );
515 NamedNodeMap nList = node.getAttributes();
516 Node n = nList.getNamedItem( "lastmodified" );
517 n.setNodeValue( m_format.format( d ) );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000518 }
519
Stuart McCullochebfe1252008-02-04 08:32:32 +0000520 NodeList list = node.getChildNodes();
521 if ( list.getLength() > 0 )
522 {
523 for ( int i = 0; i < list.getLength(); i++ )
524 {
525 if ( walkOnTree( list.item( i ) ) )
526 {
527 return true;
528 }
529 }
530 }
531
532 return false;
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000533 }
534
535
536 /**
537 * put the resource bundle in the tree.
538 * @param node Node on the xml file
539 * @param id id of the bundle ressource
540 */
541 private void searchRepository( Node node, String id )
542 {
543 if ( node.getNodeName().compareTo( "repository" ) == 0 )
544 {
Stuart McCullochb721aae2008-01-27 08:16:22 +0000545 node.appendChild( m_resourceBundle.getNode( m_repositoryDoc ) );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000546 return;
547 }
Stuart McCullochebfe1252008-02-04 08:32:32 +0000548
Stuart McCullocha132a142008-02-05 11:18:20 +0000549 m_logger.info( "Second branch..." );
Stuart McCullochebfe1252008-02-04 08:32:32 +0000550 NodeList list = node.getChildNodes();
551 if ( list.getLength() > 0 )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000552 {
Stuart McCullochebfe1252008-02-04 08:32:32 +0000553 for ( int i = 0; i < list.getLength(); i++ )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000554 {
Stuart McCullochebfe1252008-02-04 08:32:32 +0000555 searchRepository( list.item( i ), id );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000556 }
557 }
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000558 }
559
560
561 /**
562 * compare two node and update the array which compute the smallest free id.
563 * @param node : node
564 * @return true if the node is the same bundle than the ressourceBundle, else false.
565 */
566 private boolean resource( Node node )
567 {
568
569 // this part save all the id free if we need to add resource
570 String id = node.getAttributes().getNamedItem( "id" ).getNodeValue();
571 NamedNodeMap map = node.getAttributes();
572
573 if ( m_resourceBundle.isSameBundleResource( map.getNamedItem( "symbolicname" ).getNodeValue(), map
574 .getNamedItem( "version" ).getNodeValue() ) )
575 {
576 m_resourceBundle.setId( String.valueOf( id ) );
Stuart McCullochb721aae2008-01-27 08:16:22 +0000577 node.getParentNode().replaceChild( m_resourceBundle.getNode( m_repositoryDoc ), node );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000578 return true;
579 }
580 return false;
581 }
582}