Lines 60-65
Link Here
|
60 |
import org.netbeans.spi.project.support.ant.EditableProperties; |
60 |
import org.netbeans.spi.project.support.ant.EditableProperties; |
61 |
import org.openide.filesystems.FileObject; |
61 |
import org.openide.filesystems.FileObject; |
62 |
import org.openide.filesystems.FileUtil; |
62 |
import org.openide.filesystems.FileUtil; |
|
|
63 |
import org.openide.xml.XMLUtil; |
63 |
import org.w3c.dom.Comment; |
64 |
import org.w3c.dom.Comment; |
64 |
import org.w3c.dom.Document; |
65 |
import org.w3c.dom.Document; |
65 |
import org.w3c.dom.NamedNodeMap; |
66 |
import org.w3c.dom.NamedNodeMap; |
Lines 159-165
Link Here
|
159 |
if(oldRoot != null) { |
160 |
if(oldRoot != null) { |
160 |
Document doc = oldRoot.getOwnerDocument(); |
161 |
Document doc = oldRoot.getOwnerDocument(); |
161 |
Element newRoot = doc.createElementNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N |
162 |
Element newRoot = doc.createElementNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N |
162 |
copyDocument(doc, oldRoot, newRoot); |
163 |
XMLUtil.copyDocument(doc, oldRoot, newRoot, EarProjectType.PROJECT_CONFIGURATION_NAMESPACE); |
163 |
|
164 |
|
164 |
//update <web-module-/additional/-libraries/> to <j2ee-module-/additional/-libraries/> |
165 |
//update <web-module-/additional/-libraries/> to <j2ee-module-/additional/-libraries/> |
165 |
// NodeList contList = newRoot.getElementsByTagNameNS(ns, "web-module-libraries"); |
166 |
// NodeList contList = newRoot.getElementsByTagNameNS(ns, "web-module-libraries"); |
Lines 173-179
Link Here
|
173 |
Element library = (Element) libList.item(i); |
174 |
Element library = (Element) libList.item(i); |
174 |
Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0); |
175 |
Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0); |
175 |
//remove ${ and } from the beginning and end |
176 |
//remove ${ and } from the beginning and end |
176 |
String webFileText = findText(webFile); |
177 |
String webFileText = XMLUtil.findText(webFile); |
177 |
webFileText = webFileText.substring(2, webFileText.length() - 1); |
178 |
webFileText = webFileText.substring(2, webFileText.length() - 1); |
178 |
if (webFileText.startsWith("libs.")) { |
179 |
if (webFileText.startsWith("libs.")) { |
179 |
String libName = webFileText.substring(5, webFileText.indexOf(".classpath")); //NOI18N |
180 |
String libName = webFileText.substring(5, webFileText.indexOf(".classpath")); //NOI18N |
Lines 209-265
Link Here
|
209 |
return cachedElement; |
210 |
return cachedElement; |
210 |
} |
211 |
} |
211 |
|
212 |
|
212 |
private static void copyDocument (Document doc, Element from, Element to) { |
|
|
213 |
NodeList nl = from.getChildNodes(); |
214 |
int length = nl.getLength(); |
215 |
for (int i=0; i< length; i++) { |
216 |
Node node = nl.item (i); |
217 |
Node newNode = null; |
218 |
switch (node.getNodeType()) { |
219 |
case Node.ELEMENT_NODE: |
220 |
Element oldElement = (Element) node; |
221 |
newNode = doc.createElementNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); |
222 |
NamedNodeMap m = oldElement.getAttributes(); |
223 |
Element newElement = (Element) newNode; |
224 |
for (int index = 0; index < m.getLength(); index++) { |
225 |
Node attr = m.item(index); |
226 |
newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); |
227 |
} |
228 |
copyDocument(doc,oldElement,(Element)newNode); |
229 |
break; |
230 |
case Node.TEXT_NODE: |
231 |
Text oldText = (Text) node; |
232 |
newNode = doc.createTextNode(oldText.getData()); |
233 |
break; |
234 |
case Node.COMMENT_NODE: |
235 |
Comment oldComment = (Comment) node; |
236 |
newNode = doc.createComment(oldComment.getData()); |
237 |
break; |
238 |
} |
239 |
if (newNode != null) { |
240 |
to.appendChild (newNode); |
241 |
} |
242 |
} |
243 |
} |
244 |
|
245 |
/** |
246 |
* Extract nested text from a node. |
247 |
* Currently does not handle coalescing text nodes, CDATA sections, etc. |
248 |
* @param parent a parent node |
249 |
* @return the nested text, or null if none was found |
250 |
*/ |
251 |
private static String findText(Node parent) { |
252 |
NodeList l = parent.getChildNodes(); |
253 |
for (int i = 0; i < l.getLength(); i++) { |
254 |
if (l.item(i).getNodeType() == Node.TEXT_NODE) { |
255 |
Text text = (Text)l.item(i); |
256 |
return text.getNodeValue(); |
257 |
} |
258 |
} |
259 |
return null; |
260 |
} |
261 |
|
262 |
|
263 |
public EditableProperties getUpdatedProjectProperties() { |
213 |
public EditableProperties getUpdatedProjectProperties() { |
264 |
return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); |
214 |
return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); |
265 |
} |
215 |
} |