Package org.gatein.pc.portlet.impl.metadata

Examples of org.gatein.pc.portlet.impl.metadata.PortletApplication20MetaData


         {
            throw new DeploymentException("Could not read portlet.xml descriptor", e);
         }
      }

      PortletApplication20MetaData md = new PortletApplication20MetaData();

      //
      inputFactory.setProperty("javax.xml.stream.isCoalescing", true);
      StaxNavigator<Element> nav = null;
      try
      {
         XMLStreamReader stream = inputFactory.createXMLStreamReader(is);
         nav = StaxNavigatorFactory.create(new Naming.Enumerated.Simple<Element>(Element.class, null), stream);
      }
      catch (XMLStreamException e)
      {
         throw new DeploymentException("Could not create a STAX reader", e);
      }

      // We want to trim content (mandated by the spec)
      nav.setTrimContent(true);

      // Get the root element qname
      QName qname = nav.getQName();
      String rootNS = qname.getNamespaceURI();

      // Determine the correct version to parse
      int version;
      if (PORTLET_1_0.equals(rootNS))
      {
         md.setVersion("1.0");
         version = 1;
      }
      else if (PORTLET_2_0.equals(rootNS))
      {
         md.setVersion("2.0");
         version = 2;
      }
      else
      {
         throw new StaxNavException("Illegal portlet xml namespace " + rootNS);
      }

      // Perform schema validation if required
      if (schemaValidation)
      {
         XSD xsd = version == 1 ? XSD.PORTLET_1_0 : XSD.PORTLET_2_0;
         try
         {
            xsd.validate(new StreamSource(new ByteArrayInputStream(bytes)));
         }
         catch (Exception e)
         {
            throw new DeploymentException("The portlet.xml file is not valid XML", e);
         }
      }

      //
      assert Element.portlet_app == nav.getName();

      //
      if (nav.child() == null)
      {
         return md;
      }

      //
      for (StaxNavigator<Element> portletNav : nav.fork(Element.portlet))
      {
         PortletMetaData portletMD = new PortletMetaData();

         //
         portletMD.setId(portletNav.getAttribute("id"));
         portletMD.setDescription(readLocalizedString(portletNav, Element.description));
         portletMD.setPortletName(getContent(portletNav, Element.portlet_name));
         portletMD.setDisplayName(readLocalizedString(portletNav, Element.display_name));
         portletMD.setPortletClass(getContent(portletNav, Element.portlet_class));

         //
         for (InitParamMetaData initParamMD : readInitParams(portletNav))
         {
            portletMD.addInitParam(initParamMD);
         }

         //
         if (portletNav.next(Element.expiration_cache))
         {
            portletMD.setExpirationCache(Integer.parseInt(portletNav.getContent()));
         }
         if (portletNav.next(Element.cache_scope))
         {
            portletMD.setCacheScope(PortletCacheScopeEnum.valueOf(portletNav.getContent()));
         }

         //
         while (portletNav.next(Element.supports))
         {
            SupportsMetaData supportsMD = new SupportsMetaData();
            supportsMD.setId(portletNav.getAttribute("id"));
            supportsMD.setMimeType(getContent(portletNav, Element.mime_type));
            while (portletNav.next(Element.portlet_mode)) {
               PortletModeMetaData portletModeMD = new PortletModeMetaData();
               portletModeMD.setPortletMode(Mode.create(portletNav.getContent()));
               supportsMD.addPortletMode(portletModeMD);
            }
            while (portletNav.next(Element.window_state)) {
               WindowStateMetaData windowStateMD = new WindowStateMetaData();
               windowStateMD.setWindowState(WindowState.create(portletNav.getContent()));
               supportsMD.addWindowState(windowStateMD);
            }
            portletMD.addSupport(supportsMD);
         }

         //
         while (portletNav.next(Element.supported_locale))
         {
            SupportedLocaleMetaData supportedLocaleMD = new SupportedLocaleMetaData();
            supportedLocaleMD.setLocale(portletNav.getContent());
            portletMD.addSupportedLocale(supportedLocaleMD);
         }
         if (portletNav.next(Element.resource_bundle))
         {
            portletMD.setResourceBundle(portletNav.getContent());
         }

         //
         if (portletNav.next(Element.portlet_info))
         {
            PortletInfoMetaData portletInfoMD = new PortletInfoMetaData();
            if (portletNav.next(Element.title))
            {
               portletInfoMD.setTitle(portletNav.getContent());
            }
            if (portletNav.next(Element.short_title))
            {
               portletInfoMD.setShortTitle(portletNav.getContent());
            }
            if (portletNav.next(Element.keywords))
            {
               portletInfoMD.setKeywords(portletNav.getContent());
            }
            portletMD.setPortletInfo(portletInfoMD);
         }

         //
         if (portletNav.next(Element.portlet_preferences))
         {
            PortletPreferencesMetaData portletPreferencesMD = new PortletPreferencesMetaData();
            while (portletNav.next(Element.preference))
            {
               PortletPreferenceMetaData portletPreferenceMD = new PortletPreferenceMetaData();
               portletPreferenceMD.setName(getContent(portletNav, Element.name));
               while (portletNav.next(Element.value))
               {
                  portletPreferenceMD.addValue(portletNav.getContent());
               }
               if (portletNav.next(Element.read_only))
               {
                  portletPreferenceMD.setReadOnly(portletNav.parseContent(ValueType.BOOLEAN));
               }
               portletPreferencesMD.addPortletPreference(portletPreferenceMD);
            }
            if (portletNav.next(Element.preferences_validator))
            {
               portletPreferencesMD.setPreferenceValidator(portletNav.getContent());
            }
            portletMD.setPortletPreferences(portletPreferencesMD);
         }

         //
         while (portletNav.next(Element.security_role_ref))
         {
            SecurityRoleRefMetaData securityRoleRefMD = new SecurityRoleRefMetaData();
            securityRoleRefMD.setDescription(readLocalizedString(portletNav, Element.description));
            securityRoleRefMD.setRoleName(getContent(portletNav, Element.role_name));
            if (portletNav.next(Element.role_link))
            {
               securityRoleRefMD.setRoleLink(portletNav.getContent());
            }
            portletMD.addSecurityRoleRef(securityRoleRefMD);
         }

         //
         while (portletNav.next(Element.supported_processing_event) || portletNav.next(Element.supported_publishing_event))
         {
            boolean processing = portletNav.getName() == Element.supported_processing_event;
            EventDefinitionReferenceMetaData eventDefinitionReferenceMD = new EventDefinitionReferenceMetaData();
            switch (portletNav.next(NAME_OR_QNAME))
            {
               case name:
                  eventDefinitionReferenceMD.setName(portletNav.getContent());
                  break;
               case qname:
                  eventDefinitionReferenceMD.setQname(readQName(portletNav));
                  break;
            }
            if (processing)
            {
               portletMD.addSupportedProcessingEvent(eventDefinitionReferenceMD);
            }
            else
            {
               portletMD.addSupportedPublishingEvent(eventDefinitionReferenceMD);
            }
         }
         while (portletNav.next(Element.supported_public_render_parameter))
         {
            portletMD.addSupportedPublicRenderParameter(portletNav.getContent());
         }
         while (portletNav.next(Element.container_runtime_option))
         {
            ContainerRuntimeMetaData containerRuntimeOptionMD = new ContainerRuntimeMetaData();
            containerRuntimeOptionMD.setName(getContent(portletNav, Element.name));
            while (portletNav.next(Element.value))
            {
               containerRuntimeOptionMD.addValue(portletNav.getContent());
            }
            portletMD.addContainerRuntime(containerRuntimeOptionMD);
         }

         //
         md.addPortlet(portletMD);
      }

      //
      for (StaxNavigator<Element> customPortletModeNav : nav.fork(Element.custom_portlet_mode))
      {
         CustomPortletModeMetaData customPortletModeMD = new CustomPortletModeMetaData();
         customPortletModeMD.setId(customPortletModeNav .getAttribute("id"));
         customPortletModeMD.setDescription(readLocalizedString(customPortletModeNav , Element.description));
         customPortletModeMD.setPortletMode(getContent(customPortletModeNav, Element.portlet_mode));
         if (customPortletModeNav .next(Element.portal_managed))
         {
            customPortletModeMD.setPortalManaged(customPortletModeNav .parseContent(ValueType.BOOLEAN));
         }
         md.addCustomPortletMode(customPortletModeMD);
      }

      //
      for (StaxNavigator<Element> customWindowStateNav : nav.fork(Element.custom_window_state))
      {
         CustomWindowStateMetaData customWindowStateMD = new CustomWindowStateMetaData();
         customWindowStateMD.setId(customWindowStateNav.getAttribute("id"));
         customWindowStateMD.setDescription(readLocalizedString(customWindowStateNav, Element.description));
         customWindowStateMD.setWindowState(getContent(customWindowStateNav, Element.window_state));
         md.addCustomWindowState(customWindowStateMD);
      }

      //
      for (StaxNavigator<Element> userAttributeNav : nav.fork(Element.user_attribute))
      {
         UserAttributeMetaData userAttributeMD = new UserAttributeMetaData();
         userAttributeMD.setId(userAttributeNav.getAttribute("id"));
         userAttributeMD.setDescription(readLocalizedString(userAttributeNav, Element.description));
         userAttributeMD.setName(getContent(userAttributeNav, Element.name));
         md.addUserAttribute(userAttributeMD);
      }

      //
      for (StaxNavigator<Element> securityConstraintNav  : nav.fork(Element.security_constraint))
      {
         SecurityConstraintMetaData securityConstraintMD = new SecurityConstraintMetaData();
         securityConstraintMD.setId(securityConstraintNav.getAttribute("id"));
         securityConstraintMD.setDisplayName(readLocalizedString(securityConstraintNav, Element.display_name));
         if (securityConstraintNav.next() != Element.portlet_collection)
         {
            throw new StaxNavException(nav.getLocation(), "Was expecting a portlet-collection element instead of " + securityConstraintNav.getName());
         }
         PortletCollectionMetaData portletCollectionMD = new PortletCollectionMetaData();
         while (securityConstraintNav.next(Element.portlet_name))
         {
            portletCollectionMD.addPortletname(securityConstraintNav.getContent());
         }
         securityConstraintMD.setPortletList(portletCollectionMD);
         if (securityConstraintNav.next() != Element.user_data_constraint)
         {
            throw new StaxNavException(nav.getLocation(), "Was expecting a security-constraint element instead of " + securityConstraintNav.getName());
         }
         UserDataConstraintMetaData userDataConstraintMD = new UserDataConstraintMetaData();
         userDataConstraintMD.setDescription(readLocalizedString(securityConstraintNav, Element.description));
         if (securityConstraintNav.next() != Element.transport_guarantee)
         {
            throw new StaxNavException(nav.getLocation(), "Was expecting a transport-guarantee element instead of " + securityConstraintNav.getName());
         }
         userDataConstraintMD.setTransportGuarantee(securityConstraintNav.parseContent(TRANSPORT_GUARANTEE));
         securityConstraintMD.setUserDataConstraint(userDataConstraintMD);
         md.addSecurityConstraint(securityConstraintMD);
      }

      //
      if (nav.sibling(Element.resource_bundle))
      {
         md.setResourceBundle(nav.getContent());
         nav.next();
      }

      //
      for (StaxNavigator<Element> filterNav : nav.fork(Element.filter))
      {
         if (version < 2)
         {
            throw new DeploymentException("Cannot declare filter with " + PORTLET_1_0 + " descriptor");
         }
         FilterMetaData filterMD = new FilterMetaData();
         filterMD.setDescription(readLocalizedString(filterNav, Element.description));
         filterMD.setDisplayName(readLocalizedString(filterNav, Element.display_name));
         filterMD.setFilterName(getContent(filterNav, Element.filter_name));
         filterMD.setFilterClass(getContent(filterNav, Element.filter_class));
         while (filterNav.next(Element.lifecycle))
         {
            filterMD.addLifecycle(filterNav.parseContent(LIFE_CYCLE));
         }
         for (InitParamMetaData initParamMD : readInitParams(filterNav))
         {
            filterMD.addInitParam(initParamMD);
         }
         md.addFilter(filterMD);
      }

      //
      for (StaxNavigator<Element> filterMappingNav : nav.fork(Element.filter_mapping))
      {
         if (version < 2)
         {
            throw new DeploymentException("Cannot declare filter mapping with " + PORTLET_1_0 + " descriptor");
         }
         FilterMappingMetaData filterMappingMD = new FilterMappingMetaData();
         filterMappingMD.setName(getContent(filterMappingNav, Element.filter_name));
         while (filterMappingNav.next(Element.portlet_name))
         {
            filterMappingMD.addPortletName(filterMappingNav.getContent());
         }
         md.addFilterMapping(filterMappingMD);
      }

      //
      if (nav.find(Element.default_namespace))
      {
         String val = nav.getContent();
         try
         {
            md.setDefaultNamespace(new URI(val));
         }
         catch (URISyntaxException e)
         {
            throw new DeploymentException("Invalid URI " + val, e);
         }
         nav.next();
      }

      //
      for (StaxNavigator<Element> eventDefinitionNav : nav.fork(Element.event_definition))
      {
         EventDefinitionMetaData eventDefinitionMD = new EventDefinitionMetaData();
         eventDefinitionMD.setId(eventDefinitionNav.getAttribute("id"));
         eventDefinitionMD.setDescription(readLocalizedString(eventDefinitionNav, Element.description));
         switch (eventDefinitionNav.next(NAME_OR_QNAME))
         {
            case name:
               eventDefinitionMD.setName(eventDefinitionNav.getContent());
               break;
            case qname:
               eventDefinitionMD.setQname(readQName(eventDefinitionNav));
               break;
         }
         while (eventDefinitionNav.next(Element.alias))
         {
            QName name = readQName(eventDefinitionNav);
            eventDefinitionMD.addAlias(name);
         }
         if (eventDefinitionNav.next(Element.value_type))
         {
            eventDefinitionMD.setValueType(eventDefinitionNav.getContent());
         }
         md.addEventDefinition(eventDefinitionMD);
      }

      //
      for (StaxNavigator<Element> publicRenderParameterNav : nav.fork(Element.public_render_parameter))
      {
         PublicRenderParameterMetaData publicRenderParameterMD = new PublicRenderParameterMetaData();
         publicRenderParameterMD.setId(publicRenderParameterNav.getAttribute("id"));
         publicRenderParameterMD.setDescription(readLocalizedString(publicRenderParameterNav, Element.description));
         publicRenderParameterMD.setIdentifier(getContent(publicRenderParameterNav, Element.identifier));
         switch (publicRenderParameterNav.next(NAME_OR_QNAME))
         {
            case name:
               publicRenderParameterMD.setName(publicRenderParameterNav.getContent());
               break;
            case qname:
               publicRenderParameterMD.setQname(readQName(publicRenderParameterNav));
               break;
         }
         while (publicRenderParameterNav.next(Element.alias))
         {
            QName name = readQName(publicRenderParameterNav);
            publicRenderParameterMD.addAlias(name);
         }
         md.addPublicRenderParameter(publicRenderParameterMD);
      }

      //
      for (StaxNavigator<Element> listenerNav : nav.fork(Element.listener))
      {
         ListenerMetaData listenerMD = new ListenerMetaData();
         listenerMD.setId(listenerNav.getAttribute("id"));
         listenerMD.setDescription(readLocalizedString(listenerNav, Element.description));
         listenerMD.setDisplayName(readLocalizedString(listenerNav, Element.display_name));
         listenerMD.setListenerClass(getContent(listenerNav, Element.listener_class));
         md.addListener(listenerMD);
      }

      //
      for (StaxNavigator<Element> containerRuntimeNav : nav.fork(Element.container_runtime_option))
      {
         ContainerRuntimeMetaData containerRuntimeOptionMD = new ContainerRuntimeMetaData();
         containerRuntimeOptionMD.setName(getContent(containerRuntimeNav, Element.name));
         while (containerRuntimeNav.next(Element.value))
         {
            containerRuntimeOptionMD.addValue(containerRuntimeNav.getContent());
         }
         md.addContainerRuntime(containerRuntimeOptionMD);
      }

      //
      return md;
   }
