コード例 #1
0
 private static void filterProjectXML(FileObject fo, ZipInputStream str, String name)
     throws IOException {
   try {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     FileUtil.copy(str, baos);
     Document doc =
         XMLUtil.parse(
             new InputSource(new ByteArrayInputStream(baos.toByteArray())),
             false,
             false,
             null,
             null);
     NodeList nl = doc.getDocumentElement().getElementsByTagName("name");
     if (nl != null) {
       for (int i = 0; i < nl.getLength(); i++) {
         Element el = (Element) nl.item(i);
         if (el.getParentNode() != null && "data".equals(el.getParentNode().getNodeName())) {
           NodeList nl2 = el.getChildNodes();
           if (nl2.getLength() > 0) {
             nl2.item(0).setNodeValue(name);
           }
           break;
         }
       }
     }
     OutputStream out = fo.getOutputStream();
     try {
       XMLUtil.write(doc, out, "UTF-8");
     } finally {
       out.close();
     }
   } catch (Exception ex) {
     Exceptions.printStackTrace(ex);
     writeFile(str, fo);
   }
 }