Lines 104-109
Link Here
|
104 |
DTD_MAP.put ("-//NetBeans//DTD Filesystem 1.1//EN", "org/openide/filesystems/filesystem1_1.dtd");//NOI18N |
104 |
DTD_MAP.put ("-//NetBeans//DTD Filesystem 1.1//EN", "org/openide/filesystems/filesystem1_1.dtd");//NOI18N |
105 |
} |
105 |
} |
106 |
|
106 |
|
|
|
107 |
|
107 |
/** Constructor. Creates new XMLFileSystem */ |
108 |
/** Constructor. Creates new XMLFileSystem */ |
108 |
public XMLFileSystem() { |
109 |
public XMLFileSystem() { |
109 |
Impl impl = new Impl (this); |
110 |
Impl impl = new Impl (this); |
Lines 202-207
Link Here
|
202 |
} |
203 |
} |
203 |
|
204 |
|
204 |
private synchronized void setXmlUrls (URL[] urls, boolean validate) throws IOException, PropertyVetoException { |
205 |
private synchronized void setXmlUrls (URL[] urls, boolean validate) throws IOException, PropertyVetoException { |
|
|
206 |
long time = System.currentTimeMillis(); |
205 |
ResourceElem rootElem; |
207 |
ResourceElem rootElem; |
206 |
String oldDisplayName = getDisplayName (); |
208 |
String oldDisplayName = getDisplayName (); |
207 |
if (urls.length == 0) { |
209 |
if (urls.length == 0) { |
Lines 241-247
Link Here
|
241 |
handler.urlContext = act; |
243 |
handler.urlContext = act; |
242 |
xp.parse(act.toString()); |
244 |
xp.parse(act.toString()); |
243 |
} |
245 |
} |
|
|
246 |
time = System.currentTimeMillis() - time; |
247 |
System.err.println("Parsing took " + time + "ms"); |
248 |
time = System.currentTimeMillis(); |
244 |
refreshChildrenInAtomicAction ((AbstractFolder)getRoot (),rootElem ); |
249 |
refreshChildrenInAtomicAction ((AbstractFolder)getRoot (),rootElem ); |
|
|
250 |
time = System.currentTimeMillis() - time; |
251 |
System.err.println("Notifying took " + time + "ms"); |
245 |
} catch (IOException iox) { |
252 |
} catch (IOException iox) { |
246 |
urlsToXml = origUrls; |
253 |
urlsToXml = origUrls; |
247 |
throw iox; |
254 |
throw iox; |
Lines 250-260
Link Here
|
250 |
ExternalUtil.copyAnnotation (x,e); |
257 |
ExternalUtil.copyAnnotation (x,e); |
251 |
throw x; |
258 |
throw x; |
252 |
} finally { |
259 |
} finally { |
|
|
260 |
writeOut(rootElem); |
253 |
rootElem = null; |
261 |
rootElem = null; |
254 |
} |
262 |
} |
255 |
firePropertyChange (PROP_DISPLAY_NAME, oldDisplayName, getDisplayName ()); |
263 |
firePropertyChange (PROP_DISPLAY_NAME, oldDisplayName, getDisplayName ()); |
256 |
} |
264 |
} |
257 |
|
265 |
|
|
|
266 |
|
267 |
private String space(int n) { |
268 |
return " ".substring(0,2*n); |
269 |
} |
270 |
|
271 |
private void writeOut(ResourceElem root) throws IOException { |
272 |
Writer wr = new OutputStreamWriter(new FileOutputStream("/tmp/all.xml")); |
273 |
wr.write("<!DOCTYPE filesystem PUBLIC \"-//NetBeans//DTD Filesystem 1.0//EN\" \"http://www.netbeans.org/dtds/filesystem-1_0.dtd\">\n"); |
274 |
wr.write("<filesystem>\n"); |
275 |
writeFolder(wr,root,1); |
276 |
wr.write("</filesystem>\n"); |
277 |
wr.flush(); |
278 |
wr.close(); |
279 |
} |
280 |
|
281 |
private void writeFolder( Writer wr, ResourceElem elem, int depth) throws IOException { |
282 |
if(elem.children == null) return; |
283 |
Iterator it = new TreeSet(elem.children.keySet()).iterator(); |
284 |
|
285 |
while(it.hasNext()) { |
286 |
String name = (String)it.next(); |
287 |
ResourceElem child = (ResourceElem)elem.children.get(name); |
288 |
|
289 |
if(child.isFolder()) { |
290 |
wr.write(space(depth) + "<folder name='" + name + "'"); |
291 |
if(writeAttrs(wr, child.getAttr(false), depth+1)) { |
292 |
wr.write(">\n"); |
293 |
} |
294 |
writeFolder(wr, child, depth+1); |
295 |
wr.write(space(depth) + "</folder>\n"); |
296 |
} else { |
297 |
String uri = child.getURI(); |
298 |
boolean empty = true; |
299 |
if(uri != null) { |
300 |
wr.write(space(depth) + "<file name='" + name + "' url='" + uri + "'"); |
301 |
} else { |
302 |
wr.write(space(depth) + "<file name='" + name + "'"); |
303 |
} |
304 |
|
305 |
byte[] content = child.getContent(); |
306 |
if(content != null) { |
307 |
empty = false; |
308 |
wr.write("><![CDATA[" + new String(content) + "]]"); |
309 |
if(writeAttrs(wr, child.getAttr(false), depth+1)) { |
310 |
wr.write(">\n"); |
311 |
} |
312 |
} else { |
313 |
empty &= writeAttrs(wr, child.getAttr(false), depth+1); |
314 |
} |
315 |
if(empty) { |
316 |
wr.write("/>\n"); |
317 |
} else { |
318 |
wr.write(space(depth) + "</file>\n"); |
319 |
} |
320 |
} |
321 |
} |
322 |
|
323 |
} |
324 |
|
325 |
private boolean writeAttrs( Writer wr, XMLMapAttr attrs, int depth) throws IOException { |
326 |
if (attrs == null) return true; // empty attrs |
327 |
|
328 |
Iterator attri = new TreeSet(attrs.map.keySet()).iterator(); |
329 |
if(!attri.hasNext()) return true; |
330 |
|
331 |
wr.write(">\n"); |
332 |
while(attri.hasNext()) { |
333 |
String aname = (String)attri.next(); |
334 |
XMLMapAttr.Attr a = (XMLMapAttr.Attr)attrs.map.get(aname); |
335 |
wr.write(space(depth) + "<attr name='" + aname + "' " + a.getKey() + "=\"" + a.getValue() + "\"/>\n"); |
336 |
} |
337 |
|
338 |
return false; |
339 |
} |
340 |
|
258 |
/** |
341 |
/** |
259 |
* @return if value of lastModified should be cached |
342 |
* @return if value of lastModified should be cached |
260 |
*/ |
343 |
*/ |