Revision 45633 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractFunction.java

View differences:

AbstractFunction.java
14 14
import java.util.List;
15 15
import java.util.Locale;
16 16
import java.util.Objects;
17
import java.util.logging.Level;
18
import java.util.logging.Logger;
19
import java.util.regex.Matcher;
20
import java.util.regex.Pattern;
17 21
import javax.json.JsonArray;
18 22
import javax.json.JsonObject;
19 23
import javax.json.JsonStructure;
24
import org.apache.commons.io.FilenameUtils;
20 25
import org.apache.commons.io.IOUtils;
21 26
import org.apache.commons.lang3.BooleanUtils;
22 27
import org.apache.commons.lang3.Range;
......
638 643
                return;
639 644
            }
640 645
        }
641
        InputStream is = null;
646
//        InputStream is = null;
642 647
        JSONObject json;
643 648
        try {
644
            is = url.openStream();
645
            List<String> lines = IOUtils.readLines(is);
646
            json = new JSONObject(StringUtils.join(lines,  "\n"));
649
//            is = url.openStream();
650
//            List<String> lines = IOUtils.readLines(is);
651
//            json = new JSONObject(StringUtils.join(lines,  "\n"));
652
            json = new JSONObject(IOUtils.toString(url));
647 653
        } catch (Exception ex) {
648 654
            return;
649
        } finally {
650
            IOUtils.closeQuietly(is);
655
//        } finally {
656
//            IOUtils.closeQuietly(is);
651 657
        }
652 658
        
653 659
        if( json.has("group") ) {
......
669 675
            } else {
670 676
                this.description = Objects.toString(x, null);
671 677
            }
678
            this.description = process_includes(url, this.description);
672 679
            this.description = StringUtils.replace(
673 680
                    this.description, 
674 681
                    "@@@", 
......
699 706
            }
700 707
        }
701 708
    }
709
    
710
    private String process_includes(URL pathname, String text) {
711
        Pattern p1 = Pattern.compile("[<][%]include (?<fname>[a-zA-Z0-9_$.]+)[%][>]", Pattern.DOTALL);
712
        while(true) {
713
            Matcher m = p1.matcher(text);
714
            if( m==null || !m.find()) {
715
                return text;
716
            }
717
            String path = FilenameUtils.getPathNoEndSeparator(pathname.toString());
718
            String fname = m.group("fname");
719
            URL url;
720
            String replacement;
721
            try {
722
                url = new URL(path+"/"+fname);
723
                replacement = IOUtils.toString(url);
724
//                text = m.replaceAll(replacement);
725
                StringBuilder builder = new StringBuilder(text.length()+replacement.length());
726
                builder.append(text.substring(0, m.start()));
727
                builder.append(replacement);
728
                builder.append(text.substring(m.end()));
729
                text = builder.toString();
730
            } catch (Exception ex) {
731
                return text;
732
            }
733
        }
734
    }
735
    
702 736
    protected static final int TYPE_INT =     0b00000001;
703 737
    protected static final int TYPE_LONG =    0b00000010;
704 738
    protected static final int TYPE_FLOAT =   0b00000100;

Also available in: Unified diff