View Full Code Here


      }

      // portlet-app 2.0
      if (parent instanceof PortletApplication20MetaData)
      {
         PortletApplication20MetaData md = (PortletApplication20MetaData)parent;
         // add public-render-parameter
         if (child instanceof PublicRenderParameterMetaData)
         {
            md.addPublicRenderParameter((PublicRenderParameterMetaData)child);
         }
         // add event-defintion
         else if (child instanceof EventDefinitionMetaData)
         {
            md.addEventDefinition((EventDefinitionMetaData)child);
         }
         // add filter
         else if (child instanceof FilterMetaData)
         {
            FilterMetaData filter = (FilterMetaData)child;
            filter.setDisplayName(this.displayNames.getLocalizedString(filter));
            md.addFilter(filter);
         }
         // add filter-mapping
         else if (child instanceof FilterMappingMetaData)
         {
            md.addFilterMapping((FilterMappingMetaData)child);
         }
         // add container-runtime-option
         else if (child instanceof ContainerRuntimeMetaData)
         {
            md.addContainerRuntime((ContainerRuntimeMetaData)child);
         }
         // add listener
         else if (child instanceof ListenerMetaData)
         {
            ListenerMetaData listener = (ListenerMetaData)child;
            listener.setDisplayName(this.displayNames.getLocalizedString(listener));
            md.addListener(listener);
         }
      }

      // portlet
      if (parent instanceof PortletMetaData)
      {
         PortletMetaData md = (PortletMetaData)parent;
         // init-param
         if (child instanceof InitParamMetaData)
         {
            md.addInitParam((InitParamMetaData)child);
         }
         // supports
         else if (child instanceof SupportsMetaData)
         {
            md.addSupport((SupportsMetaData)child);
         }
         // supported-locale
         else if (child instanceof SupportedLocaleMetaData)
         {
            md.addSupportedLocale((SupportedLocaleMetaData)child);
         }
         // portlet-info
         else if (child instanceof PortletInfoMetaData)
         {
            md.setPortletInfo((PortletInfoMetaData)child);
         }
         // portlet-preferences
         else if (child instanceof PortletPreferencesMetaData)
         {
            md.setPortletPreferences((PortletPreferencesMetaData)child);
         }
         // security-role-ref
         else if (child instanceof SecurityRoleRefMetaData)
         {
            md.addSecurityRoleRef((SecurityRoleRefMetaData)child);
         }
         // supported-events
         else if (child instanceof EventDefinitionReferenceMetaData)
         {
            if ("supported-processing-event".equals(localName))
            {
               md.addSupportedProcessingEvent((EventDefinitionReferenceMetaData)child);
            }
            else if ("supported-publishing-event".equals(localName))
            {
               md.addSupportedPublishingEvent((EventDefinitionReferenceMetaData)child);
            }
         }
         // container-runtime-option
         else if (child instanceof ContainerRuntimeMetaData)
         {
            md.addContainerRuntime((ContainerRuntimeMetaData)child);
         }
      }

      // adding user-data-constraint and portlet-name(s) to security-constraint
      if (parent instanceof SecurityConstraintMetaData)
      {
         SecurityConstraintMetaData md = (SecurityConstraintMetaData)parent;
         // add user-data-constraint
         if (child instanceof UserDataConstraintMetaData)
         {
            md.setUserDataConstraint((UserDataConstraintMetaData)child);
         }
         // add portlet-collection
         else if (child instanceof PortletCollectionMetaData)
         {
            md.setPortletList((PortletCollectionMetaData)child);
         }
      }

      // filter
      if (parent instanceof FilterMetaData)
      {
         FilterMetaData md = (FilterMetaData)parent;
         // add init-param
         if (child instanceof InitParamMetaData)
         {
            md.addInitParam((InitParamMetaData)child);
         }
      }

      // add portlet-mode and window-state
      if (parent instanceof SupportsMetaData)
      {
         SupportsMetaData md = (SupportsMetaData)parent;
         if (child instanceof PortletModeMetaData)
         {
            md.addPortletMode((PortletModeMetaData)child);
         }
         else if (child instanceof WindowStateMetaData)
         {
            md.addWindowState((WindowStateMetaData)child);
         }
      }

      // add preference
      if (parent instanceof PortletPreferencesMetaData)
      {
         PortletPreferencesMetaData md = (PortletPreferencesMetaData)parent;
         if (child instanceof PortletPreferenceMetaData)
         {
            md.addPortletPreference((PortletPreferenceMetaData)child);
         }
      }
   }
