1 /* 2 * Copyright 2003,2004 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 /* 17 18 */ 19 20 package org.apache.pluto.portalImpl.aggregation.navigation; 21 22 import javax.servlet.ServletConfig; 23 24 import org.apache.pluto.portalImpl.aggregation.AbstractFragmentSingle; 25 import org.apache.pluto.portalImpl.core.PortalURL; 26 27 public abstract class AbstractNavigationFragment extends AbstractFragmentSingle 28 { 29 30 public AbstractNavigationFragment(String id, 31 ServletConfig config, 32 org.apache.pluto.portalImpl.aggregation.Fragment parent, 33 org.apache.pluto.portalImpl.om.page.Fragment fragDesc, 34 org.apache.pluto.portalImpl.aggregation.navigation.Navigation navigation) 35 throws Exception 36 { 37 super(id, config, parent, fragDesc, navigation); 38 } 39 40 public void createURL(PortalURL url) 41 { 42 getParent().createURL(url); 43 url.addGlobalNavigation(getId()); 44 } 45 46 public boolean isPartOfURL(PortalURL url) 47 { 48 return url.isPartOfGlobalNavigation(getId()); 49 } 50 51 public org.apache.pluto.portalImpl.aggregation.navigation.Navigation getRootNavigation() 52 { 53 org.apache.pluto.portalImpl.aggregation.Fragment returnvalue = this; 54 for (; returnvalue.getParent() != null; returnvalue = returnvalue.getParent()) { 55 } 56 return returnvalue.getNavigation(); 57 } 58 59 /*** 60 * If the given parent is NULL, the method returns the first fragment containing 61 * navigational information after the root element. 62 * <P> 63 * if the given parent points to a fragment, the method returns the first child 64 * fragment that contains navigational information 65 * 66 * @param parent the parent fragment or NULL 67 * @return Returns the first fragment that contains navigational information. 68 */ 69 /* 70 public org.apache.pluto.portalImpl.aggregation.Fragment 71 getFirstNavigation(org.apache.pluto.portalImpl.aggregation.Fragment parent) 72 { 73 org.apache.pluto.portalImpl.aggregation.Fragment returnvalue = null; 74 if (parent==null) 75 { 76 returnvalue = this; 77 // get root fragment...this does not need to have a navigation 78 for (; returnvalue.getParent()!=null; returnvalue = returnvalue.getParent()) {} 79 80 // root element does not have a navigation information 81 if (returnvalue.getNavigation()==null) 82 { 83 returnvalue = getFirstNavigation(returnvalue); 84 } 85 86 } 87 else 88 { 89 Iterator iterator = parent.getChildFragments().iterator(); 90 while (iterator.hasNext()) 91 { 92 org.apache.pluto.portalImpl.aggregation.Fragment fragment = 93 (org.apache.pluto.portalImpl.aggregation.Fragment)iterator.next(); 94 if (fragment.getNavigation()!=null) 95 { 96 returnvalue = fragment; 97 break; 98 } 99 } 100 101 // no fragment with navigational information found yet, so try a deep search 102 if (returnvalue==null) 103 { 104 iterator = parent.getChildFragments().iterator(); 105 while (iterator.hasNext()) 106 { 107 org.apache.pluto.portalImpl.aggregation.Fragment fragment = 108 (org.apache.pluto.portalImpl.aggregation.Fragment)iterator.next(); 109 110 returnvalue = getFirstNavigation(fragment); 111 112 if (returnvalue!=null) 113 break; 114 115 } 116 117 } 118 119 } 120 return returnvalue; 121 } 122 123 public org.apache.pluto.portalImpl.aggregation.Fragment 124 getNextNavigation(org.apache.pluto.portalImpl.aggregation.Fragment previous) 125 { 126 if (previous==null) 127 throw new IllegalArgumentException("previous navigation mus not be null!"); 128 129 130 return null; 131 } 132 */ 133 }