Package org.apache.commons.digester

Examples of org.apache.commons.digester.Digester


   * @throws ParseException
   */
  private static Channel fetchChannelViaHTTP(String url)
    throws HttpException, IOException, SAXException
  {
    Digester parser = new XMLDigester();
    GetMethod get = new GetMethod(url);
    //get.setRequestHeader("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; zh-cn) Opera 8.52");
        try {
          http_client.executeMethod(get);
          if(get.getStatusCode()==HttpServletResponse.SC_OK){
            Charset cs = null;
            Header header_cs = getResponseHeader(get,"Content-Type");
            if(header_cs==null){
              cs = Charset.forName(get.getResponseCharSet());
            }
            else{
              String content_type = header_cs.getValue().toLowerCase();
              try {
            Object[] values = content_type_parser.parse(content_type);
            cs = Charset.forName((String)values[1]);
          } catch (ParseException e) {
            URL o_url = new URL(url);
            String host = o_url.getHost();
            Iterator hosts = charsets.keySet().iterator();
            while(hosts.hasNext()){
              String t_host = (String)hosts.next();
              if(host.toLowerCase().endsWith(t_host)){
                cs = Charset.forName((String)charsets.get(t_host));
                break;
              }
            }
            if(cs==null)
              cs = default_charset;
           
          }
            }           
           
            BufferedReader rd = new BufferedReader(new InputStreamReader(
            get.getResponseBodyAsStream(), cs));
           
            char[] cbuf = new char[1];
            int read_idx = 1;
            do{
              rd.mark(read_idx++);
              if(rd.read(cbuf)==-1)
                break;
              if(cbuf[0]!='<')
                continue;
              rd.reset();
              break;
            }while(true);
            return (Channel)parser.parse(rd);
          }
          else{
            log.error("Fetch RSS from " + url + " failed, code="+get.getStatusCode());
          }
        }finally{
View Full Code Here


     * @see net.sf.jportlet.portlet.descriptor.ApplicationDescriptorLoader#load(java.io.InputStream)
     */
    public ApplicationDescriptor load( InputStream in )
        throws PortletException
    {
        Digester digester = new Digester(  );

        /* portlet-app */
        digester.addObjectCreate( "portlet-app", ApplicationDescriptor.class );
        digester.addBeanPropertySetter( "portlet-app/portlet-app-name", "name" );

        /* portlet-app/context-param */
        digester.addCallMethod( "portlet-app/context-param", "addContextParameter", 2 );
        digester.addCallParam( "portlet-app/context-param/param-name", 0 );
        digester.addCallParam( "portlet-app/context-param/param-value", 1 );

        /* portlet-app/portlet */
        digester.addObjectCreate( "portlet-app/portlet", PortletDescriptor.class );
        digester.addBeanPropertySetter( "portlet-app/portlet/portlet-name", "name" );
        digester.addBeanPropertySetter( "portlet-app/portlet/portlet-class", "portletClass" );
        digester.addBeanPropertySetter( "portlet-app/portlet/default-locale", "defaultLocale" );
        digester.addBeanPropertySetter( "portlet-app/portlet/action-listener", "actionListenerClass" );
        digester.addBeanPropertySetter( "portlet-app/portlet/message-listener", "messageListenerClass" );

        /* portlet-app/portlet/cache */
        digester.addObjectCreate( "portlet-app/portlet/cache", CacheDescriptor.class );
        digester.addSetProperties( "portlet-app/portlet/cache", "mode", "mode" );
        digester.addBeanPropertySetter( "portlet-app/portlet/cache/expires", "expires" );
        digester.addBeanPropertySetter( "portlet-app/portlet/cache/shared", "shared" );
        digester.addSetNext( "portlet-app/portlet/cache", "addCacheDescriptor" );

        /* portlet-app/portlet/language */
        digester.addObjectCreate( "portlet-app/portlet/language", LanguageDescriptor.class );
        digester.addSetProperties( "portlet-app/portlet/language", "locale", "locale" );
        digester.addBeanPropertySetter( "portlet-app/portlet/language/title", "title" );
        digester.addBeanPropertySetter( "portlet-app/portlet/language/title-short", "titleShort" );
        digester.addBeanPropertySetter( "portlet-app/portlet/language/description", "description" );
        digester.addBeanPropertySetter( "portlet-app/portlet/language/keywords", "keywords" );
        digester.addSetNext( "portlet-app/portlet/language", "addLanguageDescriptor" );

        /* portlet-app/portlet/supports/markup */
        digester.addObjectCreate( "portlet-app/portlet/supports/markup", MarkupDescriptor.class );
        digester.addSetProperties( "portlet-app/portlet/supports/markup", "name", "markup" );
        digester.addCallMethod( "portlet-app/portlet/supports/markup/view", "supportView" );
        digester.addCallMethod( "portlet-app/portlet/supports/markup/edit", "supportEdit" );
        digester.addCallMethod( "portlet-app/portlet/supports/markup/configure", "supportConfigure" );
        digester.addCallMethod( "portlet-app/portlet/supports/markup/help", "supportHelp" );
        digester.addSetNext( "portlet-app/portlet/supports/markup", "addMarkupDescriptor" );

        /* portlet-app/portlet/init-param */
        digester.addCallMethod( "portlet-app/portlet/init-param", "addInitParameter", 2 );
        digester.addCallParam( "portlet-app/portlet/init-param/param-name", 0 );
        digester.addCallParam( "portlet-app/portlet/init-param/param-value", 1 );

        /* portlet-app/portlet/security-contraint/auth-contraint */
        digester.addObjectCreate( "portlet-app/portlet/security-constraint/auth-constraint", AuthConstraintDescriptor.class );
        digester.addSetProperties( "portlet-app/portlet/security-constraint/auth-constraint", "mode", "mode" );
        digester.addBeanPropertySetter( "portlet-app/portlet/security-constraint/auth-constraint/allow-anonymous", "allowAnonymous" );
        digester.addCallMethod( "portlet-app/portlet/security-constraint/auth-constraint/role-name", "addRole", 1 );
        digester.addCallParam( "portlet-app/portlet/security-constraint/auth-constraint/role-name", 0 );
        digester.addSetNext( "portlet-app/portlet/security-constraint/auth-constraint", "addAuthConstraintDescriptor" );

        /* portlet-app/portlet/webflow/action */
        digester.addObjectCreate( "portlet-app/portlet/webflow/action", WebflowActionDescriptor.class );
        digester.addSetProperties( "portlet-app/portlet/webflow/action", "name", "name" );
       
        digester.addCallMethod( "portlet-app/portlet/webflow/action/return", "addReturnUri", 2 );
        digester.addCallParam( "portlet-app/portlet/webflow/action/return", 0, "code" );
        digester.addCallParam( "portlet-app/portlet/webflow/action/return", 1 );
       
        digester.addSetNext( "portlet-app/portlet/webflow/action", "addWebflowActionDescriptor" );

        digester.addSetNext( "portlet-app/portlet", "addPortletDescriptor" );

        try
        {
            digester.setValidating( true );
            return ( ApplicationDescriptor ) digester.parse( in );
        }
        catch ( Exception e )
        {
            __log.error( "Unexpected error", e );
           
View Full Code Here

     * @param input
     * @throws ServletException
     */
    private void parseMappings(InputStream input) throws ServletException {
      // Prepare a Digester to scan the web application deployment descriptor
      Digester digester = new Digester();
      digester.setNamespaceAware(true);
      digester.setValidating(false);

      // Configure the processing rules that we need
      digester.addCallMethod("web-app/servlet-mapping", "add", 2);
      digester.addCallParam("web-app/servlet-mapping/servlet-name", 0);
      digester.addCallParam("web-app/servlet-mapping/url-pattern", 1);

      digester.push(this);
      try {
        digester.parse(input);
      } catch (Exception e) {
        throw new ServletException("Could not parse /WEB-INF/web.xml", e);
      }
    }
View Full Code Here

        return tests;
    }

    static HttpTestContainer generateTests(String path) throws IOException {
        try {
            Digester digester = new Digester();
            digester.setValidating(false);

            digester.addObjectCreate(MATCH_TESTS, HttpTestContainer.class);
            digester.addSetProperties(MATCH_TESTS, "rootUrl", "rootUrl");
            digester.addSetProperties(MATCH_TESTS, "port", "port");
            digester.addSetProperties(MATCH_TESTS, "defaultUsername", "defaultUsername");
            digester.addSetProperties(MATCH_TESTS, "defaultPassword", "defaultPassword");

            digester.addObjectCreate(MATCH_TEST, HttpTestEntry.class);
            digester.addSetProperties(MATCH_TEST, "name", "name");
            digester.addSetProperties(MATCH_TEST, "authenticated", "authenticated");
            digester.addSetProperties(MATCH_TEST, "username", "username");
            digester.addSetProperties(MATCH_TEST, "password", "password");

            digester.addObjectCreate(MATCH_TEST_STEP, HttpTestEntryStep.class);
            digester.addSetProperties(MATCH_TEST_STEP, "name", "name");
            digester.addSetProperties(MATCH_TEST_STEP, "method", "method");
            digester.addSetProperties(MATCH_TEST_STEP, "url", "url");
            digester.addSetProperties(MATCH_TEST_STEP, "expectedCode", "expectedCode");
            digester.addSetProperties(MATCH_TEST_STEP, "redirectUrl", "redirectUrl");

            digester.addObjectCreate(MATCH_PARAMETER, HttpTestEntryStep.Parameter.class);
            digester.addSetProperties(MATCH_PARAMETER, "key", "key");
            digester.addSetProperties(MATCH_PARAMETER, "value", "value");
            digester.addSetNext(MATCH_PARAMETER, "addParameter");

            digester.addObjectCreate(MATCH_MESSAGE, HttpTestEntryStep.Value.class);
            digester.addSetProperties(MATCH_MESSAGE, "value", "value");
            digester.addSetNext(MATCH_MESSAGE, "addMessage");

            digester.addObjectCreate(MATCH_ERROR, HttpTestEntryStep.Value.class);
            digester.addSetProperties(MATCH_ERROR, "value", "value");
            digester.addSetNext(MATCH_ERROR, "addError");

            digester.addSetNext(MATCH_TEST_STEP, "addStep");
            digester.addSetNext(MATCH_TEST, "addEntry");

            InputStream input = new FileInputStream(path);
            return (HttpTestContainer) digester.parse(input);
        } catch (SAXException e) {
            throw new IOException(e.getMessage());
        }
    }
View Full Code Here

      } catch (Exception e) {
        log.info("Parser doesn't support XML Schema validation, using DTD...");
        log.debug(e);
      }
    }
    final Digester digester = new Digester(parser);
    digester.setLogger(getLog());
    digester.setClassLoader(context.getClassLoader());
    digester.setErrorHandler(new DefaultHandler() {
      public void error(SAXParseException e) throws SAXException {
        throw e;
      }
      public void warning(SAXParseException e) throws SAXException {
        getLog().warn(e.getMessage());
      }
    });
    digester.setEntityResolver(new EntityResolver() {
      public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
        InputSource result = null;
        if (schemaResolver != null) {
          result = schemaResolver.resolveEntity(publicId, systemId);
        }
        if (result == null && dtdResolver != null) {
          result = dtdResolver.resolveEntity(publicId, systemId);
        }
        if (result != null) {
          return result;
        }
        return digester.resolveEntity(publicId, systemId);
      }
    });

    addBaseRuleInstances(digester);
    addRuleInstances(digester);
