public ILibInfo[] getVersionLib(IDavinciProject project, String version) { if (snapshotLibs == null) { snapshotLibs = new HashMap<IDavinciProject, HashMap<String, ILibInfo[]>>(); } HashMap<String, ILibInfo[]> versions = snapshotLibs.get(project); if (versions == null) { versions = new HashMap<String, ILibInfo[]>(); snapshotLibs.put(project, versions); } ILibInfo[] libInfos = versions.get(version); if (libInfos == null) { StringBuilder path = new StringBuilder(); path.append(baseDirectory.getAbsolutePath()); path.append("/"); path.append(project.getOwnerId()); path.append("/"); path.append(Constants.REVIEW_DIRECTORY_NAME); path.append("/snapshot/"); path.append(version); path.append("/"); path.append(project.getProjectName()); path.append("/"); path.append(IDavinciServerConstants.SETTINGS_DIRECTORY_NAME); libInfos = new LibrarySettings(this.baseDirectory.newInstance(path.toString())).allLibs(); if (libInfos != null) versions.put(version, libInfos); } return libInfos; }
public ILibInfo[] getSystemLibs(IDavinciProject project) { StringBuilder path = new StringBuilder(); path.append(baseDirectory.getAbsolutePath()); path.append("/"); path.append(project.getOwnerId()); path.append("/"); path.append(project.getProjectName()); path.append("/"); path.append(IDavinciServerConstants.SETTINGS_DIRECTORY_NAME); return new LibrarySettings(this.baseDirectory.newInstance(path.toString())).allLibs(); }
public static void addComments(List<Comment> commentList, boolean append) throws ParserConfigurationException, IOException, TransformerConfigurationException, TransformerFactoryConfigurationError { if (null == commentList || commentList.isEmpty()) return; // Cache the DOM document, since comments may be from different project, // with this cache, XML files need not to be loaded multiple times. Map<String, StringBuffer> xmlFragmentMap = new HashMap<String, StringBuffer>(); IDavinciProject prj; StringBuffer xmlFragment; DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document doc = builder.newDocument(); Source source = null; OutputStream os = null; Result result = null; Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.setOutputProperty(OutputKeys.METHOD, "xml"); // $NON-NLS-1$ xformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // $NON-NLS-1$ xformer.setOutputProperty(OutputKeys.INDENT, "yes"); // $NON-NLS-1$ for (Comment comm : commentList) { prj = comm.getProject(); if (null == prj) continue; xmlFragment = xmlFragmentMap.get(prj.getCommentFilePath()); if (null == xmlFragment) { xmlFragment = new StringBuffer(); xmlFragmentMap.put(prj.getCommentFilePath(), xmlFragment); } try { source = new DOMSource(createCommentElem(comm, doc)); os = new ByteArrayOutputStream(); result = new StreamResult(os); xformer.transform(source, result); xmlFragment.append(os.toString()); } catch (TransformerException e) { e.printStackTrace(); } finally { if (os != null) os.close(); } } Set<Entry<String, StringBuffer>> entrySet = xmlFragmentMap.entrySet(); for (Entry<String, StringBuffer> entry : entrySet) { persist(entry.getValue().toString(), entry.getKey(), append); } }
public Document marshall(boolean append) throws ParserConfigurationException, IOException, TransformerConfigurationException, TransformerFactoryConfigurationError { Marshaller.addComments(project.getCommentsDocument().getCommentList(), append); return null; }
public static IPath adjustPath(IPath path, String ownerId, String version, String projectName) { // Map the request lib path stored in the snapshot to the actual system lib path // A path like: project1/./lib/dojo/dojo.js IReviewManager reviewManager = ReviewManager.getReviewManager(); IDavinciProject project = new DavinciProject(); project.setOwnerId(ownerId); project.setProjectName(projectName); ILibInfo[] sysLibs = reviewManager.getSystemLibs(project); ILibInfo[] versionLibs = reviewManager.getVersionLib(project, version); // If the lib path is not specified in the review version, // just return the path if (versionLibs == null) return path; IPath cp = new Path(path.toString()); IPath newPath = new Path(cp.segment(0)); cp = cp.removeFirstSegments(1); int c = 0; while (cp.segment(0).equals(".") || cp.segment(0).equals("..")) { c++; } cp = cp.removeFirstSegments(c); for (ILibInfo info : versionLibs) { if (info.getVirtualRoot() == null) { continue; } IPath versionVirtualRoot = new Path(info.getVirtualRoot()); if (cp.matchingFirstSegments(versionVirtualRoot) == versionVirtualRoot.segmentCount()) { String virtualRoot = null; for (ILibInfo lib : sysLibs) { if (lib.getId().equals(info.getId())) { virtualRoot = lib.getVirtualRoot(); break; } } if (virtualRoot != null) { IPath vr = newPath.append(virtualRoot); return vr.append(cp.removeFirstSegments(versionVirtualRoot.segmentCount())); } break; } } return path; }