001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.xslt.project.wizard;
020:
021: import java.io.File;
022: import java.io.IOException;
023: import java.util.Iterator;
024: import java.util.Set;
025: import org.netbeans.api.project.Project;
026: import org.netbeans.api.project.ProjectManager;
027: import org.netbeans.modules.compapp.projects.base.ui.wizards.NewIcanproProjectWizardIterator;
028: import org.netbeans.modules.xslt.project.XsltproProjectGenerator;
029: import org.netbeans.modules.xslt.tmap.util.Util;
030: import org.openide.filesystems.FileObject;
031: import org.openide.filesystems.FileUtil;
032: import org.openide.filesystems.Repository;
033: import static org.netbeans.modules.xslt.project.XsltproConstants.*;
034: import org.openide.util.NbBundle;
035: import org.netbeans.modules.soa.ui.SoaUiUtil;
036: import org.openide.loaders.DataObject;
037:
038: /**
039: * Iterator for a wizard that needs to instantiate new xslt object.
040: * @author Vitaly Bychkov
041: * @version 1.0
042: */
043: public class NewXsltproProjectWizardIterator extends
044: NewIcanproProjectWizardIterator {
045:
046: private static final long serialVersionUID = 1L;
047:
048: public NewXsltproProjectWizardIterator() {
049: super ();
050: }
051:
052: @Override
053: public Set instantiate() throws IOException {
054: Set set = super .instantiate();
055: createTMapFile(set);
056: return set;
057: }
058:
059: @Override
060: protected void createProject(File dirF, String name,
061: String j2eeLevel) throws IOException {
062: XsltproProjectGenerator.createProject(dirF, name);
063: }
064:
065: @Override
066: protected String getDefaultTitle() {
067: return NbBundle.getMessage(
068: NewXsltproProjectWizardIterator.class,
069: "LBL_XSLT_Wizard_Title"); //NOI18N
070: }
071:
072: @Override
073: protected String getDefaultName() {
074: return NbBundle.getMessage(
075: NewXsltproProjectWizardIterator.class,
076: "LBL_NPW1_DefaultProjectName"); //NOI18N
077: }
078:
079: private void createTMapFile(Set resultSet) throws IOException {
080:
081: if (resultSet == null || resultSet.isEmpty()) {
082: return;
083: }
084:
085: FileObject fo = null;
086: Iterator setIterator = resultSet.iterator();
087: while (setIterator.hasNext()) {
088: Object obj = setIterator.next();
089: if (obj instanceof FileObject) {
090: fo = (FileObject) obj;
091: break;
092: }
093: }
094: Project p = ProjectManager.getDefault().findProject(fo);
095: if (p != null) {
096: FileObject srcFo = Util.getProjectSource(p);
097: FileObject tMapFo = FileUtil.copyFile(Repository
098: .getDefault().getDefaultFileSystem().findResource(
099: "org-netbeans-xsltpro/transformmap.xml"), //NOI18N
100: srcFo, "transformmap"); //NOI18N
101:
102: SoaUiUtil.fixEncoding(DataObject.find(tMapFo), srcFo);
103: }
104: }
105: }
|