View Full Code Here

  protected Log getLog() {
    return log;
  }

  private RootConfigImpl parse(URL url) throws ConfigException {
    Digester digester = createDigester();   
    RootConfigImpl root = createRoot();
    digester.push(root);
    log.debug("Parsing: " + url);
    try {
      InputSource input = new InputSource(url.openStream());
      input.setSystemId(url.toString());
      digester.parse(input);
    } catch (Exception e) {
      throw new ConfigException("Error parsing " + url, e);
    }

    // Parse imported files
View Full Code Here

  {
  if( digester != null )
    return;

    // initialize the digester
  digester = new Digester();
  digester.setUseContextClassLoader(useContextClassLoader);

  //digester.setSchema( registeredUri[1] );
    // Register local schema and DTD
  for(int i=0;i<registeredUri.length; i+=2 )
View Full Code Here

  {
    if( this.digester != null )
      return;

    // initialize the digester
  Digester digester = new Digester();
  digester.setUseContextClassLoader(true);

  //digester.setSchema( registeredUri[1] );
  // Register local uri
  registerLocalUri( digester, registeredUri);

    // set validation
  log.info("Set rule validation to '" + validateParsing  + "'" );
  digester.setValidating(validateParsing);

  addDigesterRuleSet(digester);

  this.digester = digester;
  }
View Full Code Here

    public void setServletConfigFile(String pathname) {
        confirmSetup();

        // pull in the appropriate parts of the
        // web.xml file -- first the init-parameters
        Digester digester = new Digester();
        digester.push(this.config);
        digester.setValidating(false);
        digester.addCallMethod("web-app/servlet/init-param", //$NON-NLS-1$
                "setInitParameter", 2); //$NON-NLS-1$
        digester.addCallParam("web-app/servlet/init-param/param-name", 0); //$NON-NLS-1$
        digester.addCallParam("web-app/servlet/init-param/param-value", 1); //$NON-NLS-1$
        try {
            InputStream input = this.context.getResourceAsStream(pathname);
            if (input == null)
                throw new AssertionFailedError("Invalid pathname: " + pathname); //$NON-NLS-1$
            digester.parse(input);
            input.close();
        } catch (Exception e) {
            throw new AssertionFailedError(
                    "Received an exception while loading web.xml - " //$NON-NLS-1$
                            + e.getClass() + " : " + e.getMessage()); //$NON-NLS-1$
        }

        // now the context parameters..
        digester = new Digester();
        digester.setValidating(false);
        digester.push(this.context);
        digester.addCallMethod("web-app/context-param", "setInitParameter", 2); //$NON-NLS-1$ //$NON-NLS-2$
        digester.addCallParam("web-app/context-param/param-name", 0); //$NON-NLS-1$
        digester.addCallParam("web-app/context-param/param-value", 1); //$NON-NLS-1$
        try {
            InputStream input = this.context.getResourceAsStream(pathname);
            if (input == null)
                throw new AssertionFailedError("Invalid pathname: " + pathname); //$NON-NLS-1$
            digester.parse(input);
            input.close();
        } catch (Exception e) {
            throw new AssertionFailedError(
                    "Received an exception while loading web.xml - " //$NON-NLS-1$
                            + e.getClass() + " : " + e.getMessage()); //$NON-NLS-1$
View Full Code Here

      * Constructor.
      * Creates a digester parser and initializes syntax rules.
      */
  public XmlParser()
  {
  digester = new Digester();
  digester.setValidating(validating);
  digester.setNamespaceAware(true);
  digester.setUseContextClassLoader(true);
  // Register our local copy of the DTDs that we can find
  for (int i = 0; i < registrations.length; i += 2) {
View Full Code Here

TOP

Related Classes of org.apache.commons.digester.Digester

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.