com.dp2345.service.impl.LogConfigServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.dp2345.service.impl.LogConfigServiceImpl.java

Source

/*
 * Copyright 2013-2015 cetvision.com. All rights reserved.
 * Support: http://www.cetvision.com
 * License: http://www.cetvision.com/license
 */
package com.dp2345.service.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

import com.dp2345.CommonAttributes;
import com.dp2345.LogConfig;
import com.dp2345.service.LogConfigService;

/**
 * Service - ?
 * 
 * @author CETVISION CORP
 * @version 2.0.3
 */
@Service("logConfigServiceImpl")
public class LogConfigServiceImpl implements LogConfigService {

    @SuppressWarnings("unchecked")
    @Cacheable("logConfig")
    public List<LogConfig> getAll() {
        try {
            File dp2345XmlFile = new ClassPathResource(CommonAttributes.DP2345_XML_PATH).getFile();
            Document document = new SAXReader().read(dp2345XmlFile);
            List<org.dom4j.Element> elements = document.selectNodes("/dp2345/logConfig");
            List<LogConfig> logConfigs = new ArrayList<LogConfig>();
            for (org.dom4j.Element element : elements) {
                String operation = element.attributeValue("operation");
                String urlPattern = element.attributeValue("urlPattern");
                LogConfig logConfig = new LogConfig();
                logConfig.setOperation(operation);
                logConfig.setUrlPattern(urlPattern);
                logConfigs.add(logConfig);
            }
            return logConfigs;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}