View Full Code Here

   {

      // JSR 286 portlet-app attributes - default-namespace and resource-bundle.
      if (object instanceof PortletApplication20MetaData)
      {
         PortletApplication20MetaData md = (PortletApplication20MetaData)object;
         if ("resource-bundle".equals(localName))
         {
            md.setResourceBundle(value);
         }
         else if ("default-namespace".equals(localName))
         {
            try
            {
               md.setDefaultNamespace(new URI(value));
            }
            catch (URISyntaxException e)
            {
               log.error("Invalid syntax for default-namespace: " + value);
            }
         }
      }

      // portlet
      if (object instanceof PortletMetaData)
      {
         PortletMetaData md = (PortletMetaData)object;
         if ("portlet-name".equals(localName))
         {
            md.setPortletName(value);
         }
         else if ("portlet-class".equals(localName))
         {
            md.setPortletClass(value);
         }
         else if ("cache-scope".equals(localName) && PORTLET_JSR_286_NS.equals(nsURI))
         {
            md.setCacheScope(PortletCacheScopeEnum.valueOf(value));
         }
         else if ("expiration-cache".equals(localName))
         {
            md.setExpirationCache(Integer.valueOf(value));
         }
         else if ("resource-bundle".equals(localName))
         {
            md.setResourceBundle(value);
         }
         else if ("supported-public-render-parameter".equals(localName) && PORTLET_JSR_286_NS.equals(nsURI))
         {
            md.addSupportedPublicRenderParameter(value);
         }
      }

      if (object instanceof LocalizedDescriptionMetaData)
      {
         LocalizedDescriptionMetaData localized = (LocalizedDescriptionMetaData)object;
         if ("description".equals(localName))
         {
            localized.setDescription(value);
         }
         else if ("display-name".equals(localName))
         {
            localized.setDescription(value);
         }
      }

      // init-param
      if (object instanceof InitParamMetaData)
      {
         InitParamMetaData md = (InitParamMetaData)object;
         if ("name".equals(localName))
         {
            md.setName(value);
         }
         else if ("value".equals(localName))
         {
            md.setValue(value);
         }
      }

      // supports
      if (object instanceof SupportsMetaData)
      {
         SupportsMetaData md = (SupportsMetaData)object;
         if ("mime-type".equals(localName))
         {
            md.setMimeType(value);
         }
      }

      // supports --- portlet-mode
      if (object instanceof PortletModeMetaData)
      {
         PortletModeMetaData md = (PortletModeMetaData)object;
         if ("portlet-mode".equals(localName))
         {
            md.setPortletMode(org.gatein.pc.api.Mode.create(value));
         }
      }

      // supports --- window-state
      if (object instanceof WindowStateMetaData)
      {
         WindowStateMetaData md = (WindowStateMetaData)object;
         if ("window-state".equals(localName))
         {
            md.setWindowState(org.gatein.pc.api.WindowState.create(value));
         }
      }

      // supported-locale
      if (object instanceof SupportedLocaleMetaData)
      {
         SupportedLocaleMetaData md = (SupportedLocaleMetaData)object;
         if ("supported-locale".equals(localName))
         {
            md.setLocale(value);
         }
      }

      // portlet-info
      if (object instanceof PortletInfoMetaData)
      {
         PortletInfoMetaData md = (PortletInfoMetaData)object;
         if ("title".equals(localName))
         {
            md.setTitle(value);
         }
         else if ("short-title".equals(localName))
         {
            md.setShortTitle(value);
         }
         else if ("keywords".equals(localName))
         {
            md.setKeywords(value);
         }
      }

      // portlet-preferences
      if (object instanceof PortletPreferencesMetaData)
      {
         PortletPreferencesMetaData md = (PortletPreferencesMetaData)object;
         if ("preferences-validator".equals(localName))
         {
            md.setPreferenceValidator(value);
         }
      }

      // preference
      if (object instanceof PortletPreferenceMetaData)
      {
         PortletPreferenceMetaData md = (PortletPreferenceMetaData)object;
         if ("name".equals(localName))
         {
            md.setName(value);
         }
         else if ("value".equals(localName))
         {
            md.addValue(value);
         }
         else if ("read-only".equals(localName))
         {
            md.setReadOnly(Boolean.valueOf(value));
         }
      }

      // security-role-ref
      if (object instanceof SecurityRoleRefMetaData)
      {
         SecurityRoleRefMetaData md = (SecurityRoleRefMetaData)object;
         if ("role-name".equals(localName))
         {
            md.setRoleName(value);
         }
         else if ("role-link".equals(localName))
         {
            md.setRoleLink(value);
         }
      }

      // supported events
      if (object instanceof EventDefinitionReferenceMetaData)
      {
         EventDefinitionReferenceMetaData md = (EventDefinitionReferenceMetaData)object;
         if ("qname".equals(localName))
         {
            md.setQname(nav.resolveQName(value));
         }
         else if ("name".equals(localName))
         {
            md.setName(value);
         }
      }

      // custom-portlet-mode
      if (object instanceof CustomPortletModeMetaData)
      {
         CustomPortletModeMetaData mode = (CustomPortletModeMetaData)object;
         if ("portlet-mode".equals(localName))
         {
            mode.setPortletMode(value);
         }
         else if ("portal-managed".equals(localName) && PORTLET_JSR_286_NS.equals(nsURI))
         {
            mode.setPortalManaged(Boolean.parseBoolean(value));
         }
      }

      // custom-window-state
      if (object instanceof CustomWindowStateMetaData)
      {
         CustomWindowStateMetaData md = (CustomWindowStateMetaData)object;
         if ("window-state".equals(localName))
         {
            md.setWindowState(value);
         }
      }

      // user-attribute
      if (object instanceof UserAttributeMetaData)
      {
         UserAttributeMetaData md = (UserAttributeMetaData)object;
         if ("name".equals(localName))
         {
            md.setName(value);
         }
      }

      // user-data-constraint
      if (object instanceof UserDataConstraintMetaData)
      {
         UserDataConstraintMetaData md = (UserDataConstraintMetaData)object;
         if ("transport-guarantee".equals(localName))
         {
            md.setTransportGuarantee(TransportGuarantee.valueOf(value));
         }
      }

      // portlet-collection in security-constraint
      if (object instanceof PortletCollectionMetaData)
      {
         PortletCollectionMetaData md = (PortletCollectionMetaData)object;
         if ("portlet-name".equals(localName))
         {
            md.addPortletname(value);
         }
      }

      // filter
      if (object instanceof FilterMetaData && PORTLET_JSR_286_NS.equals(nsURI))
      {
         FilterMetaData md = (FilterMetaData)object;
         if ("filter-class".equals(localName))
         {
            md.setFilterClass(value);
         }
         else if ("filter-name".equals(localName))
         {
            md.setFilterName(value);
         }
         else if ("lifecycle".equals(localName))
         {
            int end = value.length() - "_PHASE".length();
            String lifeCycle = value.substring(0, end > 0 ? end : 0);
            try
            {
               md.addLifecycle(LifeCyclePhase.valueOf(lifeCycle));
            }
            catch (IllegalArgumentException e)
            {
               throw new IllegalArgumentException("Invalid value for lifecycle. Valid values are [RENDER_PHASE, RESOURCE_PHASE, ACTION_PHASE, EVENT_PHASE]");
            }
         }
      }

      // filter-mapping
      if (object instanceof FilterMappingMetaData && PORTLET_JSR_286_NS.equals(nsURI))
      {
         FilterMappingMetaData md = (FilterMappingMetaData)object;
         if ("filter-name".equals(localName))
         {
            md.setName(value);
         }
         if ("portlet-name".equals(localName))
         {
            md.addPortletName(value);
         }
      }

      // event-defintion
      if (object instanceof EventDefinitionMetaData && PORTLET_JSR_286_NS.equals(nsURI))
      {
         EventDefinitionMetaData md = (EventDefinitionMetaData)object;
         if ("name".equals(localName))
         {
            md.setName(value);
         }
         else if ("qname".equals(localName))
         {
            md.setQname(nav.resolveQName(value));
         }
         else if ("value-type".equals(localName))
         {
            md.setValueType(value);
         }
         else if ("alias".equals(localName))
         {
            md.addAlias(nav.resolveQName(value));
         }
      }

      // public-render-parameter
      if (object instanceof PublicRenderParameterMetaData && PORTLET_JSR_286_NS.equals(nsURI))
      {
         PublicRenderParameterMetaData md = (PublicRenderParameterMetaData)object;
         if ("identifier".equals(localName))
         {
            md.setIdentifier(value);
         }
         else if ("name".equals(localName))
         {
            md.setName(value);
         }
         else if ("qname".equals(localName))
         {
            md.setQname(nav.resolveQName(value));
         }
         else if ("alias".equals(localName))
         {
            md.addAlias(nav.resolveQName(value));
         }
      }

      // container-runtime-option
      if (object instanceof ContainerRuntimeMetaData && PORTLET_JSR_286_NS.equals(nsURI))
      {
         ContainerRuntimeMetaData md = (ContainerRuntimeMetaData)object;
         if ("name".equals(localName))
         {
            md.setName(value);
         }
         else if ("value".equals(localName))
         {
            md.addValue(value);
         }
      }

      // listener
      if (object instanceof ListenerMetaData && PORTLET_JSR_286_NS.equals(nsURI))
      {
         ListenerMetaData md = (ListenerMetaData)object;
         if ("listener-class".equals(localName))
         {
            md.setListenerClass(value);
         }
      }
   }
View Full Code Here

   private void fixMetaData(PortletApplication10MetaData portletApplicationMD)
   {
      if (portletApplicationMD instanceof PortletApplication20MetaData)
      {
         PortletApplication20MetaData tmp = (PortletApplication20MetaData)portletApplicationMD;
         if (tmp.getEvents() == null)
         {
            tmp.setEvents(EMPTY_EVENT_DEFINITION_LIST);
         }
         if (tmp.getPublicRenderParameters() == null)
         {
            tmp.setPublicRenderParameters(EMPTY_PUBLIC_RENDER_PARAMETER_LIST);
         }
         if (tmp.getDefaultNamespace() == null)
         {
            try
            {
               tmp.setDefaultNamespace(new URI(XMLConstants.NULL_NS_URI));
            }
            catch (URISyntaxException e)
            {
               throw new Error(e);
            }
         }
         if (tmp.getListeners() == null)
         {
            tmp.setListeners(EMPTY_LISTENER_LIST);
         }
         if (tmp.getFilters() == null)
         {
            tmp.setFilters(EMPTY_FILTER_MAP);
         }
         for (FilterMetaData filterMD : tmp.getFilters().values())
         {
            if (filterMD.getInitParams() == null)
            {
               filterMD.setInitParams(EMPTY_INIT_PARAM_LIST);
            }
         }
         if (tmp.getFilterMapping() == null)
         {
            tmp.setFilterMapping(EMPTY_FILTER_MAPPING_LIST);
         }
         if (tmp.getContainerRuntimeOptions() == null)
         {
            tmp.setContainerRuntimeOptions(EMPTY_CONTAINER_RUNTIME_OPTION_MAP);
         }
      }

      //
      if (portletApplicationMD.getCustomPortletModes() == null)
View Full Code Here

      String defaultNamespace = XMLConstants.NULL_NS_URI;
      List<ContainerListenerInfo> listeners = Collections.emptyList();
      Map<String, ContainerFilterInfo> allFilters = new HashMap<String, ContainerFilterInfo>();
      if (this.portletApplicationMD instanceof PortletApplication20MetaData)
      {
         PortletApplication20MetaData tmp = (PortletApplication20MetaData)this.portletApplicationMD;

         //
         defaultNamespace = tmp.getDefaultNamespace() != null ? tmp.getDefaultNamespace().toString() : null;

         //
         for (EventDefinitionMetaData eventDefinitionMD : tmp.getEvents())
         {
            try
            {
               ContainerEventInfo event = build(eventDefinitionMD);
               events.put(event.getName(), event);
            }
            catch (NoSuchClassException e)
            {
               log.error("Cannot load event class " + e.getClassName(), e);
            }
         }

         //
         for (PublicRenderParameterMetaData parameterMD : tmp.getPublicRenderParameters())
         {
            ContainerParameterInfo parameter = build(parameterMD);

            //
            publicParameters.put(parameter.getId(), parameter);
         }

         //
         Map<String, RuntimeOptionInfo> applicationOptions = build(tmp.getContainerRuntimeOptions().values());
         if (applicationOptions != null)
         {
            this.applicationOptions.putAll(applicationOptions);
         }

         //
         listeners = new ArrayList<ContainerListenerInfo>(tmp.getListeners().size());
         for (ListenerMetaData listenerMD : tmp.getListeners())
         {
            ContainerListenerInfo listener = build(listenerMD);
            listeners.add(listener);
         }
         listeners = Collections.unmodifiableList(listeners);

         //
         for (FilterMetaData filterMD : tmp.getFilterCollection())
         {
            ContainerFilterInfo filter = build(filterMD);
            allFilters.put(filter.getName(), filter);
         }
      }
View Full Code Here

      {
         bytes = IOTools.getBytes(is);
         is = new ByteArrayInputStream(bytes);
      }

      PortletApplication20MetaData md = new PortletApplication20MetaData();

      //
      inputFactory.setProperty("javax.xml.stream.isCoalescing", true);
      XMLStreamReader stream = inputFactory.createXMLStreamReader(is);
      StaxNavigator<Element> nav = StaxNavigatorFactory.create(new Naming.Enumerated.Simple<Element>(Element.class, null), stream);

      // We want to trim content (mandated by the spec)
      nav.setTrimContent(true);

      // Get the root element qname
      QName qname = nav.getQName();
      String rootNS = qname.getNamespaceURI();

      // Determine the correct version to parse
      int version;
      if (PORTLET_1_0.equals(rootNS))
      {
         md.setVersion("1.0");
         version = 1;
      }
      else if (PORTLET_2_0.equals(rootNS))
      {
         md.setVersion("2.0");
         version = 2;
      }
      else
      {
         throw new StaxNavException("Illegal portlet xml namespace " + rootNS);
      }

      // Perform schema validation if required
      if (schemaValidation)
      {
         XSD xsd = version == 1 ? XSD.PORTLET_1_0 : XSD.PORTLET_2_0;
         xsd.validate(new StreamSource(new ByteArrayInputStream(bytes)));
      }

      //
      assert Element.portlet_app == nav.getName();

      //
      if (nav.child() == null)
      {
         return md;
      }

      //
      for (StaxNavigator<Element> portletNav : nav.fork(Element.portlet))
      {
         PortletMetaData portletMD = new PortletMetaData();

         //
         portletMD.setId(portletNav.getAttribute("id"));
         portletMD.setDescription(readLocalizedString(portletNav, Element.description));
         portletMD.setPortletName(getContent(portletNav, Element.portlet_name));
         portletMD.setDisplayName(readLocalizedString(portletNav, Element.display_name));
         portletMD.setPortletClass(getContent(portletNav, Element.portlet_class));

         //
         for (InitParamMetaData initParamMD : readInitParams(portletNav))
         {
            portletMD.addInitParam(initParamMD);
         }

         //
         if (portletNav.next(Element.expiration_cache))
         {
            portletMD.setExpirationCache(Integer.parseInt(portletNav.getContent()));
         }
         if (portletNav.next(Element.cache_scope))
         {
            portletMD.setCacheScope(PortletCacheScopeEnum.valueOf(portletNav.getContent()));
         }

         //
         while (portletNav.next(Element.supports))
         {
            SupportsMetaData supportsMD = new SupportsMetaData();
            supportsMD.setId(portletNav.getAttribute("id"));
            supportsMD.setMimeType(getContent(portletNav, Element.mime_type));
            while (portletNav.next(Element.portlet_mode)) {
               PortletModeMetaData portletModeMD = new PortletModeMetaData();
               portletModeMD.setPortletMode(Mode.create(portletNav.getContent()));
               supportsMD.addPortletMode(portletModeMD);
            }
            while (portletNav.next(Element.window_state)) {
               WindowStateMetaData windowStateMD = new WindowStateMetaData();
               windowStateMD.setWindowState(WindowState.create(portletNav.getContent()));
               supportsMD.addWindowState(windowStateMD);
            }
            portletMD.addSupport(supportsMD);
         }

         //
         while (portletNav.next(Element.supported_locale))
         {
            SupportedLocaleMetaData supportedLocaleMD = new SupportedLocaleMetaData();
            supportedLocaleMD.setLocale(portletNav.getContent());
            portletMD.addSupportedLocale(supportedLocaleMD);
         }
         if (portletNav.next(Element.resource_bundle))
         {
            portletMD.setResourceBundle(portletNav.getContent());
         }

         //
         if (portletNav.next(Element.portlet_info))
         {
            PortletInfoMetaData portletInfoMD = new PortletInfoMetaData();
            if (portletNav.next(Element.title))
            {
               portletInfoMD.setTitle(portletNav.getContent());
            }
            if (portletNav.next(Element.short_title))
            {
               portletInfoMD.setShortTitle(portletNav.getContent());
            }
            if (portletNav.next(Element.keywords))
            {
               portletInfoMD.setKeywords(portletNav.getContent());
            }
            portletMD.setPortletInfo(portletInfoMD);
         }

         //
         if (portletNav.next(Element.portlet_preferences))
         {
            PortletPreferencesMetaData portletPreferencesMD = new PortletPreferencesMetaData();
            while (portletNav.next(Element.preference))
            {
               PortletPreferenceMetaData portletPreferenceMD = new PortletPreferenceMetaData();
               portletPreferenceMD.setName(getContent(portletNav, Element.name));
               while (portletNav.next(Element.value))
               {
                  portletPreferenceMD.addValue(portletNav.getContent());
               }
               if (portletNav.next(Element.read_only))
               {
                  portletPreferenceMD.setReadOnly(portletNav.parseContent(ValueType.BOOLEAN));
               }
               portletPreferencesMD.addPortletPreference(portletPreferenceMD);
            }
            if (portletNav.next(Element.preferences_validator))
            {
               portletPreferencesMD.setPreferenceValidator(portletNav.getContent());
            }
            portletMD.setPortletPreferences(portletPreferencesMD);
         }

         //
         while (portletNav.next(Element.security_role_ref))
         {
            SecurityRoleRefMetaData securityRoleRefMD = new SecurityRoleRefMetaData();
            securityRoleRefMD.setDescription(readLocalizedString(portletNav, Element.description));
            securityRoleRefMD.setRoleName(getContent(portletNav, Element.role_name));
            if (portletNav.next(Element.role_link))
            {
               securityRoleRefMD.setRoleLink(portletNav.getContent());
            }
            portletMD.addSecurityRoleRef(securityRoleRefMD);
         }

         //
         while (portletNav.next(Element.supported_processing_event) || portletNav.next(Element.supported_publishing_event))
         {
            boolean processing = portletNav.getName() == Element.supported_processing_event;
            EventDefinitionReferenceMetaData eventDefinitionReferenceMD = new EventDefinitionReferenceMetaData();
            switch (portletNav.next(NAME_OR_QNAME))
            {
               case name:
                  eventDefinitionReferenceMD.setName(portletNav.getContent());
                  break;
               case qname:
                  eventDefinitionReferenceMD.setQname(readQName(portletNav));
                  break;
            }
            if (processing)
            {
               portletMD.addSupportedProcessingEvent(eventDefinitionReferenceMD);
            }
            else
            {
               portletMD.addSupportedPublishingEvent(eventDefinitionReferenceMD);
            }
         }
         while (portletNav.next(Element.supported_public_render_parameter))
         {
            portletMD.addSupportedPublicRenderParameter(portletNav.getContent());
         }
         while (portletNav.next(Element.container_runtime_option))
         {
            ContainerRuntimeMetaData containerRuntimeOptionMD = new ContainerRuntimeMetaData();
            containerRuntimeOptionMD.setName(getContent(portletNav, Element.name));
            while (portletNav.next(Element.value))
            {
               containerRuntimeOptionMD.addValue(portletNav.getContent());
            }
            portletMD.addContainerRuntime(containerRuntimeOptionMD);
         }

         //
         md.addPortlet(portletMD);
      }

      //
      for (StaxNavigator<Element> customPortletModeNav : nav.fork(Element.custom_portlet_mode))
      {
         CustomPortletModeMetaData customPortletModeMD = new CustomPortletModeMetaData();
         customPortletModeMD.setId(customPortletModeNav .getAttribute("id"));
         customPortletModeMD.setDescription(readLocalizedString(customPortletModeNav , Element.description));
         customPortletModeMD.setPortletMode(getContent(customPortletModeNav, Element.portlet_mode));
         if (customPortletModeNav .next(Element.portal_managed))
         {
            customPortletModeMD.setPortalManaged(customPortletModeNav .parseContent(ValueType.BOOLEAN));
         }
         md.addCustomPortletMode(customPortletModeMD);
      }

      //
      for (StaxNavigator<Element> customWindowStateNav : nav.fork(Element.custom_window_state))
      {
         CustomWindowStateMetaData customWindowStateMD = new CustomWindowStateMetaData();
         customWindowStateMD.setId(customWindowStateNav.getAttribute("id"));
         customWindowStateMD.setDescription(readLocalizedString(customWindowStateNav, Element.description));
         customWindowStateMD.setWindowState(getContent(customWindowStateNav, Element.window_state));
         md.addCustomWindowState(customWindowStateMD);
      }

      //
      for (StaxNavigator<Element> userAttributeNav : nav.fork(Element.user_attribute))
      {
         UserAttributeMetaData userAttributeMD = new UserAttributeMetaData();
         userAttributeMD.setId(userAttributeNav.getAttribute("id"));
         userAttributeMD.setDescription(readLocalizedString(userAttributeNav, Element.description));
         userAttributeMD.setName(getContent(userAttributeNav, Element.name));
         md.addUserAttribute(userAttributeMD);
      }

      //
      for (StaxNavigator<Element> securityConstraintNav  : nav.fork(Element.security_constraint))
      {
         SecurityConstraintMetaData securityConstraintMD = new SecurityConstraintMetaData();
         securityConstraintMD.setId(securityConstraintNav.getAttribute("id"));
         securityConstraintMD.setDisplayName(readLocalizedString(securityConstraintNav, Element.display_name));
         if (securityConstraintNav.next() != Element.portlet_collection)
         {
            throw new StaxNavException(nav.getLocation(), "Was expecting a portlet-collection element instead of " + securityConstraintNav.getName());
         }
         PortletCollectionMetaData portletCollectionMD = new PortletCollectionMetaData();
         while (securityConstraintNav.next(Element.portlet_name))
         {
            portletCollectionMD.addPortletname(securityConstraintNav.getContent());
         }
         securityConstraintMD.setPortletList(portletCollectionMD);
         if (securityConstraintNav.next() != Element.user_data_constraint)
         {
            throw new StaxNavException(nav.getLocation(), "Was expecting a security-constraint element instead of " + securityConstraintNav.getName());
         }
         UserDataConstraintMetaData userDataConstraintMD = new UserDataConstraintMetaData();
         userDataConstraintMD.setDescription(readLocalizedString(securityConstraintNav, Element.description));
         if (securityConstraintNav.next() != Element.transport_guarantee)
         {
            throw new StaxNavException(nav.getLocation(), "Was expecting a transport-guarantee element instead of " + securityConstraintNav.getName());
         }
         userDataConstraintMD.setTransportGuarantee(securityConstraintNav.parseContent(TRANSPORT_GUARANTEE));
         securityConstraintMD.setUserDataConstraint(userDataConstraintMD);
         md.addSecurityConstraint(securityConstraintMD);
      }

      //
      if (nav.sibling(Element.resource_bundle))
      {
         md.setResourceBundle(nav.getContent());
         nav.next();
      }

      //
      for (StaxNavigator<Element> filterNav : nav.fork(Element.filter))
      {
         if (version < 2)
         {
            throw new Exception("Cannot declare filter with " + PORTLET_1_0 + " descriptor");
         }
         FilterMetaData filterMD = new FilterMetaData();
         filterMD.setDescription(readLocalizedString(filterNav, Element.description));
         filterMD.setDisplayName(readLocalizedString(filterNav, Element.display_name));
         filterMD.setFilterName(getContent(filterNav, Element.filter_name));
         filterMD.setFilterClass(getContent(filterNav, Element.filter_class));
         while (filterNav.next(Element.lifecycle))
         {
            filterMD.addLifecycle(filterNav.parseContent(LIFE_CYCLE));
         }
         for (InitParamMetaData initParamMD : readInitParams(filterNav))
         {
            filterMD.addInitParam(initParamMD);
         }
         md.addFilter(filterMD);
      }

      //
      for (StaxNavigator<Element> filterMappingNav : nav.fork(Element.filter_mapping))
      {
         if (version < 2)
         {
            throw new Exception("Cannot declare filter mapping with " + PORTLET_1_0 + " descriptor");
         }
         FilterMappingMetaData filterMappingMD = new FilterMappingMetaData();
         filterMappingMD.setName(getContent(filterMappingNav, Element.filter_name));
         while (filterMappingNav.next(Element.portlet_name))
         {
            filterMappingMD.addPortletName(filterMappingNav.getContent());
         }
         md.addFilterMapping(filterMappingMD);
      }

      //
      if (nav.find(Element.default_namespace))
      {
         md.setDefaultNamespace(new URI(nav.getContent()));
         nav.next();
      }

      //
      for (StaxNavigator<Element> eventDefinitionNav : nav.fork(Element.event_definition))
      {
         EventDefinitionMetaData eventDefinitionMD = new EventDefinitionMetaData();
         eventDefinitionMD.setId(eventDefinitionNav.getAttribute("id"));
         eventDefinitionMD.setDescription(readLocalizedString(eventDefinitionNav, Element.description));
         switch (eventDefinitionNav.next(NAME_OR_QNAME))
         {
            case name:
               eventDefinitionMD.setName(eventDefinitionNav.getContent());
               break;
            case qname:
               eventDefinitionMD.setQname(readQName(eventDefinitionNav));
               break;
         }
         while (eventDefinitionNav.next(Element.alias))
         {
            QName name = readQName(eventDefinitionNav);
            eventDefinitionMD.addAlias(name);
         }
         if (eventDefinitionNav.next(Element.value_type))
         {
            eventDefinitionMD.setValueType(eventDefinitionNav.getContent());
         }
         md.addEventDefinition(eventDefinitionMD);
      }

      //
      for (StaxNavigator<Element> publicRenderParameterNav : nav.fork(Element.public_render_parameter))
      {
         PublicRenderParameterMetaData publicRenderParameterMD = new PublicRenderParameterMetaData();
         publicRenderParameterMD.setId(publicRenderParameterNav.getAttribute("id"));
         publicRenderParameterMD.setDescription(readLocalizedString(publicRenderParameterNav, Element.description));
         publicRenderParameterMD.setIdentifier(getContent(publicRenderParameterNav, Element.identifier));
         switch (publicRenderParameterNav.next(NAME_OR_QNAME))
         {
            case name:
               publicRenderParameterMD.setName(publicRenderParameterNav.getContent());
               break;
            case qname:
               publicRenderParameterMD.setQname(readQName(publicRenderParameterNav));
               break;
         }
         while (publicRenderParameterNav.next(Element.alias))
         {
            QName name = readQName(publicRenderParameterNav);
            publicRenderParameterMD.addAlias(name);
         }
         md.addPublicRenderParameter(publicRenderParameterMD);
      }

      //
      for (StaxNavigator<Element> listenerNav : nav.fork(Element.listener))
      {
         ListenerMetaData listenerMD = new ListenerMetaData();
         listenerMD.setId(listenerNav.getAttribute("id"));
         listenerMD.setDescription(readLocalizedString(listenerNav, Element.description));
         listenerMD.setDisplayName(readLocalizedString(listenerNav, Element.display_name));
         listenerMD.setListenerClass(getContent(listenerNav, Element.listener_class));
         md.addListener(listenerMD);
      }

      //
      for (StaxNavigator<Element> containerRuntimeNav : nav.fork(Element.container_runtime_option))
      {
         ContainerRuntimeMetaData containerRuntimeOptionMD = new ContainerRuntimeMetaData();
         containerRuntimeOptionMD.setName(getContent(containerRuntimeNav, Element.name));
         while (containerRuntimeNav.next(Element.value))
         {
            containerRuntimeOptionMD.addValue(containerRuntimeNav.getContent());
         }
         md.addContainerRuntime(containerRuntimeOptionMD);
      }

      //
      return md;
   }
View Full Code Here

   }

   public PortletApplication20MetaData build(InputStream is) throws Exception
   {

      PortletApplication20MetaData md = new PortletApplication20MetaData();

      XMLInputFactory factory = XMLInputFactory.newInstance();
      factory.setProperty("javax.xml.stream.isCoalescing", true);
      XMLStreamReader stream = factory.createXMLStreamReader(is);
      StaxNavigator<Element> nav = StaxNavigatorFactory.create(new Naming.Enumerated.Simple<Element>(Element.class, null), stream);
     
      nav.setTrimContent(true);

      // For now we do it this way
      // but it's not correct
      String defaultNS = nav.getNamespaceByPrefix("");
      int version;
      if (PORTLET_1_0.equals(defaultNS))
      {
         md.setVersion("1.0");
         version = 1;
      }
      else if (PORTLET_2_0.equals(defaultNS))
      {
         md.setVersion("2.0");
         version = 2;
      }
      else
      {
         throw new UnsupportedOperationException();
      }

      //
      assert Element.portlet_app == nav.getName();

      //
      if (nav.child() == null)
      {
         return md;
      }

      //
      for (StaxNavigator<Element> portletNav : nav.fork(Element.portlet))
      {
         PortletMetaData portletMD = new PortletMetaData();

         //
         portletMD.setId(portletNav.getAttribute("id"));
         portletMD.setDescription(readLocalizedString(portletNav, Element.description));
         portletMD.setPortletName(getContent(portletNav, Element.portlet_name));
         portletMD.setDisplayName(readLocalizedString(portletNav, Element.display_name));
         portletMD.setPortletClass(getContent(portletNav, Element.portlet_class));

         //
         for (InitParamMetaData initParamMD : readInitParams(portletNav))
         {
            portletMD.addInitParam(initParamMD);
         }

         //
         if (portletNav.next(Element.expiration_cache))
         {
            portletMD.setExpirationCache(Integer.parseInt(portletNav.getContent()));
         }
         if (portletNav.next(Element.cache_scope))
         {
            portletMD.setCacheScope(PortletCacheScopeEnum.valueOf(portletNav.getContent()));
         }

         //
         while (portletNav.next(Element.supports))
         {
            SupportsMetaData supportsMD = new SupportsMetaData();
            supportsMD.setId(portletNav.getAttribute("id"));
            supportsMD.setMimeType(getContent(portletNav, Element.mime_type));
            while (portletNav.next(Element.portlet_mode)) {
               PortletModeMetaData portletModeMD = new PortletModeMetaData();
               portletModeMD.setPortletMode(Mode.create(portletNav.getContent()));
               supportsMD.addPortletMode(portletModeMD);
            }
            while (portletNav.next(Element.window_state)) {
               WindowStateMetaData windowStateMD = new WindowStateMetaData();
               windowStateMD.setWindowState(WindowState.create(portletNav.getContent()));
               supportsMD.addWindowState(windowStateMD);
            }
            portletMD.addSupport(supportsMD);
         }

         //
         while (portletNav.next(Element.supported_locale))
         {
            SupportedLocaleMetaData supportedLocaleMD = new SupportedLocaleMetaData();
            supportedLocaleMD.setLocale(portletNav.getContent());
            portletMD.addSupportedLocale(supportedLocaleMD);
         }
         if (portletNav.next(Element.resource_bundle))
         {
            portletMD.setResourceBundle(portletNav.getContent());
         }

         //
         if (portletNav.next(Element.portlet_info))
         {
            PortletInfoMetaData portletInfoMD = new PortletInfoMetaData();
            if (portletNav.next(Element.title))
            {
               portletInfoMD.setTitle(portletNav.getContent());
            }
            if (portletNav.next(Element.short_title))
            {
               portletInfoMD.setShortTitle(portletNav.getContent());
            }
            if (portletNav.next(Element.keywords))
            {
               portletInfoMD.setKeywords(portletNav.getContent());
            }
            portletMD.setPortletInfo(portletInfoMD);
         }

         //
         if (portletNav.next(Element.portlet_preferences))
         {
            PortletPreferencesMetaData portletPreferencesMD = new PortletPreferencesMetaData();
            while (portletNav.next(Element.preference))
            {
               PortletPreferenceMetaData portletPreferenceMD = new PortletPreferenceMetaData();
               portletPreferenceMD.setName(getContent(portletNav, Element.name));
               while (portletNav.next(Element.value))
               {
                  portletPreferenceMD.addValue(portletNav.getContent());
               }
               if (portletNav.next(Element.read_only))
               {
                  portletPreferenceMD.setReadOnly(portletNav.parseContent(ValueType.BOOLEAN));
               }
               portletPreferencesMD.addPortletPreference(portletPreferenceMD);
            }
            if (portletNav.next(Element.preferences_validator))
            {
               portletPreferencesMD.setPreferenceValidator(portletNav.getContent());
            }
            portletMD.setPortletPreferences(portletPreferencesMD);
         }

         //
         while (portletNav.next(Element.security_role_ref))
         {
            SecurityRoleRefMetaData securityRoleRefMD = new SecurityRoleRefMetaData();
            securityRoleRefMD.setDescription(readLocalizedString(portletNav, Element.description));
            securityRoleRefMD.setRoleName(getContent(portletNav, Element.role_name));
            if (portletNav.next(Element.role_link))
            {
               securityRoleRefMD.setRoleLink(portletNav.getContent());
            }
            portletMD.addSecurityRoleRef(securityRoleRefMD);
         }

         //
         while (portletNav.next(Element.supported_processing_event) || portletNav.next(Element.supported_publishing_event))
         {
            boolean processing = portletNav.getName() == Element.supported_processing_event;
            EventDefinitionReferenceMetaData eventDefinitionReferenceMD = new EventDefinitionReferenceMetaData();
            switch (portletNav.next(NAME_OR_QNAME))
            {
               case name:
                  eventDefinitionReferenceMD.setName(portletNav.getContent());
                  break;
               case qname:
                  eventDefinitionReferenceMD.setQname(readQName(portletNav));
                  break;
            }
            if (processing)
            {
               portletMD.addSupportedProcessingEvent(eventDefinitionReferenceMD);
            }
            else
            {
               portletMD.addSupportedPublishingEvent(eventDefinitionReferenceMD);
            }
         }
         while (portletNav.next(Element.supported_public_render_parameter))
         {
            portletMD.addSupportedPublicRenderParameter(portletNav.getContent());
         }
         while (portletNav.next(Element.container_runtime_option))
         {
            ContainerRuntimeMetaData containerRuntimeOptionMD = new ContainerRuntimeMetaData();
            containerRuntimeOptionMD.setName(getContent(portletNav, Element.name));
            while (portletNav.next(Element.value))
            {
               containerRuntimeOptionMD.addValue(portletNav.getContent());
            }
            portletMD.addContainerRuntime(containerRuntimeOptionMD);
         }

         //
         md.addPortlet(portletMD);
      }

      //
      for (StaxNavigator<Element> customPortletModeNav : nav.fork(Element.custom_portlet_mode))
      {
         CustomPortletModeMetaData customPortletModeMD = new CustomPortletModeMetaData();
         customPortletModeMD.setId(customPortletModeNav .getAttribute("id"));
         customPortletModeMD.setDescription(readLocalizedString(customPortletModeNav , Element.description));
         customPortletModeMD.setPortletMode(getContent(customPortletModeNav, Element.portlet_mode));
         if (customPortletModeNav .next(Element.portal_managed))
         {
            customPortletModeMD.setPortalManaged(customPortletModeNav .parseContent(ValueType.BOOLEAN));
         }
         md.addCustomPortletMode(customPortletModeMD);
      }

      //
      for (StaxNavigator<Element> customWindowStateNav : nav.fork(Element.custom_window_state))
      {
         CustomWindowStateMetaData customWindowStateMD = new CustomWindowStateMetaData();
         customWindowStateMD.setId(customWindowStateNav.getAttribute("id"));
         customWindowStateMD.setDescription(readLocalizedString(customWindowStateNav, Element.description));
         customWindowStateMD.setWindowState(getContent(customWindowStateNav, Element.window_state));
         md.addCustomWindowState(customWindowStateMD);
      }

      //
      for (StaxNavigator<Element> userAttributeNav : nav.fork(Element.user_attribute))
      {
         UserAttributeMetaData userAttributeMD = new UserAttributeMetaData();
         userAttributeMD.setId(userAttributeNav.getAttribute("id"));
         userAttributeMD.setDescription(readLocalizedString(userAttributeNav, Element.description));
         userAttributeMD.setName(getContent(userAttributeNav, Element.name));
         md.addUserAttribute(userAttributeMD);
      }

      //
      for (StaxNavigator<Element> securityConstraintNav  : nav.fork(Element.security_constraint))
      {
         SecurityConstraintMetaData securityConstraintMD = new SecurityConstraintMetaData();
         securityConstraintMD.setId(securityConstraintNav.getAttribute("id"));
         securityConstraintMD.setDisplayName(readLocalizedString(securityConstraintNav, Element.display_name));
         if (securityConstraintNav.next() != Element.portlet_collection)
         {
            throw new StaxNavException(nav.getLocation(), "Was expecting a portlet-collection element instead of " + securityConstraintNav.getName());
         }
         PortletCollectionMetaData portletCollectionMD = new PortletCollectionMetaData();
         while (securityConstraintNav.next(Element.portlet_name))
         {
            portletCollectionMD.addPortletname(securityConstraintNav.getContent());
         }
         securityConstraintMD.setPortletList(portletCollectionMD);
         if (securityConstraintNav.next() != Element.user_data_constraint)
         {
            throw new StaxNavException(nav.getLocation(), "Was expecting a security-constraint element instead of " + securityConstraintNav.getName());
         }
         UserDataConstraintMetaData userDataConstraintMD = new UserDataConstraintMetaData();
         userDataConstraintMD.setDescription(readLocalizedString(securityConstraintNav, Element.description));
         if (securityConstraintNav.next() != Element.transport_guarantee)
         {
            throw new StaxNavException(nav.getLocation(), "Was expecting a transport-guarantee element instead of " + securityConstraintNav.getName());
         }
         userDataConstraintMD.setTransportGuarantee(securityConstraintNav.parseContent(TRANSPORT_GUARANTEE));
         securityConstraintMD.setUserDataConstraint(userDataConstraintMD);
         md.addSecurityConstraint(securityConstraintMD);
      }

      //
      if (nav.find(Element.resource_bundle))
      {
         md.setResourceBundle(nav.getContent());
         nav.next();
      }

      //
      for (StaxNavigator<Element> filterNav : nav.fork(Element.filter))
      {
         if (version < 2)
         {
            throw new Exception("Cannot declare filter with " + PORTLET_1_0 + " descriptor");
         }
         FilterMetaData filterMD = new FilterMetaData();
         filterMD.setDescription(readLocalizedString(filterNav, Element.description));
         filterMD.setDisplayName(readLocalizedString(filterNav, Element.display_name));
         filterMD.setFilterName(getContent(filterNav, Element.filter_name));
         filterMD.setFilterClass(getContent(filterNav, Element.filter_class));
         while (filterNav.next(Element.lifecycle))
         {
            filterMD.addLifecycle(filterNav.parseContent(LIFE_CYCLE));
         }
         for (InitParamMetaData initParamMD : readInitParams(filterNav))
         {
            filterMD.addInitParam(initParamMD);
         }
         md.addFilter(filterMD);
      }

      //
      for (StaxNavigator<Element> filterMappingNav : nav.fork(Element.filter_mapping))
      {
         if (version < 2)
         {
            throw new Exception("Cannot declare filter mapping with " + PORTLET_1_0 + " descriptor");
         }
         FilterMappingMetaData filterMappingMD = new FilterMappingMetaData();
         filterMappingMD.setName(getContent(filterMappingNav, Element.filter_name));
         while (filterMappingNav.next(Element.portlet_name))
         {
            filterMappingMD.addPortletName(filterMappingNav.getContent());
         }
         md.addFilterMapping(filterMappingMD);
      }

      //
      if (nav.find(Element.default_namespace))
      {
         md.setDefaultNamespace(new URI(nav.getContent()));
         nav.next();
      }

      //
      for (StaxNavigator<Element> eventDefinitionNav : nav.fork(Element.event_definition))
      {
         EventDefinitionMetaData eventDefinitionMD = new EventDefinitionMetaData();
         eventDefinitionMD.setId(eventDefinitionNav.getAttribute("id"));
         eventDefinitionMD.setDescription(readLocalizedString(eventDefinitionNav, Element.description));
         switch (eventDefinitionNav.next(NAME_OR_QNAME))
         {
            case name:
               eventDefinitionMD.setName(eventDefinitionNav.getContent());
               break;
            case qname:
               eventDefinitionMD.setQname(readQName(eventDefinitionNav));
               break;
         }
         while (eventDefinitionNav.next(Element.alias))
         {
            QName name = readQName(eventDefinitionNav);
            eventDefinitionMD.addAlias(name);
         }
         if (eventDefinitionNav.next(Element.value_type))
         {
            eventDefinitionMD.setValueType(eventDefinitionNav.getContent());
         }
         md.addEventDefinition(eventDefinitionMD);
      }

      //
      for (StaxNavigator<Element> publicRenderParameterNav : nav.fork(Element.public_render_parameter))
      {
         PublicRenderParameterMetaData publicRenderParameterMD = new PublicRenderParameterMetaData();
         publicRenderParameterMD.setId(publicRenderParameterNav.getAttribute("id"));
         publicRenderParameterMD.setDescription(readLocalizedString(publicRenderParameterNav, Element.description));
         publicRenderParameterMD.setIdentifier(getContent(publicRenderParameterNav, Element.identifier));
         switch (publicRenderParameterNav.next(NAME_OR_QNAME))
         {
            case name:
               publicRenderParameterMD.setName(publicRenderParameterNav.getContent());
               break;
            case qname:
               publicRenderParameterMD.setQname(readQName(publicRenderParameterNav));
               break;
         }
         while (publicRenderParameterNav.next(Element.alias))
         {
            QName name = readQName(publicRenderParameterNav);
            publicRenderParameterMD.addAlias(name);
         }
         md.addPublicRenderParameter(publicRenderParameterMD);
      }

      //
      for (StaxNavigator<Element> listenerNav : nav.fork(Element.listener))
      {
         ListenerMetaData listenerMD = new ListenerMetaData();
         listenerMD.setId(listenerNav.getAttribute("id"));
         listenerMD.setDescription(readLocalizedString(listenerNav, Element.description));
         listenerMD.setDisplayName(readLocalizedString(listenerNav, Element.display_name));
         listenerMD.setListenerClass(getContent(listenerNav, Element.listener_class));
         md.addListener(listenerMD);
      }

      //
      for (StaxNavigator<Element> containerRuntimeNav : nav.fork(Element.container_runtime_option))
      {
         ContainerRuntimeMetaData containerRuntimeOptionMD = new ContainerRuntimeMetaData();
         containerRuntimeOptionMD.setName(getContent(containerRuntimeNav, Element.name));
         while (containerRuntimeNav.next(Element.value))
         {
            containerRuntimeOptionMD.addValue(containerRuntimeNav.getContent());
         }
         md.addContainerRuntime(containerRuntimeOptionMD);
      }

      //
      return md;
   }
View Full Code Here

TOP

Related Classes of org.gatein.pc.portlet.impl.metadata.PortletApplication20MetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.