Path: blob/master/sourcetools/com.ibm.uma/com/ibm/uma/freemarker/ArtifactDataElement.java
6004 views
/*******************************************************************************1* Copyright (c) 2001, 2017 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package com.ibm.uma.freemarker;2223import com.ibm.uma.UMAException;24import com.ibm.uma.om.Artifact;2526import freemarker.ext.beans.BeansWrapper;27import freemarker.ext.beans.BooleanModel;28import freemarker.template.SimpleScalar;29import freemarker.template.TemplateCollectionModel;30import freemarker.template.TemplateHashModel;31import freemarker.template.TemplateModel;32import freemarker.template.TemplateModelException;33import freemarker.template.TemplateModelIterator;3435public class ArtifactDataElement implements TemplateHashModel {3637Artifact artifact;38String key;39String [] data;4041class ADEIterator implements TemplateModelIterator, TemplateCollectionModel {42String[] data;43int pos = 0;4445public ADEIterator(String [] data) {46this.data = data;47}48public boolean hasNext() throws TemplateModelException {49return data != null && pos < data.length;50}51public TemplateModel next() throws TemplateModelException {52return new SimpleScalar(data[pos++]);53}5455public TemplateModelIterator iterator() throws TemplateModelException {56return this;57}58}5960public ArtifactDataElement(String key, Artifact artifact) throws UMAException {61this.artifact = artifact;62this.key = key;63this.data = artifact.getData(key);64}6566public TemplateModel get(String arg0) throws TemplateModelException {67if (arg0.equals("list")) {68return new ADEIterator(data);69}70if (arg0.equals("present")) {71return new BooleanModel(data!=null, new BeansWrapper());72}73if (arg0.equals("data")) {74String string = "";75for (String tmp : data) {76string += tmp;77}78return new SimpleScalar(string);79}80if (arg0.equals("underscored_data")) {81String string = "";82for (String tmp : data) {83string += "_" + tmp.toUpperCase();84}85return new SimpleScalar(string);86}87return null;88}8990public boolean isEmpty() throws TemplateModelException {91return false;92}9394}959697