/**
 * Copyright 2013 52°North Initiative for Geospatial Open Source Software GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.n52.geolabel.server.mapping.description;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.map.annotate.JacksonInject;
import org.n52.geolabel.commons.Label;
import org.n52.geolabel.commons.ProducerCommentsFacet;
import org.n52.geolabel.server.config.TransformationDescriptionResources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;

/**
 * Checks availability of producer comments information
 *
 */
public class ProducerCommentsFacetDescription extends FacetTransformationDescription<ProducerCommentsFacet> {

    private static Logger log = LoggerFactory.getLogger(ProducerCommentsFacetDescription.class);

	private String producerCommentsPath;

	private XPathExpression producerCommentsExpression;

    @JsonCreator
    public ProducerCommentsFacetDescription(@JacksonInject
    TransformationDescriptionResources resources) {
        super(resources);
        log.debug("NEW {}", this);
    }

    @Override
	public void initXPaths(XPath xPath) throws XPathExpressionException {
        if (this.producerCommentsPath != null)
            this.producerCommentsExpression = xPath.compile(this.producerCommentsPath);
		super.initXPaths(xPath);
	}

	@Override
	public ProducerCommentsFacet updateFacet(final ProducerCommentsFacet facet, Document metadataXml)
			throws XPathExpressionException {
        visitExpressionResultStrings(this.producerCommentsExpression, metadataXml, new ExpressionResultFunction() {
			@Override
			public boolean eval(String value) {
				facet.addProducerComment(value);
				return true;
			}
		});

        return super.updateFacet(facet, metadataXml);
	}

	@Override
	public ProducerCommentsFacet getAffectedFacet(Label label) {
		return label.getProducerCommentsFacet();
	}

}
@@ -637,16 +637,17 @@
 se.%0A */%0A
+%0A
 package 
@@ -696,38 +696,8 @@
 n;%0A%0A
-import javax.xml.xpath.XPath;%0A
 impo
@@ -1419,17 +1419,20 @@
 lass);%0A%0A
-%09
+    
 private 
@@ -1461,17 +1461,20 @@
 sPath;%0A%0A
-%09
+    
 private 
@@ -1717,16 +1717,19 @@
   %7D%0A%0A   
+ //
  @Overri
@@ -1727,25 +1727,31 @@
 / @Override%0A
-%09
+    // 
 public void 
@@ -1812,19 +1812,21 @@
 n %7B%0A    
-   
+// //
  if (thi
@@ -1861,23 +1861,21 @@
 ll)%0A    
-  
-     
+// //
  this.pr
@@ -1943,18 +1943,23 @@
 sPath);%0A
-%09%09
+    // 
 super.in
@@ -1975,21 +1975,30 @@
 xPath);%0A
-%09%7D%0A%0A%09
+    // %7D%0A%0A    
 @Overrid
@@ -1991,33 +1991,36 @@
 %0A%0A    @Override%0A
-%09
+    
 public ProducerC
@@ -2100,20 +2100,17 @@
 dataXml)
-%0A%09%09%09
+ 
 throws X
@@ -2147,234 +2147,79 @@
     
-visitExpressionResultStrings(this.producerCommentsExpression, metadataXml, new ExpressionResultFunction() %7B%0A%09%09%09@Override%0A%09%09%09public boolean eval(String value) %7B%0A%09%09%09%09fac
+ProducerCommentsFacet f = super.updateDrilldownUrlWithM
 et
-.
 ad
-dProducerComment(value);%0A%09%09%09%09return true;%0A%09%09%09%7D%0A%09%09%7D
+ata(facet
 );%0A
-%0A
     
@@ -2248,20 +2248,16 @@
 eFacet(f
-acet
 , metada
@@ -2268,13 +2268,19 @@
 l);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 @Ove
@@ -2285,17 +2285,20 @@
 verride%0A
-%09
+    
 public P
@@ -2354,10 +2354,16 @@
 ) %7B%0A
-%09%09
+        
 retu
@@ -2403,9 +2403,12 @@
 ();%0A
-%09
+    
 %7D%0A%0A%7D

fix drilldown URL for producer comments facet