ingo@937: package de.intevation.flys.artifacts; ingo@937: felix@1969: import java.util.Collection; ingo@937: import java.util.List; ingo@937: ingo@937: import org.apache.log4j.Logger; ingo@937: ingo@937: import org.w3c.dom.Document; ingo@937: import org.w3c.dom.Element; ingo@937: ingo@937: import de.intevation.artifacts.ArtifactNamespaceContext; ingo@937: import de.intevation.artifacts.CallContext; ingo@937: felix@1969: import de.intevation.artifactdatabase.data.StateData; ingo@937: import de.intevation.artifactdatabase.ProtocolUtils; ingo@937: import de.intevation.artifactdatabase.state.Facet; ingo@937: import de.intevation.artifactdatabase.state.Output; ingo@937: import de.intevation.artifactdatabase.state.State; ingo@937: ingo@937: import de.intevation.artifacts.common.utils.XMLUtils; ingo@937: import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; ingo@937: felix@1969: /** felix@1969: * A basic FLYSArtifact. felix@1969: */ ingo@937: public abstract class StaticFLYSArtifact extends FLYSArtifact { ingo@937: felix@3050: /** Private logger. */ ingo@937: private static final Logger logger = ingo@937: Logger.getLogger(StaticFLYSArtifact.class); ingo@937: felix@2740: /** Path to 'ids' (data) in doc that comes from datacage. */ felix@2740: public static final String XPATH_IDS = "/art:action/art:ids/@value"; ingo@937: felix@1969: /** felix@1969: * Create description document which includes outputmodes. felix@1969: * @param data ignored. felix@1969: */ ingo@937: @Override ingo@937: public Document describe(Document data, CallContext cc) { ingo@937: logger.debug("Describe artifact: " + identifier()); ingo@937: ingo@937: Document desc = XMLUtils.newDocument(); ingo@937: ingo@937: ElementCreator creator = new ElementCreator( ingo@937: desc, ingo@937: ArtifactNamespaceContext.NAMESPACE_URI, ingo@937: ArtifactNamespaceContext.NAMESPACE_PREFIX); ingo@937: ingo@937: Element root = ProtocolUtils.createRootNode(creator); ingo@937: desc.appendChild(root); ingo@937: ingo@937: ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); ingo@943: root.appendChild(createOutputModes(cc, desc, creator)); ingo@937: felix@1969: // Add the data to an anonymous state. felix@1969: Collection datas = this.data.values(); felix@1969: if (datas.size() > 0) { felix@1969: Element ui = creator.create("ui"); felix@1969: Element staticE = creator.create("static"); felix@1969: Element state = creator.create("state"); felix@1969: ui.appendChild(staticE); felix@1969: staticE.appendChild(state); felix@1969: root.appendChild(ui); felix@1969: felix@1969: for (StateData dataItem : datas) { felix@1969: Element itemelent = creator.create("data"); felix@1969: creator.addAttr(itemelent, "name", dataItem.getName(), true); felix@1969: creator.addAttr(itemelent, "type", dataItem.getType(), true); felix@1969: state.appendChild(itemelent); felix@1969: Element valuement = creator.create("item"); felix@1969: creator.addAttr(valuement, "label", dataItem.getDescription(), true); felix@1969: creator.addAttr(valuement, "value", dataItem.getValue().toString(), true); felix@1969: itemelent.appendChild(valuement); felix@1969: } felix@1969: } felix@1969: ingo@937: return desc; ingo@937: } ingo@937: ingo@937: felix@2741: /** felix@2741: * Return the value of id element in Datacage data document. felix@2741: * @param data Document as passed by datacage. felix@2741: * @return the id element value of data document. felix@2741: */ felix@2741: public static String getDatacageIDValue(Document data) { felix@2741: return XMLUtils.xpathString(data, XPATH_IDS, felix@2741: ArtifactNamespaceContext.INSTANCE); felix@2741: } felix@2741: felix@2741: ingo@943: protected Element createOutputModes( ingo@943: CallContext cc, ingo@943: Document doc, ingo@943: ElementCreator creator) ingo@943: { ingo@937: Element outs = ProtocolUtils.createArtNode( ingo@937: creator, "outputmodes", null, null); ingo@937: ingo@937: State state = getCurrentState(cc); ingo@937: List list = state.getOutputs(); ingo@937: ingo@937: if (list != null && list.size() > 0) { felix@1771: List fs = facets.get(state.getID()); felix@1771: if (fs != null && fs.size() > 0) { felix@1771: List generated = generateOutputs(list, fs); ingo@937: felix@1771: logger.debug("Found " + fs.size() + " current facets."); ingo@937: if (!generated.isEmpty()) { ingo@937: ProtocolUtils.appendOutputModes( ingo@943: doc, outs, generated); ingo@937: } ingo@937: } ingo@937: else { ingo@937: logger.debug("No facets found for the current state."); ingo@937: } ingo@937: } ingo@937: ingo@937: return outs; ingo@937: } ingo@937: } ingo@937: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :