Package org.staxnav

Examples of org.staxnav.StaxNavException


        return new StaxNavException(navigator.getLocation(), "Content for element '" + navigator.getLocalName()
                + "' is required.");
    }

    public static StaxNavException invalidParent(StaxNavigator navigator) {
        return new StaxNavException(navigator.getLocation(), "Invalid parent for element '" + navigator.getLocalName() + "'");
    }
View Full Code Here


    public static StaxNavException invalidParent(StaxNavigator navigator) {
        return new StaxNavException(navigator.getLocation(), "Invalid parent for element '" + navigator.getLocalName() + "'");
    }

    public static StaxNavException unexpectedEndOfFile(StaxNavigator navigator) {
        return new StaxNavException(navigator.getLocation(), "Unexpected end of file.");
    }
View Full Code Here

            if (input instanceof InputStream) {
                if (inputEncoding == null) {
                    try {
                        reader = factory.createXMLStreamReader((InputStream) input, inputEncoding);
                    } catch (XMLStreamException e) {
                        throw new StaxNavException(e);
                    }
                } else {
                    try {
                        reader = factory.createXMLStreamReader((InputStream) input);
                    } catch (XMLStreamException e) {
                        throw new StaxNavException(null, "Exception creating XMLStreamReader with inputStream: " + input, e);
                    }
                }
            } else if (input instanceof Reader) {
                try {
                    reader = factory.createXMLStreamReader((Reader) input);
                } catch (XMLStreamException e) {
                    throw new StaxNavException(null, "Exception creating XMLStreamReader with reader: " + input, e);
                }
            } else if (input instanceof Source) {
                try {
                    reader = factory.createXMLStreamReader((Source) input);
                } catch (XMLStreamException e) {
                    throw new StaxNavException(null, "Exception creating XMLStreamReader with Source: " + input, e);
                }
            } else {
                throw new IllegalStateException("Unknown input: " + input); // should never happen...
            }
        }
View Full Code Here

    }

    public static String getRequiredAttribute(StaxNavigator navigator, String attributeName) throws StaxNavException {
        String value = navigator.getAttribute(attributeName);
        if (value == null) {
            throw new StaxNavException(navigator.getLocation(), "Attribute '" + attributeName + "' is required for element '"
                    + navigator.getLocalName() + "'");
        }

        return value;
    }
View Full Code Here

        if (portalLayout == null) {
            portalLayout = PortalConfig.DEFAULT_LAYOUT;
        } else {
            int count = countPageBodyElements(portalLayout, 0);
            if (count < 1) {
                throw new StaxNavException("No page-body element found.");
            } else if (count > 1) {
                throw new StaxNavException("Multiple page-body elements found.");
            }
        }

        portalConfig.setPortalLayout(portalLayout);
View Full Code Here

         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);
      }
View Full Code Here

      {
         return nav.getContent();
      }
      else
      {
         throw new StaxNavException(nav.getLocation(), "Was expecting elemnt " + element + " to be present");
      }
   }
View Full Code Here

         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);
      }
View Full Code Here

      {
         return nav.getContent();
      }
      else
      {
         throw new StaxNavException(nav.getLocation(), "Was expecting elemnt " + element + " to be present");
      }
   }
View Full Code Here

        if (portalLayout == null) {
            portalLayout = PortalConfig.DEFAULT_LAYOUT;
        } else {
            int count = countPageBodyElements(portalLayout, 0);
            if (count < 1) {
                throw new StaxNavException("No page-body element found.");
            } else if (count > 1) {
                throw new StaxNavException("Multiple page-body elements found.");
            }
        }

        portalConfig.setPortalLayout(portalLayout);
View Full Code Here

TOP

Related Classes of org.staxnav.StaxNavException

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.