Search in sources :

Example 66 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class ListUtil method listToArrayTrim.

/**
 * casts a list to Array object, remove all empty items at start and end of the list
 * @param list list to cast
 * @param delimiter delimter of the list
 * @return Array Object
 */
public static Array listToArrayTrim(String list, String delimiter) {
    if (delimiter.length() == 1)
        return listToArrayTrim(list, delimiter.charAt(0));
    if (list.length() == 0)
        return new ArrayImpl();
    char[] del = delimiter.toCharArray();
    char c;
    // remove at start
    outer: while (list.length() > 0) {
        c = list.charAt(0);
        for (int i = 0; i < del.length; i++) {
            if (c == del[i]) {
                list = list.substring(1);
                continue outer;
            }
        }
        break;
    }
    int len;
    outer: while (list.length() > 0) {
        c = list.charAt(list.length() - 1);
        for (int i = 0; i < del.length; i++) {
            if (c == del[i]) {
                len = list.length();
                list = list.substring(0, len - 1 < 0 ? 0 : len - 1);
                continue outer;
            }
        }
        break;
    }
    return listToArray(list, delimiter);
}
Also used : ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 67 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class FeedHandler method startElement.

@Override
public void startElement(String uri, String name, String qName, Attributes atts) {
    deep++;
    if ("entry".equals(name))
        inEntry = true;
    else if ("author".equals(name))
        inAuthor = true;
    if (qName.startsWith("dc:")) {
        name = "dc_" + name;
        hasDC = true;
    }
    inside = KeyImpl.getInstance(name);
    if (StringUtil.isEmpty(path))
        path = name;
    else {
        path += "." + name;
    }
    if (decl == null) {
        String decName = name;
        String version = atts.getValue("version");
        if ("feed".equals(decName)) {
            if (!StringUtil.isEmpty(version))
                decName = "atom_" + version;
            else
                decName = "atom_1.0";
        } else {
            if (!StringUtil.isEmpty(version))
                decName += "_" + version;
        }
        decl = FeedDeclaration.getInstance(decName);
        root.put("version", decName);
        isAtom = decl.getType().equals("atom");
    }
    FeedStruct sct = new FeedStruct(path, inside, uri);
    // attributes
    Map<String, String> attrs = getAttributes(atts, path);
    if (attrs != null) {
        Entry<String, String> entry;
        Iterator<Entry<String, String>> it = attrs.entrySet().iterator();
        sct.setHasAttribute(true);
        while (it.hasNext()) {
            entry = it.next();
            sct.setEL(entry.getKey(), entry.getValue());
        }
    }
    // assign
    if (!isAtom || deep < 4) {
        Object obj = data.get(inside, null);
        if (obj instanceof Array) {
            ((Array) obj).appendEL(sct);
        } else if (obj instanceof FeedStruct) {
            Array arr = new ArrayImpl();
            arr.appendEL(obj);
            arr.appendEL(sct);
            data.setEL(inside, arr);
        } else if (obj instanceof String) {
        // wenn wert schon existiert wird castableArray in setContent erstellt
        } else {
            El el = decl.getDeclaration().get(path);
            if (el != null && (el.getQuantity() == El.QUANTITY_0_N || el.getQuantity() == El.QUANTITY_1_N)) {
                Array arr = new ArrayImpl();
                arr.appendEL(sct);
                data.setEL(inside, arr);
            } else
                data.setEL(inside, sct);
        }
    }
    parents.add(data);
    data = sct;
// <enclosure url="http://www.scripting.com/mp3s/weatherReportDicksPicsVol7.mp3" length="6182912" type="audio/mpeg"/>
}
Also used : Array(lucee.runtime.type.Array) CastableArray(lucee.runtime.type.CastableArray) Entry(java.util.Map.Entry) ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 68 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class XMLValidator method validate.

public Struct validate(InputSource xml) throws XMLException {
    warnings = new ArrayImpl();
    errors = new ArrayImpl();
    fatals = new ArrayImpl();
    try {
        XMLReader parser = XMLUtil.createXMLReader();
        parser.setContentHandler(this);
        parser.setErrorHandler(this);
        parser.setEntityResolver(this);
        parser.setFeature("http://xml.org/sax/features/validation", true);
        parser.setFeature("http://apache.org/xml/features/validation/schema", true);
        parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
        // if(!validateNamespace)
        if (!StringUtil.isEmpty(strSchema))
            parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", strSchema);
        parser.parse(xml);
    } catch (SAXException e) {
    } catch (IOException e) {
        throw new XMLException(e.getMessage());
    }
    // result
    Struct result = new StructImpl();
    result.setEL("warnings", warnings);
    result.setEL("errors", errors);
    result.setEL("fatalerrors", fatals);
    result.setEL("status", Caster.toBoolean(!hasErrors));
    release();
    return result;
}
Also used : XMLException(lucee.runtime.exp.XMLException) StructImpl(lucee.runtime.type.StructImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException) Struct(lucee.runtime.type.Struct)

Example 69 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class WeakConstructorStorage method store.

/**
 * stores the constructors for a Class
 * @param clazz
 * @return stored structure
 */
private Array store(Class clazz) {
    Constructor[] conArr = clazz.getConstructors();
    Array args = new ArrayImpl();
    for (int i = 0; i < conArr.length; i++) {
        storeArgs(conArr[i], args);
    }
    map.put(clazz, args);
    return args;
}
Also used : Array(lucee.runtime.type.Array) Constructor(java.lang.reflect.Constructor) ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 70 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class Perl5Util method find.

/**
 * find occurence of a pattern in a string (same like indexOf), but dont return first ocurence , it return
 * struct with all information
 * @param strPattern
 * @param strInput
 * @param offset
 * @param caseSensitive
 * @return
 * @throws MalformedPatternException
 */
public static Struct find(String strPattern, String strInput, int offset, boolean caseSensitive) throws MalformedPatternException {
    Perl5Matcher matcher = new Perl5Matcher();
    PatternMatcherInput input = new PatternMatcherInput(strInput);
    int compileOptions = caseSensitive ? 0 : Perl5Compiler.CASE_INSENSITIVE_MASK;
    compileOptions += Perl5Compiler.SINGLELINE_MASK;
    if (offset < 1)
        offset = 1;
    Pattern pattern = getPattern(strPattern, compileOptions);
    if (offset <= strInput.length())
        input.setCurrentOffset(offset - 1);
    if (offset <= strInput.length() && matcher.contains(input, pattern)) {
        MatchResult result = matcher.getMatch();
        int groupCount = result.groups();
        Array posArray = new ArrayImpl();
        Array lenArray = new ArrayImpl();
        for (int i = 0; i < groupCount; i++) {
            int off = result.beginOffset(i);
            posArray.appendEL(Integer.valueOf(off + 1));
            lenArray.appendEL(Integer.valueOf(result.endOffset(i) - off));
        }
        Struct struct = new StructImpl();
        struct.setEL("pos", posArray);
        struct.setEL("len", lenArray);
        return struct;
    }
    Array posArray = new ArrayImpl();
    Array lenArray = new ArrayImpl();
    posArray.appendEL(Constants.INTEGER_0);
    lenArray.appendEL(Constants.INTEGER_0);
    Struct struct = new StructImpl();
    struct.setEL("pos", posArray);
    struct.setEL("len", lenArray);
    return struct;
}
Also used : Array(lucee.runtime.type.Array) Pattern(org.apache.oro.text.regex.Pattern) StructImpl(lucee.runtime.type.StructImpl) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) ArrayImpl(lucee.runtime.type.ArrayImpl) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult) Struct(lucee.runtime.type.Struct)

Aggregations

ArrayImpl (lucee.runtime.type.ArrayImpl)100 Array (lucee.runtime.type.Array)79 Struct (lucee.runtime.type.Struct)33 StructImpl (lucee.runtime.type.StructImpl)24 PageException (lucee.runtime.exp.PageException)14 Entry (java.util.Map.Entry)13 Key (lucee.runtime.type.Collection.Key)12 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 ArrayList (java.util.ArrayList)6 ListIterator (java.util.ListIterator)6 FunctionException (lucee.runtime.exp.FunctionException)6 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)6 ApplicationException (lucee.runtime.exp.ApplicationException)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 Query (lucee.runtime.type.Query)5 QueryImpl (lucee.runtime.type.QueryImpl)5 ListAsArray (lucee.runtime.type.wrap.ListAsArray)5 NodeList (org.w3c.dom.NodeList)5