alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.core.windows.persistence.convert;

import org.netbeans.core.projects.SessionManager;
import org.netbeans.core.windows.Debug;
import org.netbeans.core.windows.WindowManagerImpl;
import org.netbeans.core.windows.persistence.InternalConfig;
import org.netbeans.core.windows.persistence.PersistenceManager;
import org.netbeans.core.windows.persistence.WindowManagerParser;
import org.openide.ErrorManager;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;
import org.openide.modules.SpecificationVersion;
import org.openide.util.NbBundle;
import org.openide.windows.WindowManager;
import org.openide.xml.XMLUtil;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * Handle loading/saving of Mode configuration data.
 *
 * @author Marek Slama
 */

class ModeParserOld {
    
    private static final String INSTANCE_DTD_ID_1_0
        = "-//NetBeans//DTD Mode Properties 1.0//EN"; // NOI18N
    private static final String INSTANCE_DTD_ID_1_1
        = "-//NetBeans//DTD Mode Properties 1.1//EN"; // NOI18N
    private static final String INSTANCE_DTD_ID_1_2
        = "-//NetBeans//DTD Mode Properties 1.2//EN"; // NOI18N
    private static final String INSTANCE_DTD_ID_2_0
        = "-//NetBeans//DTD Mode Properties 2.0//EN"; // NOI18N
    
    /** Module parent folder */
    private FileObject moduleParentFolder;
    
    /** Module mode folder. Cached here to get events from filesystem
     * when some children are added. */
    private FileObject moduleModeFolder;
        
    private PropertyHandler propertyHandler;
    
    private InternalConfig internalConfig;
    
    /** Map of TCRefParserOld instances. Used for fast access. */
    private Map tcRefParserMap = new HashMap(19);
    
    /** Unique mode name from file name */
    private String modeName;
    
    public ModeParserOld (String name) {
        this.modeName = name;
    }
    
    /** Load mode configuration including all tcrefs. */
    ModeConfigOld load () throws IOException {
        //log("load ENTER" + " mo:" + getName());
        ModeConfigOld mc = new ModeConfigOld();
        readProperties(mc);
        readTCRefs(mc);
        //log("load LEAVE" + " mo:" + getName());
        return mc;
    }
    
    private void readProperties (ModeConfigOld mc) throws IOException {
        log("readProperties ENTER" + " mo:" + getName());
        if (propertyHandler == null) {
            propertyHandler = new PropertyHandler();
        }
        InternalConfig internalCfg = getInternalConfig();
        internalCfg.clear();
        propertyHandler.readData(mc, internalCfg);
        
        /*log("               specVersion: " + internalCfg.specVersion);
        log("        moduleCodeNameBase: " + internalCfg.moduleCodeNameBase);
        log("     moduleCodeNameRelease: " + internalCfg.moduleCodeNameRelease);
        log("moduleSpecificationVersion: " + internalCfg.moduleSpecificationVersion);*/
        
        log("readProperties LEAVE" + " mo:" + getName());
    }
    
    private void readTCRefs (ModeConfigOld mc) throws IOException {
        log("readTCRefs ENTER" + " mo:" + getName());
        
        //log("moduleParentFolder: " + moduleParentFolder);
        //log(" localParentFolder: " + localParentFolder);
        //log("  moduleModeFolder: " + moduleModeFolder);
        //log("   localModeFolder: " + localModeFolder);
        
        moduleModeFolder = moduleParentFolder.getFileObject(modeName);
        if (moduleModeFolder != null) {
            FileObject [] files = moduleModeFolder.getChildren();
            for (int i = 0; i < files.length; i++) {
                log("fo[" + i + "]: " + files[i]);
                if (!files[i].isFolder() && PersistenceManager.TCREF_EXT.equals(files[i].getExt())) {
                    //Look for file at install layer
                    SessionManager sm = SessionManager.getDefault();
                    FileSystem installLayer = sm.getLayer(SessionManager.LAYER_INSTALL);
                    FileObject fo = installLayer.findResource(files[i].getPath());
                    if (fo == null) {
                        //File is not at install layer, ignore it.
                        continue;
                    }
                    
                    //wstcref file
                    TCRefParserOld tcRefParser;
                    if (tcRefParserMap.containsKey(files[i].getName())) {
                        tcRefParser = (TCRefParserOld) tcRefParserMap.get(files[i].getName());
                    } else {
                        tcRefParser = new TCRefParserOld(files[i].getName());
                        tcRefParserMap.put(files[i].getName(), tcRefParser);
                    }
                    tcRefParser.setModuleParentFolder(moduleModeFolder);
                }
            }
        }
        
        /*for (Iterator it = tcRefParserMap.keySet().iterator(); it.hasNext(); ) {
            TCRefParserOld tcRefParser = (TCRefParserOld) tcRefParserMap.get(it.next());
            log("tcRefParser: " + tcRefParser.getName()
            + " isInModuleFolder:" + tcRefParser.isInModuleFolder()
            + " isInLocalFolder:" + tcRefParser.isInLocalFolder());
        }*/
        
        List localList = new ArrayList(10);
        
        for (Iterator it = tcRefParserMap.keySet().iterator(); it.hasNext(); ) {
            TCRefParserOld tcRefParser = (TCRefParserOld) tcRefParserMap.get(it.next());
            localList.add(tcRefParser);
        }
        
        List tcRefCfgList = new ArrayList(localList.size());
        for (int i = 0; i < localList.size(); i++) {
            TCRefParserOld tcRefParser = (TCRefParserOld) localList.get(i);
            TCRefConfigOld tcRefCfg;
            try {
                tcRefCfg = tcRefParser.load();
            } catch (IOException exc) {
                //If reading of one tcRef fails we want to log message
                //and continue.
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
                continue;
            }
            tcRefCfgList.add(tcRefCfg);
        }
        
        mc.tcRefConfigs = (TCRefConfigOld [])
            tcRefCfgList.toArray(new TCRefConfigOld[tcRefCfgList.size()]);
        
        log("readTCRefs LEAVE" + " mo:" + getName());
    }
    
    /** Called from WorkspaceParserOld when Windows folder or Windows/WindowManager
     * folder or workspace folder or mode folder is deleted from module folder.
     * Removes all instances of TCRefParserOld.
     */
    void removeAllTCRefs (String workspaceName) {
        log("removeAllTCRefs" + " ws:" + workspaceName + " mo:" + getName());
        for (Iterator it = tcRefParserMap.keySet().iterator(); it.hasNext(); ) {
            TCRefParserOld tcRefParser = (TCRefParserOld) tcRefParserMap.get(it.next());
            Map importedItems = ImportManager.getDefault().getImportedTCRefs();
            //Remove imported TCRef
            if (importedItems.containsKey(tcRefParser.getName())) {
                ImportedItem item = (ImportedItem) importedItems.get(tcRefParser.getName());
                if (workspaceName.equals(item.workspaceName) && getName().equals(item.modeName)) {
                    WindowManagerParser wmParser = PersistenceManager.getDefault().getWindowManagerParser();
                    if (wmParser.removeTCRef(tcRefParser.getName())) {
                        //Remove TCRef from model if it was imported
                        WindowManagerImpl wmi = (WindowManagerImpl) WindowManager.getDefault();
                        log("removeAllTCRefs mo:" + getName() + " CALL OF topComponentRefConfigRemoved");
                        wmi.getPersistenceObserver().topComponentRefConfigRemoved(tcRefParser.getName());
                    }
                    importedItems.remove(tcRefParser.getName());
                    log("removeAllTCRefs mo:" + getName() + " tcRef:" + tcRefParser.getName() + " REMOVED"
                    + " contains:" + importedItems.containsKey(tcRefParser.getName()));
                }
            }
        }
        tcRefParserMap.clear();
    }
    
    /** Called from WorkspaceParserOld when Windows folder or Windows/WindowManager
     * folder or workspace folder or mode folder is deleted from module folder.
     * Removes all instances of TCRefParserOld.
     */
    void removeTCRef (String workspaceName, String tcRefName) {
        log("removeTCRef" + " ws:" + workspaceName + " mo:" + getName()
        + " tcRef:" + tcRefName);
        TCRefParserOld tcRefParser = (TCRefParserOld) tcRefParserMap.get(tcRefName);
        if (tcRefParser != null) {
            Map importedItems = ImportManager.getDefault().getImportedTCRefs();
            //Remove imported TCRef
            if (importedItems.containsKey(tcRefParser.getName())) {
                ImportedItem item = (ImportedItem) importedItems.get(tcRefParser.getName());
                if (workspaceName.equals(item.workspaceName) && getName().equals(item.modeName)) {
                    WindowManagerParser wmParser = PersistenceManager.getDefault().getWindowManagerParser();
                    if (wmParser.removeTCRef(tcRefParser.getName())) {
                        //Remove TCRef from model if it was imported
                        WindowManagerImpl wmi = (WindowManagerImpl) WindowManager.getDefault();
                        log("removeTCRef mo:" + getName() + " CALL OF topComponentRefConfigRemoved");
                        wmi.getPersistenceObserver().topComponentRefConfigRemoved(tcRefParser.getName());
                    }
                    importedItems.remove(tcRefParser.getName());
                    log("removeTCRef mo:" + getName() + " tcRef:" + tcRefParser.getName() + " REMOVED"
                    + " contains:" + importedItems.containsKey(tcRefParser.getName()));
                }
            }
            tcRefParserMap.remove(tcRefName);
        }
    }
    
    /** Called from WindowManagerParserOld when file wstcref is added to module folder.
     * Adds TCRefParserOld.
     * @param tcRefName unique name of tcRef
     */
    TCRefConfigOld addTCRef (String tcRefName) {
        log("addTCRef ENTER" + " tcRef:" + tcRefName);
        TCRefParserOld tcRefParser =
            (TCRefParserOld) tcRefParserMap.get(tcRefName);
        if (tcRefParser != null) {
            ErrorManager.getDefault().log(ErrorManager.WARNING,
            "[WinSys.TCRefParserOld.addTCRef]" // NOI18N
            + " Warning: TCRefParserOld " + tcRefName // NOI18N
            + " exists but it should not."); // NOI18N
            tcRefParserMap.remove(tcRefName);
        }
        tcRefParser = new TCRefParserOld(tcRefName);
        FileObject moduleModeFolder = moduleParentFolder.getFileObject(getName());
        tcRefParser.setModuleParentFolder(moduleModeFolder);
        tcRefParserMap.put(tcRefName, tcRefParser);
        TCRefConfigOld tcRefConfig = null;
        try {
            tcRefConfig = tcRefParser.load();
        } catch (IOException exc) {
            ErrorManager em = ErrorManager.getDefault();
            em.log(ErrorManager.WARNING,
            "[WinSys.ModeParserOld.addTCRef]" // NOI18N
            + " Warning: Cannot load tcRef " + tcRefName); // NOI18N
            em.notify(ErrorManager.INFORMATIONAL, exc);
        }
        return tcRefConfig;
    }
    
    /** Getter for internal configuration data.
     * @return instance of internal configuration data
     */
    InternalConfig getInternalConfig () {
        if (internalConfig == null) {
            internalConfig = new InternalConfig();
        }
        return internalConfig;
    }
    
    void setModuleParentFolder (FileObject moduleParentFolder) {
        this.moduleParentFolder = moduleParentFolder;
    }
    
    String getName () {
        return modeName;
    }
    
    /** Returns instance of TCRefParserOld.
     */
    TCRefParserOld findTCRefParser (String tcRefName) {
        return (TCRefParserOld) tcRefParserMap.get(tcRefName);
    }
    
    void log (String s) {
        Debug.log(ModeParserOld.class, s);
    }
    
    private final class PropertyHandler extends DefaultHandler {
        
        /** Mode configuration data */
        private ModeConfigOld modeConfig = null;
        
        /** Internal configuration data */
        private InternalConfig internalConfig = null;
        
        /** xml parser */
        private XMLReader parser;
        
        /** Lock to prevent mixing readData and writeData */
        private final Object RW_LOCK = new Object();
        
        private String activeUIType = ""; // NOI18N
        
        private int containerTypeMdi = -1;
        private int containerTypeSdi = -1;
        private int containerTypeAny = -1;
        
        private int frameTypeMdi = -1;
        private int frameTypeSdi = -1;
        private int frameTypeAny = -1;
        
        public PropertyHandler () {
        }
        
        private FileObject getConfigFOInput () {
            FileObject fo = moduleParentFolder.getFileObject
            (ModeParserOld.this.getName(), PersistenceManager.MODE_EXT);
            
            log("getConfigFOInput" + " fo:" + fo); // NOI18N
            
            FileObject modeConfigFO = null;
            if (fo != null) {
                //Look for file at install layer
                SessionManager sm = SessionManager.getDefault();
                FileSystem installLayer = sm.getLayer(SessionManager.LAYER_INSTALL);
                modeConfigFO = installLayer.findResource(fo.getPath());
            }
            
            log("getConfigFOInput" + " modeConfigFO:" + modeConfigFO); // NOI18N
            
            return modeConfigFO;
        }
        
        /**
         Reads mode configuration data from XML file. 
         Data are returned in output params.
         */
        void readData (ModeConfigOld modeCfg, InternalConfig internalCfg)
        throws IOException {
            modeConfig = modeCfg;
            internalConfig = internalCfg;
            
            activeUIType = ""; // NOI18N

            containerTypeMdi = -1;
            containerTypeSdi = -1;
            containerTypeAny = -1;

            frameTypeMdi = -1;
            frameTypeSdi = -1;
            frameTypeAny = -1;
            
            FileObject cfgFOInput = getConfigFOInput();
            if (cfgFOInput == null) {
                //No configuration data
                //Set name even in such case
                modeConfig.name = ModeParserOld.this.getName();
                return;
            }
            try {
                synchronized (RW_LOCK) {
                    //DUMP BEGIN
                    /*if ("explorer".equals(ModeParserOld.this.getName())) {
                        InputStream is = cfgFOInput.getInputStream();
                        byte [] arr = new byte [is.available()];
                        is.read(arr);
                        log("DUMP Mode:");
                        String s = new String(arr);
                        log(s);
                    }*/
                    //DUMP END
                    
                    getXMLParser().parse(new InputSource(cfgFOInput.getInputStream()));
                }
            } catch (SAXException exc) {
                //Turn into annotated IOException
                String msg = NbBundle.getMessage(ModeParserOld.class,
                    "EXC_ModeParse", cfgFOInput);
                IOException ioe = new IOException(msg);
                ErrorManager.getDefault().annotate(ioe, exc);
                throw ioe;
            }

            if (frameTypeMdi != -1) {
                modeConfig.frameType = frameTypeMdi;
            } else if (frameTypeAny != -1) {
                modeConfig.frameType = frameTypeAny;
            } else {
                modeConfig.frameType = ImportManager.TOP_FRAME;
            }
            
            if (containerTypeMdi != -1) {
                modeConfig.containerType = containerTypeMdi;
            } else if (containerTypeAny != -1) {
                modeConfig.containerType = containerTypeAny;
            } else {
                modeConfig.containerType = ImportManager.MULTI_TABBED_CONTAINER;
            }
            
            modeConfig.initialized = true;
            
            modeCfg = modeConfig;
            internalCfg = internalConfig;
            
            modeConfig = null;
            internalConfig = null;
        }
        
        public void startElement (String nameSpace, String name, String qname, Attributes attrs) throws SAXException {
            if ("mode".equals(qname)) { // NOI18N
                handleMode(attrs);
            } else if (internalConfig.specVersion.compareTo(new SpecificationVersion("2.0")) == 0) { // NOI18N
                //Parse version 2.0
            } else {
                //Parse version < 2.0
                //log("startElement PARSING OLD mo:" + ModeParserOld.this.getName()
                //+ " qname:" + qname);
                if ("module".equals(qname)) { // NOI18N
                    handleModule(attrs);
                } else if ("name".equals(qname)) { // NOI18N
                    handleName(attrs);
                } else if ("frame".equals(qname)) { // NOI18N
                    handleFrame(attrs);
                } else if ("container".equals(qname)) { // NOI18N
                    handleContainer(attrs);
                } else if ("ui-type".equals(qname)) { // NOI18N
                    startUIType(attrs);
                }
            }
        }
        
        public void endElement(String nameSpace, String name, String qname)
        throws SAXException {
            if ("ui-type".equals(qname)) { // NOI18N
                endUIType();
            }
        }
        
        public void error(SAXParseException ex) throws SAXException  {
            throw ex;
        }
        
        public void fatalError(SAXParseException ex) throws SAXException {
            throw ex;
        }
        
        public void warning(SAXParseException ex) throws SAXException {
            // ignore
        }
        
        /** Reads element "mode" */
        private void handleMode (Attributes attrs) {
            String version = attrs.getValue("version"); // NOI18N
            if (version != null) {
                internalConfig.specVersion = new SpecificationVersion(version);
            } else {
                ErrorManager.getDefault().log(ErrorManager.WARNING,
                "[WinSys.ModeParserOld.handleMode]" // NOI18N
                + " Warning: Missing attribute \"version\" of element \"mode\"."); // NOI18N
                internalConfig.specVersion = new SpecificationVersion("1.2"); // NOI18N
            }
        }
        
        /** Reads element "module" and updates mode config content */
        private void handleModule (Attributes attrs) {
            String moduleCodeName = attrs.getValue("name"); // NOI18N
            //Parse code name
            internalConfig.moduleCodeNameBase = null;
            internalConfig.moduleCodeNameRelease = null;
            internalConfig.moduleSpecificationVersion = null;
            if (moduleCodeName != null) {
                int i = moduleCodeName.indexOf('/');
                if (i != -1) {
                    internalConfig.moduleCodeNameBase = moduleCodeName.substring(0, i);
                    internalConfig.moduleCodeNameRelease = moduleCodeName.substring(i + 1);
                    checkReleaseCode(internalConfig);
                } else {
                    internalConfig.moduleCodeNameBase = moduleCodeName;
                }
                internalConfig.moduleSpecificationVersion = attrs.getValue("spec"); // NOI18N
            }
        }

        /** Checks validity of moduleCodeNameRelease field. 
         * Helper method. */
        private void checkReleaseCode (InternalConfig internalConfig) {
            // #24844. Repair the wrongly saved "null" string
            // as release number.
            if("null".equals(internalConfig.moduleCodeNameRelease)) { // NOI18N
                ErrorManager.getDefault().notify(
                    ErrorManager.INFORMATIONAL,
                    new IllegalStateException(
                        "Module release code was saved as null string" // NOI18N
                        + " for module "  + internalConfig.moduleCodeNameBase // NOI18N
                        + "! Repairing.") // NOI18N
                );
                internalConfig.moduleCodeNameRelease = null;
            }
        }
        
        /** Reads element "name" */
        private void handleName (Attributes attrs) throws SAXException {
            String name = attrs.getValue("unique"); // NOI18N
            if (name != null) {
                modeConfig.name = name;
                if (!name.equals(ModeParserOld.this.getName())) {
                    ErrorManager.getDefault().log(ErrorManager.WARNING,
                    "[WinSys.ModeParserOld.handleName]" // NOI18N
                    + " Error: Value of attribute \"unique\" of element \"name\"" // NOI18N
                    + " and configuration file name must be the same."); // NOI18N
                    throw new SAXException("Invalid attribute value"); // NOI18N
                }
            } else {
                ErrorManager.getDefault().log(ErrorManager.WARNING,
                "[WinSys.ModeParserOld.handleName]" // NOI18N
                + " Error: Missing required attribute \"unique\" of element \"name\"."); // NOI18N
                throw new SAXException("Missing required attribute"); // NOI18N
            }
        }
        
        /** Reads element "frame" */
        private void handleFrame (Attributes attrs) {
            String frameType = attrs.getValue("type"); // NOI18N
            if ("mdi".equals(activeUIType)) {
                if (frameType != null) {
                    if ("internal".equals(frameType)) { // NOI18N
                        frameTypeMdi = ImportManager.INTERNAL_FRAME;
                    } else if ("desktop".equals(frameType)) { // NOI18N
                        frameTypeMdi = ImportManager.DESKTOP_FRAME;
                    } else if ("window".equals(frameType)) { // NOI18N
                        frameTypeMdi = ImportManager.TOP_FRAME;
                    } else if ("dialog".equals(frameType)) { // NOI18N
                        //Unsupported. Convert to TOP_FRAME.
                        frameTypeMdi = ImportManager.TOP_FRAME;
                    } else {
                        frameTypeMdi = ImportManager.TOP_FRAME;
                        ErrorManager.getDefault().log(ErrorManager.WARNING,
                        "[WinSys.ModeParserOld.handleFrame]" // NOI18N
                        + " Warning: Invalid value of attribute \"type\"" // NOI18N
                        + " of element \"frame\"."); // NOI18N
                    }
                } else {
                    frameTypeMdi = ImportManager.TOP_FRAME;
                    ErrorManager.getDefault().log(ErrorManager.WARNING,
                    "[WinSys.ModeParserOld.handleFrame]" // NOI18N
                    + " Warning: Missing required attribute \"type\"" // NOI18N
                    + " of element \"frame\"."); // NOI18N
                }
            } else if ("sdi".equals(activeUIType)) {
                if (frameType != null) {
                    if ("internal".equals(frameType)) { // NOI18N
                        frameTypeSdi = ImportManager.INTERNAL_FRAME;
                    } else if ("desktop".equals(frameType)) { // NOI18N
                        frameTypeSdi = ImportManager.DESKTOP_FRAME;
                    } else if ("window".equals(frameType)) { // NOI18N
                        frameTypeSdi = ImportManager.TOP_FRAME;
                    } else if ("dialog".equals(frameType)) { // NOI18N
                        //Unsupported. Convert to TOP_FRAME.
                        frameTypeSdi = ImportManager.TOP_FRAME;
                    } else {
                        frameTypeSdi = ImportManager.TOP_FRAME;
                        ErrorManager.getDefault().log(ErrorManager.WARNING,
                        "[WinSys.ModeParserOld.handleFrame]" // NOI18N
                        + " Warning: Invalid value of attribute \"type\"" // NOI18N
                        + " of element \"frame\"."); // NOI18N
                    }
                } else {
                    frameTypeSdi = ImportManager.TOP_FRAME;
                    ErrorManager.getDefault().log(ErrorManager.WARNING,
                    "[WinSys.ModeParserOld.handleFrame]" // NOI18N
                    + " Warning: Missing required attribute \"type\"" // NOI18N
                    + " of element \"frame\"."); // NOI18N
                }
            } else if ("any".equals(activeUIType)) {
                 if (frameType != null) {
                    if ("internal".equals(frameType)) { // NOI18N
                        frameTypeAny = ImportManager.INTERNAL_FRAME;
                    } else if ("desktop".equals(frameType)) { // NOI18N
                        frameTypeAny = ImportManager.DESKTOP_FRAME;
                    } else if ("window".equals(frameType)) { // NOI18N
                        frameTypeAny = ImportManager.TOP_FRAME;
                    } else if ("dialog".equals(frameType)) { // NOI18N
                        //Unsupported. Convert to TOP_FRAME.
                        frameTypeAny = ImportManager.TOP_FRAME;
                    } else {
                        frameTypeAny = ImportManager.TOP_FRAME;
                        ErrorManager.getDefault().log(ErrorManager.WARNING,
                        "[WinSys.ModeParserOld.handleFrame]" // NOI18N
                        + " Warning: Invalid value of attribute \"type\"" // NOI18N
                        + " of element \"frame\"."); // NOI18N
                    }
                 } else {
                    frameTypeAny = ImportManager.TOP_FRAME;
                    ErrorManager.getDefault().log(ErrorManager.WARNING,
                    "[WinSys.ModeParserOld.handleFrame]" // NOI18N
                    + " Warning: Missing required attribute \"type\"" // NOI18N
                    + " of element \"frame\"."); // NOI18N
                 }
            }
        }
        
        /** Reads attributes of element "ui-type". */
        private void startUIType (Attributes attrs) {
            activeUIType = attrs.getValue("type"); // NOI18N
        }
        
        private void endUIType () {
            activeUIType = "";
        }
        
