Package org.rometools.feed.module.cc

Examples of org.rometools.feed.module.cc.CreativeCommonsImpl


     */
    public ModuleParserRSS1() {
    }

    public Module parse(Element element) {
  CreativeCommonsImpl module = new CreativeCommonsImpl();
  {
      // Parsing Channel level.
      Element root =element;
      while(root.getParentElement() != null )
    root = root.getParentElement();
      List licenseList = root.getChildren( "License", NS );
      ArrayList licenses = new ArrayList();
      Iterator it = licenseList.iterator();
      while( it.hasNext() ){
    Element licenseTag = (Element) it.next();
    String licenseURI = licenseTag.getAttributeValue("about", RDF);
    if( licenseURI == null )
        continue;
    License license = License.findByValue( licenseURI );
    {
        ArrayList permitsValues = new ArrayList();
        ArrayList requiresValues = new ArrayList();
        List permitsTags = licenseTag.getChildren("permits", NS );
        Iterator sit = permitsTags.iterator();
        while(sit.hasNext() ){
      Element permitTag = (Element) sit.next();
      permitsValues.add( License.Behaviour.findByValue( permitTag.getAttributeValue( "resource", RDF) ));     
        }
        List requiresTags = licenseTag.getChildren( "requires", NS);
        sit = requiresTags.iterator();
        while(sit.hasNext()){
      Element requireTag = (Element) sit.next();
      requiresValues.add( License.Behaviour.findByValue(requireTag.getAttributeValue("resource", RDF)));
        }
        license = new License( licenseURI,
          (License.Behaviour[]) requiresValues.toArray( new License.Behaviour[requiresValues.size()]),
          (License.Behaviour[]) permitsValues.toArray( new License.Behaviour[permitsValues.size()]) );
       
    }
   
    licenses.add( license );
      }
      module.setAllLicenses( (License[]) licenses.toArray( new License[0] ) );
  }
  ArrayList licenses = new ArrayList();
  List licenseTags = element.getChildren( "license", NS );
  Iterator lit = licenseTags.iterator();
  while( lit.hasNext() ){
      Element licenseTag = (Element) lit.next();
      licenses.add( License.findByValue( licenseTag.getAttributeValue( "resource", RDF)));
  }
 
  if( licenses.size() > 0 ){
      module.setLicenses( (License[]) licenses.toArray( new License[licenses.size()]));
  }
 
  if( module.getLicenses() != null || module.getAllLicenses() != null ){
      return module;
  } else {
      return null;
  }
    }
View Full Code Here


    /** Creates a new instance of ModuleParserRSS2 */
    public ModuleParserRSS2() {
    }

    public Module parse(Element element) {
  CreativeCommonsImpl module = new CreativeCommonsImpl();
  //Do channel global
  {
      Element root = element;
      while( !root.getName().equals("channel") && !root.getName().equals("feed") )
    root = root.getParentElement();
      ArrayList licenses = new ArrayList();
      List items = null;
      if( root.getName().equals("channel"))
    items = root.getChildren("item");
      else
    items = root.getChildren("entry");
     
      Iterator iit = items.iterator();
      while( iit.hasNext() ){
    Element item = (Element) iit.next();
    List licenseTags = item.getChildren( "license", NS );
    Iterator lit = licenseTags.iterator();
    while(lit.hasNext() ){
        Element licenseTag = (Element) lit.next();
        License license = License.findByValue( licenseTag.getTextTrim() );
        if( !licenses.contains( license ));
      licenses.add( license );
    }
      }
      if( licenses.size() > 0 ){
    module.setAllLicenses( (License[]) licenses.toArray( new License[0] ) );
      }
  }
  // do element local
  ArrayList licenses = new ArrayList();
  List licenseTags = element.getChildren( "license", NS );
  Iterator it = licenseTags.iterator();
  while( it.hasNext() ){
      Element licenseTag = (Element) it.next();
      licenses.add( License.findByValue(licenseTag.getTextTrim() ));
  }
  if( licenses.size() > 0 ){
      module.setLicenses( (License[]) licenses.toArray( new License[0]));
  }
 
  if( module.getLicenses() != null && module.getAllLicenses() != null ){
      return module;
  } else {
      return null;
  }
    }
View Full Code Here

TOP

Related Classes of org.rometools.feed.module.cc.CreativeCommonsImpl

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.