001    /******************************************************************************
002     * Copyright (C) MActor Developers. All rights reserved.                        *
003     * ---------------------------------------------------------------------------*
004     * This file is part of MActor.                                               *
005     *                                                                            *
006     * MActor is free software; you can redistribute it and/or modify             *
007     * it under the terms of the GNU General Public License as published by       *
008     * the Free Software Foundation; either version 2 of the License, or          *
009     * (at your option) any later version.                                        *
010     *                                                                            *
011     * MActor is distributed in the hope that it will be useful,                  *
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
014     * GNU General Public License for more details.                               *
015     *                                                                            *
016     * You should have received a copy of the GNU General Public License          *
017     * along with MActor; if not, write to the Free Software                      *
018     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *
019     ******************************************************************************/
020    package org.mactor.ui.gui.project.editors;
021    
022    import org.dom4j.Element;
023    import org.mactor.framework.spec.GlobalConfig.Group;
024    
025    public class EditorUtil {
026            public static void setAttributeValue(Element e, String attrName, String attrValue) {
027                    if (attrValue == null)
028                            attrValue = "";
029                    if (e == null)
030                            return;
031                    if (e.attribute(attrName) == null)
032                            e.addAttribute(attrName, attrValue);
033                    else
034                            e.attribute(attrName).setValue(attrValue);
035            }
036            public static String getAttributeValue(Element e, String attrName) {
037                    if (e == null)
038                            return "";
039                    String v = e.attributeValue(attrName);
040                    if (v == null)
041                            return "";
042                    return v.trim();
043            }
044            public static boolean isGlobalConfigDBGroupElement(Element e) {
045                    if (e == null)
046                            return false;
047                    try {
048                            return isGlobalConfigDBGroup(Group.loadGroup(e));
049                    } catch (Exception ex) {
050                            return false;
051                    }
052            }
053            public static boolean isGlobalConfigDBGroup(Group g) {
054                    try {
055                            g.getRequieredValue("url");
056                            g.getRequieredValue("driver");
057                            return true;
058                    } catch (Exception ex) {
059                            return false;
060                    }
061            }
062    }