        /** Reads attributes of element "container". */
        private void handleContainer (Attributes attrs) {
            String type = attrs.getValue("type"); // NOI18N
            if ("mdi".equals(activeUIType)) {
                if (type != null) {
                    if ("split".equals(type)) { // NOI18N
                        containerTypeMdi = ImportManager.SPLIT_CONTAINER;
                    } else if ("tabbed".equals(type)) { // NOI18N
                        containerTypeMdi = ImportManager.MULTI_TABBED_CONTAINER;
                    } else {
                        containerTypeMdi = ImportManager.MULTI_TABBED_CONTAINER;
                        ErrorManager.getDefault().log(ErrorManager.WARNING,
                        "[WinSys.ModeParserOld.handleContainer]" // NOI18N
                        + " Warning: Invalid value of attribute \"type\"" // NOI18N
                        + " of element \"container\"."); // NOI18N
                    }
                } else {
                    containerTypeMdi = ImportManager.MULTI_TABBED_CONTAINER;
                    ErrorManager.getDefault().log(ErrorManager.WARNING,
                    "[WinSys.ModeParserOld.handleContainer]" // NOI18N
                    + " Warning: Missing required attribute \"type\"" // NOI18N
                    + " of element \"container\"."); // NOI18N
                }
            } else if ("sdi".equals(activeUIType)) {
                if (type != null) {
                    if ("split".equals(type)) { // NOI18N
                        containerTypeSdi = ImportManager.SPLIT_CONTAINER;
                    } else if ("tabbed".equals(type)) { // NOI18N
                        containerTypeSdi = ImportManager.MULTI_TABBED_CONTAINER;
                    } else {
                        containerTypeSdi = ImportManager.MULTI_TABBED_CONTAINER;
                        ErrorManager.getDefault().log(ErrorManager.WARNING,
                        "[WinSys.ModeParserOld.handleContainer]" // NOI18N
                        + " Warning: Invalid value of attribute \"type\"" // NOI18N
                        + " of element \"container\"."); // NOI18N
                    }
                } else {
                    containerTypeSdi = ImportManager.MULTI_TABBED_CONTAINER;
                    ErrorManager.getDefault().log(ErrorManager.WARNING,
                    "[WinSys.ModeParserOld.handleContainer]" // NOI18N
                    + " Warning: Missing required attribute \"type\"" // NOI18N
                    + " of element \"container\"."); // NOI18N
                }
            } else if ("any".equals(activeUIType)) {
                if (type != null) {
                    if ("split".equals(type)) { // NOI18N
                        containerTypeAny = ImportManager.SPLIT_CONTAINER;
                    } else if ("tabbed".equals(type)) { // NOI18N
                        containerTypeAny = ImportManager.MULTI_TABBED_CONTAINER;
                    } else {
                        containerTypeAny = ImportManager.MULTI_TABBED_CONTAINER;
                        ErrorManager.getDefault().log(ErrorManager.WARNING,
                        "[WinSys.ModeParserOld.handleContainer]" // NOI18N
                        + " Warning: Invalid value of attribute \"type\"" // NOI18N
                        + " of element \"container\"."); // NOI18N
                    }
                } else {
                    containerTypeAny = ImportManager.MULTI_TABBED_CONTAINER;
                    ErrorManager.getDefault().log(ErrorManager.WARNING,
                    "[WinSys.ModeParserOld.handleContainer]" // NOI18N
                    + " Warning: Missing required attribute \"type\"" // NOI18N
                    + " of element \"container\"."); // NOI18N
                }
            }
        }
        
        public void endDocument() throws SAXException {
        }
        
        public void ignorableWhitespace(char[] values, int param, int param2) 
        throws SAXException {
        }
        
        public void skippedEntity(String str) throws SAXException {
        }
        
        public void processingInstruction(String str, String str1) 
        throws SAXException {
        }
                
        public void endPrefixMapping(String str) throws SAXException {
        }
        
        public void startPrefixMapping(String str, String str1) 
        throws SAXException {
        }
        
        public void characters(char[] values, int param, int param2) 
        throws SAXException {
        }
        
        public void setDocumentLocator(org.xml.sax.Locator locator) {
        }
        
        public void startDocument() throws SAXException {
        }
        
        /** @return Newly created parser with set content handler, errror handler
         * and entity resolver
         */
        private XMLReader getXMLParser () throws SAXException {
            if (parser == null) {
                // get non validating, not namespace aware parser
                parser = XMLUtil.createXMLReader();
                parser.setContentHandler(this);
                parser.setErrorHandler(this);
                parser.setEntityResolver(this);
            }
            return parser;
        }

        /** Implementation of entity resolver. Points to the local DTD
         * for our public ID */
        public InputSource resolveEntity (String publicId, String systemId)
        throws SAXException {
            if (INSTANCE_DTD_ID_1_0.equals(publicId)
             || INSTANCE_DTD_ID_1_1.equals(publicId)
             || INSTANCE_DTD_ID_1_2.equals(publicId)
             || INSTANCE_DTD_ID_2_0.equals(publicId)) {
                InputStream is = new ByteArrayInputStream(new byte[0]);
                //getClass().getResourceAsStream(INSTANCE_DTD_LOCAL);
//                if (is == null) {
//                    throw new IllegalStateException ("Entity cannot be resolved."); // NOI18N
//                }
                return new InputSource(is);
            }
            return null; // i.e. follow advice of systemID
        }
        
        void log (String s) {
            Debug.log(PropertyHandler.class, s);
        }
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.