private void copyFile(IStorage source, IStorage destination) { try { destination.getParentFile().mkdirs(); InputStream in = source.getInputStream(); OutputStream out = destination.getOutputStream(); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); // throw new UserException(UserException.ERROR_COPYING_USER_BASE_DIRECTORY); } }
public void save(IStorage file, org.davinci.server.review.user.Reviewer reviewer) { OutputStream out = null; try { if (!file.exists()) try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { out = file.getOutputStream(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element rootElement = document.createElement("reviewer"); document.appendChild(rootElement); Iterator<ReviewerVersion> iterator = reviewer.getReviewerVersions(); while (iterator.hasNext()) { ReviewerVersion version = iterator.next(); Element element = document.createElement("version"); element.setAttribute("designerID", version.getDesignerID()); element.setAttribute("time", version.getTimeVersion()); rootElement.appendChild(element); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); // $NON-NLS-1$ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // $NON-NLS-1$ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // $NON-NLS-1$ DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(out); transformer.transform(source, result); } catch (TransformerFactoryConfigurationError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public void save(IStorage file, org.davinci.server.review.user.IDesignerUser user) { OutputStream out = null; try { if (!file.exists()) try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { out = file.getOutputStream(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element rootElement = document.createElement("user"); document.appendChild(rootElement); Element latestVersionElement = document.createElement("latestVersion"); latestVersionElement.setAttribute("id", user.getLatestVersion().getVersionID()); latestVersionElement.setAttribute("title", user.getLatestVersion().getVersionTitle()); latestVersionElement.setAttribute("time", user.getLatestVersion().getTime()); rootElement.appendChild(latestVersionElement); for (Version version : user.getVersions()) { Element element = document.createElement("version"); element.setAttribute("id", version.getVersionID()); element.setAttribute("title", version.getVersionTitle()); element.setAttribute("time", version.getTime()); element.setAttribute("isDraft", version.isDraft() ? "true" : "false"); element.setAttribute("dueDate", version.dueDateString()); element.setAttribute("desireWidth", version.getDesireWidth() + ""); element.setAttribute("desireHeight", version.getDesireHeight() + ""); element.setAttribute( "hasClosedManually", Boolean.toString(version.isHasClosedManually())); element.setAttribute("restartFrom", version.getRestartFrom()); element.setAttribute("description", version.getDescription()); element.setAttribute("receiveEmail", version.isReceiveEmail() ? "true" : "false"); element.setAttribute("hasRestarted", version.isHasRestarted() ? "true" : "false"); for (Reviewer reviewer : version.getReviewers()) { Element reviewerElement = document.createElement("reviewer"); reviewerElement.setAttribute("name", reviewer.getUserName()); reviewerElement.setAttribute("email", reviewer.getEmail()); element.appendChild(reviewerElement); } for (String resource : version.resources) { Element resourceElement = document.createElement("resource"); resourceElement.setAttribute("path", resource); element.appendChild(resourceElement); } rootElement.appendChild(element); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); // $NON-NLS-1$ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // $NON-NLS-1$ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // $NON-NLS-1$ DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(out); transformer.transform(source, result); } catch (TransformerFactoryConfigurationError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }