Lines 69-81
Link Here
|
69 |
import org.openide.filesystems.URLMapper; |
69 |
import org.openide.filesystems.URLMapper; |
70 |
import org.openide.util.Mutex; |
70 |
import org.openide.util.Mutex; |
71 |
import org.openide.util.NbBundle; |
71 |
import org.openide.util.NbBundle; |
72 |
import org.w3c.dom.Comment; |
72 |
import org.openide.xml.XMLUtil; |
73 |
import org.w3c.dom.Document; |
73 |
import org.w3c.dom.Document; |
74 |
import org.w3c.dom.Element; |
74 |
import org.w3c.dom.Element; |
75 |
import org.w3c.dom.NamedNodeMap; |
|
|
76 |
import org.w3c.dom.Node; |
75 |
import org.w3c.dom.Node; |
77 |
import org.w3c.dom.NodeList; |
76 |
import org.w3c.dom.NodeList; |
78 |
import org.w3c.dom.Text; |
|
|
79 |
|
77 |
|
80 |
/** |
78 |
/** |
81 |
* |
79 |
* |
Lines 295-301
Link Here
|
295 |
if (oldRoot != null) { |
293 |
if (oldRoot != null) { |
296 |
Document doc = oldRoot.getOwnerDocument(); |
294 |
Document doc = oldRoot.getOwnerDocument(); |
297 |
Element newRoot = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N |
295 |
Element newRoot = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N |
298 |
copyDocument (doc, oldRoot, newRoot); |
296 |
XMLUtil.copyDocument (doc, oldRoot, newRoot, WebProjectType.PROJECT_CONFIGURATION_NAMESPACE); |
299 |
if (version == 1) { |
297 |
if (version == 1) { |
300 |
//1->2 upgrade |
298 |
//1->2 upgrade |
301 |
Element sourceRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N |
299 |
Element sourceRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N |
Lines 317-323
Link Here
|
317 |
Element library = (Element) libList.item(i); |
315 |
Element library = (Element) libList.item(i); |
318 |
Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0); |
316 |
Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0); |
319 |
//remove ${ and } from the beginning and end |
317 |
//remove ${ and } from the beginning and end |
320 |
String webFileText = findText(webFile); |
318 |
String webFileText = XMLUtil.findText(webFile); |
321 |
webFileText = webFileText.substring(2, webFileText.length() - 1); |
319 |
webFileText = webFileText.substring(2, webFileText.length() - 1); |
322 |
// warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? findText((Element) pathInWarElements.item(0)) : Item.PATH_IN_WAR_NONE); |
320 |
// warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? findText((Element) pathInWarElements.item(0)) : Item.PATH_IN_WAR_NONE); |
323 |
if (webFileText.startsWith ("lib.")) { |
321 |
if (webFileText.startsWith ("lib.")) { |
Lines 375-430
Link Here
|
375 |
} |
373 |
} |
376 |
} |
374 |
} |
377 |
|
375 |
|
378 |
/** |
|
|
379 |
* Extract nested text from a node. |
380 |
* Currently does not handle coalescing text nodes, CDATA sections, etc. |
381 |
* @param parent a parent node |
382 |
* @return the nested text, or null if none was found |
383 |
*/ |
384 |
private static String findText(Node parent) { |
385 |
NodeList l = parent.getChildNodes(); |
386 |
for (int i = 0; i < l.getLength(); i++) { |
387 |
if (l.item(i).getNodeType() == Node.TEXT_NODE) { |
388 |
Text text = (Text)l.item(i); |
389 |
return text.getNodeValue(); |
390 |
} |
391 |
} |
392 |
return null; |
393 |
} |
394 |
|
395 |
private static void copyDocument (Document doc, Element from, Element to) { |
396 |
NodeList nl = from.getChildNodes(); |
397 |
int length = nl.getLength(); |
398 |
for (int i=0; i< length; i++) { |
399 |
Node node = nl.item (i); |
400 |
Node newNode = null; |
401 |
switch (node.getNodeType()) { |
402 |
case Node.ELEMENT_NODE: |
403 |
Element oldElement = (Element) node; |
404 |
newNode = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); |
405 |
NamedNodeMap m = oldElement.getAttributes(); |
406 |
Element newElement = (Element) newNode; |
407 |
for (int index = 0; index < m.getLength(); index++) { |
408 |
Node attr = m.item(index); |
409 |
newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); |
410 |
} |
411 |
copyDocument(doc,oldElement,(Element)newNode); |
412 |
break; |
413 |
case Node.TEXT_NODE: |
414 |
Text oldText = (Text) node; |
415 |
newNode = doc.createTextNode(oldText.getData()); |
416 |
break; |
417 |
case Node.COMMENT_NODE: |
418 |
Comment oldComment = (Comment) node; |
419 |
newNode = doc.createComment(oldComment.getData()); |
420 |
break; |
421 |
} |
422 |
if (newNode != null) { |
423 |
to.appendChild (newNode); |
424 |
} |
425 |
} |
426 |
} |
427 |
|
428 |
private static Element updateMinAntVersion (final Element root, final Document doc) { |
376 |
private static Element updateMinAntVersion (final Element root, final Document doc) { |
429 |
NodeList list = root.getElementsByTagNameNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,TAG_MINIMUM_ANT_VERSION); |
377 |
NodeList list = root.getElementsByTagNameNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,TAG_MINIMUM_ANT_VERSION); |
430 |
if (list.getLength() == 1) { |
378 |
if (list.getLength() == 1) { |