Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
   *
   * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   * Other names may be trademarks of their respective owners.
   *
   * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common
  * Development and Distribution License("CDDL") (collectively, the
  * "License"). You may not use this file except in compliance with the
  * License. You can obtain a copy of the License at
  * http://www.netbeans.org/cddl-gplv2.html
  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  * specific language governing permissions and limitations under the
  * License.  When distributing the software, include this License Header
  * Notice in each file and include the License file at
  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Oracle in the GPL Version 2 section of the License file that
  * accompanied this code. If applicable, add the following below the
  * License Header, with the fields enclosed by brackets [] replaced by
  * your own identifying information:
  * "Portions Copyrighted [year] [name of copyright owner]"
  *
  * Contributor(s):
  *
  * The Original Software is NetBeans. The Initial Developer of the Original
  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
  * Microsystems, Inc. All Rights Reserved.
  *
  * If you wish your version of this file to be governed by only the CDDL
  * or only the GPL Version 2, indicate your decision by adding
  * "[Contributor] elects to include this software in this distribution
  * under the [CDDL or GPL Version 2] license." If you do not indicate a
  * single choice of license, a recipient has the option to distribute
  * your version of this file under either the CDDL, the GPL Version 2 or
  * to extend the choice of license to its licensees as provided above.
  * However, if you add GPL Version 2 code and therefore, elected the GPL
  * Version 2 license, then the option applies only if the new code is
  * made subject to such option by the copyright holder.
  */
 package org.netbeans.modules.xml.jaxb.ui;
 
 import java.io.File;
 import java.util.List;
 import java.util.Map;
 

