/** * Copyright 2011 the original author or authors. * * 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.bricket.web; import java.io.Serializable; import java.util.List; import brix.BrixNodeModel; import brix.jcr.api.JcrValue; import brix.jcr.wrapper.BrixNode; import brix.web.reference.Reference; /** * @author Ingo Renner * @author Henning Teek * */ public abstract class BricketTileConfig implements Serializable { public abstract void load(BrixNode node); public abstract void save(BrixNode node); protected final boolean load(BrixNode node, String path, boolean field) { if (node.hasProperty(path)) { return node.getProperty(path).getBoolean(); } return field; } protected final long load(BrixNode node, String path, long field) { if (node.hasProperty(path)) { return node.getProperty(path).getLong(); } return field; } protected final int load(BrixNode node, String path, int field) { if (node.hasProperty(path)) { return (int) node.getProperty(path).getLong(); } return field; } protected final String load(BrixNode node, String path, String field) { if (node.hasProperty(path)) { return node.getProperty(path).getString(); } return field; } protected final Reference load(BrixNode node, String path, Reference field) { if (node.hasNode(path)) { return Reference.load(node, path); } return field; } protected final void load(BrixNode node, String path, List<String> field) { if (node.hasProperty(path)) { field.clear(); for (JcrValue val : node.getProperty(path).getValues()) { field.add(val.getString()); } } } protected final BrixNodeModel load(BrixNode node, String path, String field, BrixNodeModel brixNodeModel) { if (node.hasProperty(path)) { return BricketApplication.get().getBrixLink(field); } return brixNodeModel; } protected final void save(BrixNode node, String path, boolean field) { if (node != null) { node.setProperty(path, field); } } protected final void save(BrixNode node, String path, long field) { if (node != null) { node.setProperty(path, field); } } protected final void save(BrixNode node, String path, int field) { if (node != null) { node.setProperty(path, field); } } protected final void save(BrixNode node, String path, String field) { if (node != null) { node.setProperty(path, field); } } protected final void save(BrixNode node, String path, Reference field) { if (node != null) { field.save(node, path); } } protected final void save(BrixNode node, String path, List<String> field) { if (node != null) { node.setProperty(path, field.toArray(new String[field.size()])); } } }