package com.celements.metatag;

import java.util.Map;

import javax.validation.constraints.NotNull;

import org.xwiki.component.annotation.Component;
import org.xwiki.component.annotation.Requirement;
import org.xwiki.script.service.ScriptService;

import com.celements.metatag.enums.ECharset;

@Component(MetaTagScriptService.COMPONENT_HINT)
public class MetaTagScriptService implements ScriptService {

  public static final String COMPONENT_HINT = "metatag";

  @Requirement
  MetaTagServiceRole metaTag;

  public @NotNull MetaTag getCharsetMetaTag(@NotNull String charsetStr) {
    ECharset charset = ECharset.getCharset(charsetStr);
    if (charset != null) {
      return new MetaTag(charset);
    }
    return new MetaTag(ECharset.ATTRIB_NAME, charsetStr, null);
  }

  public void addMetaTagToCollector(@NotNull String attributeName, @NotNull String attributeValue,
      @NotNull String content) {
    metaTag.addMetaTagToCollector(new MetaTag(attributeName, attributeValue, content));
  }

  public void addMetaTagToCollector(@NotNull Map<String, String> attributes,
      @NotNull String content) {
    metaTag.addMetaTagToCollector(new MetaTag(attributes, content));
  }

  public @NotNull String displayCollectedMetaTags() {
    return metaTag.displayCollectedMetaTags();
  }
}

@@ -48,16 +48,50 @@
 l.Map;%0A%0A
+import javax.annotation.Nullable;%0A
 import j
@@ -320,16 +320,55 @@
 Charset;
+%0Aimport com.google.common.base.Strings;
 %0A%0A@Compo
@@ -941,38 +941,39 @@
 eValue,%0A      @N
-otN
 ull
+able
  String content)
@@ -1051,16 +1051,45 @@
 teValue,
+ Strings.nullToEmpty(%0A       
  content
@@ -1082,32 +1082,33 @@
        content))
+)
 ;%0A  %7D%0A%0A  public 
@@ -1183,22 +1183,23 @@
       @N
-otN
 ull
+able
  String 
@@ -1267,16 +1267,36 @@
 ibutes, 
+Strings.nullToEmpty(
 content)
@@ -1296,16 +1296,17 @@
 ontent))
+)
 ;%0A  %7D%0A%0A 

allow content null in script service