Author(s):
gmpatil
 
 public class JAXBWizBindingCfgPanel implements WizardDescriptor.Panel,
                                         WizardDescriptor.ValidatingPanel
                                         WizardDescriptor.FinishablePanel{
     public static final int MODE_WIZARD  = 0;
     public static final int MODE_EDITING = 1;
     private static final String WIZ_NEW_FILE_TITLE = "NewFileWizard_Title"//NOI18N
 
     private WizardDescriptor wd = null;
     private List<ChangeListenerlisteners = new ArrayList<ChangeListener>();  
     private JAXBBindingInfoPnl bindingInfoPnl = null;
     private List<StringexistingSchemaNames = null;
     private File projDir = null;
     private Logger logger;
     
     public JAXBWizBindingCfgPanel() {
          = Logger.getLogger(this.getClass().getName());
         initUI();
     }
         
     private void initUI() {
          = new JAXBBindingInfoPnl(this);
         .setName(NbBundle.getMessage(this.getClass(), 
                 "LBL_JAXBWizTitle")); //NOI18N        
     }
         
     public void removeChangeListener(ChangeListener cl) {
         this..removecl );
     }
     
     public void addChangeListener(ChangeListener cl) {
         this..addcl );
     }
 
    public void validate() throws WizardValidationException {
        .log(."validate() called.");
    }
    private boolean isEmpty(String str){
        boolean ret = true;
        if ((str != null) && (!"".equals(str.trim()))){ //NOI18N
            ret = false;
        }
        return ret;
    }
    
    private void setError(String msg){
        this..putProperty(.msg);  
    }
    
    private boolean isValid(StringBuffer sb){
        .log(."isValidate() called.");        
        boolean valid = true;
        
        if (isEmpty(this..getSchemaName())){
            sb.append(NbBundle.getMessage(this.getClass(),
                    "MSG_EnterSchemaName")); //NOI18N
            valid = false;
            setError(sb.toString());
            return valid;
        } else {
            String schemaName = this..getSchemaName();
            if ((this. != null) && 
                    (this..contains(schemaName))){
                sb.append(NbBundle.getMessage(this.getClass(),
                        "MSG_SchemaNameExists")); //NOI18N
                valid = false;
                setError(sb.toString());
                return valid;                
            }
            
            // Do not allow characters (,.\\/;:)
            if ((schemaName.indexOf(",") > -1) ||           //NOI18N
                    (schemaName.indexOf(".") > -1)  ||      //NOI18N  
                    (schemaName.indexOf("\\") > -1) ||      //NOI18N
                    (schemaName.indexOf("/") > -1)  ||      //NOI18N
                    (schemaName.indexOf(";") > -1)  ||      //NOI18N
                    (schemaName.indexOf(":") > -1)  ){      //NOI18N  
                sb.append(NbBundle.getMessage(this.getClass(),
                        "MSG_InvalidCharInSchemaName")); //NOI18N
                valid = false;
                setError(sb.toString());
                return valid;                
            }
        }
        
        if ( isEmpty(this..getSchemaFile())
                && isEmpty(this..getSchemaURL())){
            sb.append(NbBundle.getMessage(this.getClass(), 
                    "MSG_EnterSchemaFileOrURL")); //NOI18N
            valid = false;
            setError(sb.toString());
            return valid;
        }else {
            // When from URL is selected check for empty "http://"
            if (this..isFromURLSelected()){
                String url = this..getSchemaURL();
                if (url != null){
                    url = url.trim();
                } else {
                    url = ""//NOI18N
                }
                if (isEmpty(url) || "http://".equalsIgnoreCase(url)){ //NOI18N
                    sb.append(NbBundle.getMessage(this.getClass(), 
                                        "MSG_EnterSchemaFileOrURL")); //NOI18N
                    valid = false;
                    setError(sb.toString());
                    return valid;                    
                }
                //TODO check for valid URL
            }
            
            //check for valid file
            if (this..isFromFSSelected()){
                String schFl = this..getSchemaFile();
                if (schFl != null){
                    schFl = schFl.trim();
                } else {
                    schFl = ""//NOI18N
                }
                
                if (isEmpty(schFl)){ 
                    sb.append(NbBundle.getMessage(this.getClass(), 
                                        "MSG_EnterSchemaFileOrURL")); //NOI18N
                    valid = false;
                    setError(sb.toString());
                    return valid;                    
                }
                               
                File file = null;
                if (schFl.startsWith("\\") || schFl.startsWith("/") || (schFl.indexOf(":") == 1)){ //NOI18N
                    file = new File(schFl); // abs path
                } else {
                    // starts with . or .. or any alpha numeric character 
                    file = new File(this.schFl); // relative path                    
                }
                
                if (schFl.startsWith(".") || schFl.startsWith("..")){ 
                } else {
                    
                }
                if (!file.exists()){
                    sb.append(NbBundle.getMessage(this.getClass(), 
                                    "MSG_enterValidSchemaFile")); //NOI18N
                    valid = false;
                    setError(sb.toString());
                    return valid;                    
                }
                if (!file.isFile()){
                    sb.append(NbBundle.getMessage(this.getClass(), 
                                    "MSG_enterValidSchemaFile")); //NOI18N
                    valid = false;
                    setError(sb.toString());
                    return valid;                    
                }                    
            }
            
        }
        
        if (!isEmpty(this..getPackageName())){
            String packageName = this..getPackageName();
            // Do not allow characters (,\\/;:)
            if ((packageName.indexOf(",") > -1) ||           //NOI18N
                    (packageName.indexOf("\\") > -1) ||      //NOI18N
                    (packageName.indexOf("/") > -1)  ||      //NOI18N
                    (packageName.indexOf(";") > -1)  ||      //NOI18N
                    (packageName.indexOf(":") > -1)  ){      //NOI18N  
                sb.append(NbBundle.getMessage(this.getClass(),
                        "MSG_InvalidCharInPackageName")); //NOI18N
                valid = false;
                setError(sb.toString());
                return valid;                
            }            
        }
        
        Map<StringBooleanoptions = this..getOptions();
        if (..equals(
                options.get(.)) && 
                ..equals(
                options.get(.))){ 
            valid = false;
            sb.append(NbBundle.getMessage(this.getClass(), 
                    "MSG_CanNotSelectQuietAndVerbose")); //NOI18N
            setError(sb.toString());
            return valid;
        }
        
        if (valid){
            setError(null);           
            return valid;
        } else{
            setError(sb.toString());
            return valid;
        }
    }
    
    public boolean isValid() {
        StringBuffer sb = new StringBuffer(); 
        return isValid(sb);
    }
    
    public boolean isFinishPanel() {
        return true;
    } 
    
    public HelpCtx getHelp() {
        return new HelpCtx(JAXBWizBindingCfgPanel.class);
    }
    public Component getComponent() {
        return ;
    }
        
    public void setMode(int mode) {
        switch ( mode ) {
            case :
                break;
            default:
            case :
                break;
        }
    }
    
    public void fireChangeEvent() {
        ChangeEvent che = new ChangeEvent(this);
        try {
            for ( ChangeListener cl :  ) {
                cl.stateChangedche );
            }
        } catch (Exception ex){
            this..log(."fireChangeEvent()"ex);  
        }
    }
    
    public void storeSettings(Object settings) {
        WizardDescriptor wdNew = (WizardDescriptorsettings;              
        wdNew.putProperty(null);
        if (this..getSchemaName() != null) {
            wdNew.putProperty(.
                    this..getSchemaName());    
        }
        if (this..getPackageName() != null) {
            wdNew.putProperty(.
                    this..getPackageName());    
        }
        if (this..getSchemaType() != null) {
            wdNew.putProperty(.
                    this..getSchemaType());    
        }
        
        Map<StringBooleanoptions =  this..getOptions();
        wdNew.putProperty(.options);
        
        List<StringxsdFileList = new ArrayList<String>();
        String schemaLoc = this..getSchemaFile();
        if (schemaLoc == null){
            xsdFileList.add(this..getSchemaURL());            
                    .);
        } else {
            xsdFileList.add(this..getSchemaFile());            
                    .);            
        }
        
        wdNew.putProperty(.xsdFileList);            
        
        // Binding files
        List<Stringbindings = this..getBindingFiles();
        wdNew.putProperty(.bindings);
        
        // catalog file
        String catalogFile = this..getCatalogFile();
        wdNew.putProperty(.catalogFile);
    }
        
    public void readSettings(Object settings) {
        try {
            this. = (WizardDescriptorsettings;
            this..setInitializing(true);
            
            if (.getProperty(.) != null) {
                this..setSchemaName((String
                        .getProperty(.));
            }
            if (.getProperty(.) != null) {
                this..setProjectName((String
                        .getProperty(.));
            }
            if (.getProperty(.) != null) {
                this..setProjectDir((File
                        .getProperty(.));
                this. = (File.getProperty(.);
            }
            if (.getProperty(.) != null) {
                this..setPackageName((String
                        .getProperty(.));
            }
            if (.getProperty(.) != null) {
                this..setSchemaType((String
                        .getProperty(.));
            }
            Map<StringBooleanoptions = (Map<StringBoolean>) 
                    .getProperty(.);
            if (options != null) {
                this..setOptions(options);
            }
            String origSrcLocType = (String
                    .getProperty(.);
            List<StringxsdFileList = (List<String>) 
                    .getProperty(.);
            if ((origSrcLocType != null) && (
                    ..equals(
                        origSrcLocType))) {
                if ((xsdFileList != null) && (xsdFileList.size() > 0)) {
                    Iterator<Stringitr = xsdFileList.iterator();
                    String file = itr.next();
                    this..setSchemaURL(file);
                }
            } else {
                if ((xsdFileList != null) && (xsdFileList.size() > 0)) {
                    Iterator<Stringitr = xsdFileList.iterator();
                    String file = itr.next();
                    this..setSchemaFile(file);
                }
            }
            // Bindig files
            List<StringbindingFileList = (List<String>) 
                    .getProperty(.);
            if (bindingFileList != null) {
                this..setBindingFiles(bindingFileList);
            }
            String catalog = (String
                    .getProperty(.);
            if (catalog != null) {
                this..setCatalogFile(catalog);
            }
            this. = (List<String>) 
                    .getProperty(.);
            // XXX hack, TemplateWizard in final setTemplateImpl() forces new 
            // wizard's title this name is used in NewFileWizard to modify the title
            if ( instanceof TemplateWizard) {
                .putProperty(, NbBundle.getMessage(
                        this.getClass(), "LBL_TemplateWizardTitle")); //NOI18N
            }
        } finally {
            this..setInitializing(false);
        }
    }    
New to GrepCode? Check out our FAQ X