⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fragmentloader.java

📁 uPortal是开放源码的Portal门户产品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Attempts to determine group key based on a group name.     * If the group key can not be determined in a unique way, the method will terminate!     *     * @param groupName a <code>String</code> value     * @return a group key     */    static String getGroupKey(String groupName) throws Exception {        EntityIdentifier[] mg=GroupService.searchForGroups(groupName,IGroupConstants.IS,Class.forName("org.jasig.portal.security.IPerson"));        if(mg!=null && mg.length>0) {            if(mg.length>1) {                // multiple matches                System.out.println("ERROR: group name \""+groupName+"\" matches several existing groups: [Key\tName\tDescription]");                for(int i=0;i<mg.length;i++) {                    IEntityGroup g=GroupService.findGroup(mg[i].getKey());                    System.out.print("\t\""+g.getKey()+"\"\t"+g.getName()+"\"\t"+g.getDescription());                }                System.out.println("Please modify config file to specify group key directly (i.e. <group key=\"keyValue\">...)");                System.exit(1);            } else {                System.out.println("DEBUG: group \""+groupName+"\", key=\""+mg[0].getKey()+"\"");                return mg[0].getKey();            }        } else {            // didnt' match            System.out.println("ERROR: can not find user group with name \""+groupName+"\" in the database !");            // try nonexact match            EntityIdentifier[] mg2=GroupService.searchForGroups(groupName,IGroupConstants.CONTAINS,Class.forName("org.jasig.portal.security.IPerson"));            if(mg2!=null && mg2.length>0) {                System.out.print("Possible matches are: [");                for(int i=0;i<mg2.length;i++) {                    IEntityGroup g=GroupService.findGroup(mg2[i].getKey());                    System.out.print("\""+g.getName()+"\" ");                }                System.out.println("]");            }             throw new PortalException("ERROR: can not find user group with name \""+groupName+"\" in the database !");        }        return null;    }    /**     * A filter that will perform the following functions:     * - intercept and verify restriction names, writing out ids     * - intercept and verify user group names, writing out ids     *     */    private static class ConfigFilter extends SAX2FilterImpl {        private Map rMap;        private boolean groupMode=false;        private AttributesImpl groupAtts;        private String groupLocalName;        private String groupUri;        private String groupData=null;        private Map fragmentIds;        private static IAggregatedUserLayoutStore layoutStore = null;        private static IChannelRegistryStore channelStore = null;        private static String adminId = null;        public ConfigFilter(ContentHandler ch,Map rMap) throws PortalException {            super(ch);            this.rMap=rMap;            fragmentIds = new HashMap();            if ( layoutStore == null ) {             IUserLayoutStore layoutStoreImpl = UserLayoutStoreFactory.getUserLayoutStoreImpl();             if ( layoutStoreImpl == null || !(layoutStoreImpl instanceof IAggregatedUserLayoutStore) )              throw new PortalException ( "The user layout store is NULL or must implement IAggregatedUserLayoutStore!" );             layoutStore =  (IAggregatedUserLayoutStore) layoutStoreImpl;            }            if ( channelStore == null )             channelStore = ChannelRegistryStoreFactory.getChannelRegistryStoreImpl();        }        private String getAdminId() throws Exception {           if ( adminId == null ) {           	Connection con = RDBMServices.getConnection();           	ResultSet rs = con.createStatement().executeQuery("SELECT USER_ID FROM UP_USER WHERE USER_NAME='admin'");           	if ( rs.next() )           	  adminId = rs.getString(1);           	rs.close();           	con.close();           }           return adminId;        }                        public Set getFragmentNames() {           return fragmentIds.keySet();        }                public Map getFragmentIds() {           return fragmentIds;        }        public void characters (char ch[], int start, int length) throws SAXException   {            if(groupMode) {                // accumulate character data                String ds=new String(ch,start,length);                if(groupData==null) {                    groupData=ds;                } else {                    groupData=groupData+ds;                }            } else {                super.characters(ch,start,length);            }        }        public void startElement (String uri, String localName, String qName, Attributes atts) throws SAXException {            AttributesImpl ai=new AttributesImpl(atts);             // Adding the fragment name to the vector            if ( qName.equals("fragment") ) {             String name = atts.getValue("name");             try {              String id = layoutStore.getNextFragmentId();              if ( !fragmentIds.containsKey(name) )                fragmentIds.put(name,id);              ai.addAttribute(uri,"id","id","CDATA",id);              ai.addAttribute(uri,"owner","owner","CDATA",getAdminId());             } catch ( Exception pe ) {                 throw new SAXException(pe.getMessage());               }            } // Getting the channel ID by the fname            else if ( qName.equals("channel") ) {             String fname = atts.getValue("fname");             ChannelDefinition chanDef;             try {                 chanDef = channelStore.getChannelDefinition(fname);             } catch ( Exception e ) {                 // We have to catch Exception because getChannelDefinition() throws Exception.                 throw new SAXException(e);             }             if (chanDef == null){                 throw new SAXException("Unable to find definition for channel fname: "+ fname);             }                            ai.addAttribute(uri,"id","id","CDATA",chanDef.getId()+"");            }            if(qName.equals("group")) { // this could be made more robust by adding another mode for "groups" element                groupMode=true;                groupUri=uri; groupLocalName=localName; groupAtts=new AttributesImpl(atts);            } else if(qName.equals("restriction")) { // this can also be made more robust by adding another mode for "restrictions" element                // look up restriction name in the DB                String restrType;                if(ai.getIndex("type")!=-1) {                    // restriction type was specified                    if(!rMap.containsValue(ai.getValue("type"))) {                        System.out.println("ERROR: specified restriction type \""+ai.getValue("type")+"\" does not exist ! Either correct the type value, or consider using match by restriction name (i.e. <restriction name=\"priority\" ...)");                        System.exit(1);                    } else {                        if(ai.getIndex("name")!=-1 && rMap.containsKey(ai.getValue("name")) && (!ai.getValue("type").equals((String)rMap.get(ai.getValue("name"))))) {                            System.out.println("ERROR: specified restriction type \""+ai.getValue("type")+"\" does not match the specified name \""+ai.getValue("name")+"\" in the database. name \""+ai.getValue("name")+"\" matches restriction type \""+(String)rMap.get(ai.getValue("name"))+"\"");                            System.exit(1);                        } else {                            super.startElement(uri,localName,qName,ai);                        }                    }                } else {                    String restrName=ai.getValue("name");                    restrType=(String)rMap.get(restrName);                    if(restrType!=null) {                        ai.addAttribute(uri,"type","type","CDATA",restrType);                    } else {                        System.out.println("ERROR: config file specifies a restriction name \""+restrName+"\" which is not registered with the database!");                        System.exit(1);                    }                    super.startElement(uri,localName,qName,ai);                }            } else {                super.startElement(uri,localName,qName,ai);            }        }        public void endElement (String uri, String localName, String qName)	throws SAXException {            if(groupMode) {                if(qName.equals("group")) {                    if(groupAtts.getIndex("key")==-1) {                        if(groupData!=null) {                            String groupKey=null;                            try {                                groupKey=getGroupKey(groupData);                            } catch (Exception e) {                                System.out.println("ERROR: encountered exception while trying to determine group key for a group name \""+groupData+"\"");                                e.printStackTrace();                                System.exit(1);                            }                            groupAtts.addAttribute(groupUri,"key","key","CDATA",groupKey);                            // output group element                            super.startElement(groupUri,groupLocalName,"group",groupAtts);                            super.characters(groupData.toCharArray(), 0, groupData.length());                            super.endElement(groupUri,groupLocalName,"group");                        } else {                            System.out.println("ERROR: one of the group elements is empty and no group key has been specified !");                            System.exit(1);                        }                    } else {                        // check specified group key                        try {                            IEntityGroup g=GroupService.findGroup(groupAtts.getValue("key"));                            if(g!=null) {                                if(groupData!=null) {                                    if(g.getName().equals(groupData)) {                                        System.out.println("DEBUG: group key=\""+groupAtts.getValue("key")+"\" checked out with the name \""+groupData+"\".");                                        // output group element                                        super.startElement(groupUri,groupLocalName,"group",groupAtts);                                        if(groupData!=null) {                                            super.characters(groupData.toCharArray(), 0, groupData.length());                                        }                                        super.endElement(groupUri,groupLocalName,"group");                                    } else {                                        System.out.println("ERROR: group key \""+groupAtts.getValue("key")+"\" belongs to a group with a name \""+g.getName()+"\", where the name specified by the config file is \""+groupData+"\". Please fix the config file.");                                        System.exit(1);                                    }                                }                            } else {                                System.out.println("ERROR: unable to find a group with a key \""+groupAtts.getValue("key")+"\"! Either correct the key, or consider matching the group by name.");                                System.exit(1);                            }                        } catch (Exception e) {                            System.out.println("ERROR: exception raised while trying to look up group by a key=\""+groupAtts.getValue("key")+"\"!");                            e.printStackTrace();                            System.exit(1);                        }                    }                } else {                    System.out.println("WARNING: <group/> contains other elements, which it shouldn't! Please check config validity.");                }                groupMode=false;                groupData=null;                groupAtts=null;                groupUri=null;                groupLocalName=null;            } else {                super.endElement(uri,localName,qName);            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -