001/* 002 * (C) Copyright 2011 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * tdelprat 016 * 017 */ 018package org.nuxeo.wizard.helpers; 019 020import java.io.File; 021import java.io.FileWriter; 022import java.io.IOException; 023 024import org.nuxeo.launcher.config.ConfigurationGenerator; 025import org.nuxeo.wizard.context.Context; 026import org.nuxeo.wizard.context.ParamCollector; 027 028public class ConnectRegistrationHelper { 029 030 public static boolean isConnectRegistrationFileAlreadyPresent(Context ctx) { 031 String connectRegistrationFilePath = getConnectRegistrationFile(ctx); 032 return new File(connectRegistrationFilePath).exists(); 033 } 034 035 public static String getConnectRegistrationFile(Context ctx) { 036 ParamCollector collector = ctx.getCollector(); 037 ConfigurationGenerator cg = collector.getConfigurationGenerator(); 038 String regTargetPath = cg.getDataDir().getAbsolutePath(); // cg.getRuntimeHome(); 039 040 if (!regTargetPath.endsWith("/")) { 041 regTargetPath = regTargetPath + "/"; 042 } 043 044 String connectRegistrationFilePath = regTargetPath + "instance.clid"; 045 046 return connectRegistrationFilePath; 047 } 048 049 public static void saveConnectRegistrationFile(Context ctx) throws IOException { 050 051 String connectRegistrationFilePath = getConnectRegistrationFile(ctx); 052 053 String CLID1 = Context.getConnectMap().get("CLID").split("--")[0]; 054 String CLID2 = Context.getConnectMap().get("CLID").split("--")[1]; 055 String regFileContent = CLID1 + "\n" + CLID2 + "\nnew instance"; 056 057 File regFile = new File(connectRegistrationFilePath); 058 FileWriter writer = new FileWriter(regFile); 059 writer.write(regFileContent); 060 writer.close(); 061 } 062 063}