コード例 #1
0
 private static String getWindowStateOrDefault(UpdateNavigationalStateResponse navResponse) {
   org.gatein.pc.api.WindowState state = navResponse.getWindowState();
   if (state == null) {
     state = org.gatein.pc.api.WindowState.NORMAL;
   }
   return state.toString();
 }
コード例 #2
0
ファイル: Page.java プロジェクト: mwringe/gatein-pc
  Page(PortletInvoker invoker, String s) throws ServletException {
    LinkedHashMap<String, Window> windows = new LinkedHashMap<String, Window>();
    int count = 0;
    Map<String, String[]> parameters;

    //
    if (s == null || s.length() == 0 || (s.length() == 1 && s.charAt(0) == '/')) {
      parameters = null;
    } else {
      Segment segments = (Segment) Chunk.parse(s);

      // Skip context path
      segments = (Segment) segments.next;

      // Servlet parameter
      parameters = segments.parameters;

      //
      for (Segment segment : (Segment) segments.next) {
        Portlet found = null;
        if (invoker != null) {
          try {
            for (Portlet portlet : invoker.getPortlets()) {
              if (portlet.getInfo().getName().equals(segment.value)) {
                found = portlet;
                break;
              }
            }
          } catch (PortletInvokerException e) {
            // ?
          }
        }

        //
        LinkedHashMap<String, String[]> windowParameters;
        Mode windowMode;
        WindowState windowState;
        if (segment.parameters != null) {
          windowParameters = new LinkedHashMap<String, String[]>(segment.parameters);
          String[] modeParameter = windowParameters.remove("javax.portlet.portlet_mode");
          String[] windowStateParameter = windowParameters.remove("javax.portlet.window_state");
          windowMode = modeParameter != null ? Mode.create(modeParameter[0]) : null;
          windowState =
              windowStateParameter != null ? WindowState.create(windowStateParameter[0]) : null;
        } else {
          windowParameters = null;
          windowMode = null;
          windowState = null;
        }

        //
        Window context =
            new Window(
                "" + count++, found, segment.value, windowMode, windowState, windowParameters);

        //
        windows.put(context.id, context);
      }
    }

    //
    this.windows = windows;
    this.parameters = parameters;
  }
コード例 #3
0
  public PortletApplication20MetaData build(InputStream is) throws DeploymentException {

    // We will need to read the input stream twice
    byte[] bytes = null;
    if (schemaValidation) {
      try {
        bytes = IOTools.getBytes(is);
        is = new ByteArrayInputStream(bytes);
      } catch (IOException e) {
        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;
  }