Lines 58-63
Link Here
|
58 |
import org.w3c.dom.Text; |
58 |
import org.w3c.dom.Text; |
59 |
import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType; |
59 |
import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType; |
60 |
import org.netbeans.modules.java.api.common.util.CommonProjectUtils; |
60 |
import org.netbeans.modules.java.api.common.util.CommonProjectUtils; |
|
|
61 |
import org.openide.xml.XMLUtil; |
61 |
|
62 |
|
62 |
/** |
63 |
/** |
63 |
* |
64 |
* |
Lines 95-101
Link Here
|
95 |
for ( int i = 0; i < libs.getLength(); i++ ) { |
96 |
for ( int i = 0; i < libs.getLength(); i++ ) { |
96 |
Element item = (Element)libs.item( i ); |
97 |
Element item = (Element)libs.item( i ); |
97 |
// ejbjar is different from other j2ee projects - it stores reference without ${ and } |
98 |
// ejbjar is different from other j2ee projects - it stores reference without ${ and } |
98 |
String ref = "${"+findText( item )+"}"; |
99 |
String ref = "${"+XMLUtil.findText( item )+"}"; |
99 |
libraries.add(ref); // NOI18N |
100 |
libraries.add(ref); // NOI18N |
100 |
String dirs = item.getAttribute(ATTR_DIRS); |
101 |
String dirs = item.getAttribute(ATTR_DIRS); |
101 |
if (Util.DESTINATION_DIRECTORY_ROOT.equals(dirs) || |
102 |
if (Util.DESTINATION_DIRECTORY_ROOT.equals(dirs) || |
Lines 125-131
Link Here
|
125 |
Document doc = data.getOwnerDocument(); |
126 |
Document doc = data.getOwnerDocument(); |
126 |
for (ClassPathSupport.Item item : classpath) { |
127 |
for (ClassPathSupport.Item item : classpath) { |
127 |
if("true".equals(item.getAdditionalProperty(INCLUDE_IN_DEPLOYMENT))) { // NOI18N |
128 |
if("true".equals(item.getAdditionalProperty(INCLUDE_IN_DEPLOYMENT))) { // NOI18N |
128 |
appendChildElement(data, |
129 |
XMLUtil.appendChildElement(data, |
129 |
createLibraryElement(antProjectHelper, doc, item, includedLibrariesElement), |
130 |
createLibraryElement(antProjectHelper, doc, item, includedLibrariesElement), |
130 |
ejbjarElemOrder); |
131 |
ejbjarElemOrder); |
131 |
} |
132 |
} |
Lines 134-195
Link Here
|
134 |
antProjectHelper.putPrimaryConfigurationData( data, true ); |
135 |
antProjectHelper.putPrimaryConfigurationData( data, true ); |
135 |
} |
136 |
} |
136 |
|
137 |
|
137 |
/** |
|
|
138 |
* Find all direct child elements of an element. |
139 |
* More useful than {@link Element#getElementsByTagNameNS} because it does |
140 |
* not recurse into recursive child elements. |
141 |
* Children which are all-whitespace text nodes are ignored; others cause |
142 |
* an exception to be thrown. |
143 |
* @param parent a parent element in a DOM tree |
144 |
* @return a list of direct child elements (may be empty) |
145 |
* @throws IllegalArgumentException if there are non-element children besides whitespace |
146 |
*/ |
147 |
private static List<Element> findSubElements(Element parent) throws IllegalArgumentException { |
148 |
NodeList l = parent.getChildNodes(); |
149 |
List<Element> elements = new ArrayList<Element>(l.getLength()); |
150 |
for (int i = 0; i < l.getLength(); i++) { |
151 |
Node n = l.item(i); |
152 |
if (n.getNodeType() == Node.ELEMENT_NODE) { |
153 |
elements.add((Element)n); |
154 |
} else if (n.getNodeType() == Node.TEXT_NODE) { |
155 |
String text = ((Text)n).getNodeValue(); |
156 |
if (text.trim().length() > 0) { |
157 |
throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N |
158 |
} |
159 |
} else if (n.getNodeType() == Node.COMMENT_NODE) { |
160 |
// skip |
161 |
} else { |
162 |
throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N |
163 |
} |
164 |
} |
165 |
return elements; |
166 |
} |
167 |
|
168 |
/** |
169 |
* Append child element to the correct position according to given |
170 |
* order. |
171 |
* @param parent parent to which the child will be added |
172 |
* @param el element to be added |
173 |
* @param order order of the elements which must be followed |
174 |
*/ |
175 |
private static void appendChildElement(Element parent, Element el, String[] order) { |
176 |
Element insertBefore = null; |
177 |
List l = Arrays.asList(order); |
178 |
int index = l.indexOf(el.getLocalName()); |
179 |
assert index != -1 : el.getLocalName()+" was not found in "+l; // NOI18N |
180 |
Iterator it = findSubElements(parent).iterator(); |
181 |
while (it.hasNext()) { |
182 |
Element e = (Element)it.next(); |
183 |
int index2 = l.indexOf(e.getLocalName()); |
184 |
assert index2 != -1 : e.getLocalName()+" was not found in "+l; // NOI18N |
185 |
if (index2 > index) { |
186 |
insertBefore = e; |
187 |
break; |
188 |
} |
189 |
} |
190 |
parent.insertBefore(el, insertBefore); |
191 |
} |
192 |
|
193 |
private static Element createLibraryElement(AntProjectHelper antProjectHelper, Document doc, Item item, String includedLibrariesElement) { |
138 |
private static Element createLibraryElement(AntProjectHelper antProjectHelper, Document doc, Item item, String includedLibrariesElement) { |
194 |
Element libraryElement = doc.createElementNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement ); |
139 |
Element libraryElement = doc.createElementNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement ); |
195 |
// ejbjar is different from other j2ee projects - it stores reference without ${ and } |
140 |
// ejbjar is different from other j2ee projects - it stores reference without ${ and } |
Lines 197-220
Link Here
|
197 |
Util.updateDirsAttributeInCPSItem(item, libraryElement); |
142 |
Util.updateDirsAttributeInCPSItem(item, libraryElement); |
198 |
return libraryElement; |
143 |
return libraryElement; |
199 |
} |
144 |
} |
200 |
|
|
|
201 |
/** |
202 |
* Extracts <b>the first</b> nested text from an element. |
203 |
* Currently does not handle coalescing text nodes, CDATA sections, etc. |
204 |
* @param parent a parent element |
205 |
* @return the nested text, or null if none was found |
206 |
*/ |
207 |
private static String findText( Element parent ) { |
208 |
NodeList l = parent.getChildNodes(); |
209 |
for ( int i = 0; i < l.getLength(); i++ ) { |
210 |
if ( l.item(i).getNodeType() == Node.TEXT_NODE ) { |
211 |
Text text = (Text)l.item( i ); |
212 |
return text.getNodeValue(); |
213 |
} |
214 |
} |
215 |
return null; |
216 |
} |
217 |
|
218 |
|
145 |
|
219 |
public void readAdditionalProperties(List<Item> items, String projectXMLElement) { |
146 |
public void readAdditionalProperties(List<Item> items, String projectXMLElement) { |
220 |
Map<String, String> destination = new HashMap<String, String>(); |
147 |
Map<String, String> destination = new HashMap<String, String>(); |