Package org.apache.lenya.xml

Examples of org.apache.lenya.xml.NamespaceHelper


        if (!element.getLocalName().equals("trigger")) {
            throw new IllegalArgumentException();
        }

        String triggerType = element.getAttribute(TRIGGER_TYPE);
        NamespaceHelper helper = SchedulerStore.getNamespaceHelper();

        // SimpleTrigger
        if (triggerType.equals(ONCE)) {
            Element[] parameterElements = helper.getChildren(element, "parameter");
            GregorianCalendar date = new GregorianCalendar();

            for (int i = 0; i < parameterElements.length; i++) {
                String name = parameterElements[i].getAttribute("name");
                String value = parameterElements[i].getAttribute("value");

                if (name.equals(YEAR)) {
                    date.set(Calendar.YEAR, Integer.parseInt(value));
                }

                if (name.equals(MONTH)) {
                    date.set(Calendar.MONTH, Integer.parseInt(value) - 1);
                }

                if (name.equals(DAY)) {
                    date.set(Calendar.DAY_OF_MONTH, Integer.parseInt(value));
                }

                if (name.equals(HOUR)) {
                    date.set(Calendar.HOUR_OF_DAY, Integer.parseInt(value));
                }

                if (name.equals(MINUTE)) {
                    date.set(Calendar.MINUTE, Integer.parseInt(value));
                }

                if (name.equals(HOUR)) {
                    date.set(Calendar.HOUR_OF_DAY, Integer.parseInt(value));
                }
            }

            return createSimpleTrigger(jobName, jobGroup, date.getTime());
        }

        // CronTrigger
        if (triggerType.equals(REPEATED)) {
            Element[] parameterElements = helper.getChildren(element, "parameter");
            String name = parameterElements[0].getAttribute("name");
            String value = parameterElements[0].getAttribute("value");
            String cron_expression;

            if (name.equals(CRON_EXPRESSION)) {
View Full Code Here


     * @param helper The namespace helper of the document.
     * @return An XML element.
     */
    public Element save(NamespaceHelper helper) {
        org.w3c.dom.Document document = helper.getDocument();
        NamespaceHelper taskHelper = new NamespaceHelper(Task.NAMESPACE,
                Task.DEFAULT_PREFIX,
                document);
        Element element = taskHelper.createElement(ELEMENT_TASK);

        List keys = new ArrayList(getParameters().keySet());
        Collections.sort(keys);

        for (Iterator i = keys.iterator(); i.hasNext();) {
            String key = (String) i.next();
            Element parameterElement = taskHelper.createElement(ELEMENT_PARAMETER);
            parameterElement.setAttribute(ATTRIBUTE_NAME, key);
            parameterElement.setAttribute(ATTRIBUTE_VALUE, (String) getParameters().get(key));
            element.appendChild(parameterElement);
        }

View Full Code Here

     * @param parent The parent of the task wrapper element.
     * @param helper The namespace helper of the document.
     */
    public void restore(NamespaceHelper helper, Element parent) {
        org.w3c.dom.Document document = helper.getDocument();
        NamespaceHelper taskHelper = new NamespaceHelper(Task.NAMESPACE,
                Task.DEFAULT_PREFIX,
                document);
        Element taskElement = taskHelper.getFirstChild(parent, ELEMENT_TASK);
        Element[] parameterElements = taskHelper.getChildren(taskElement, ELEMENT_PARAMETER);
        for (int i = 0; i < parameterElements.length; i++) {
            String key = parameterElements[i].getAttribute(ATTRIBUTE_NAME);
            String value = parameterElements[i].getAttribute(ATTRIBUTE_VALUE);
            getParameterObject().put(key, value);
        }
View Full Code Here

     * @return An XML document.
     * @exception SchedulerException if an error occurs
     */
    public Document getSnapshot(Publication publication, JobWrapper[] jobs)
        throws SchedulerException {
        NamespaceHelper helper = SchedulerStore.getNamespaceHelper();
        Document document = helper.getDocument();
        Element root = document.getDocumentElement();

        log.debug("Creating job snapshot for publication [" + publication.getId() + "]");
        root.appendChild(createSnapshot(helper, publication, jobs));

View Full Code Here

     * Returns a scheduler namespace helper for a document.
     * @param document The XML document.
     * @return a namespace helper.
     */
    public static NamespaceHelper getNamespaceHelper(Document document) {
        return new NamespaceHelper(NAMESPACE, "sch", document);
    }
View Full Code Here

     * a &lt;sch:scheduler&gt; element.
     * @return a namespace helper.
     */
    public static NamespaceHelper getNamespaceHelper() {
        try {
            return new NamespaceHelper(NAMESPACE, "sch", "scheduler");
        } catch (Exception e) {
            log.error("Could not create namespace helper: ", e);

            return null;
        }
View Full Code Here

            try {
                document = DocumentHelper.readDocument(jobsFile);
            } catch (Exception e) {
                throw new SchedulerException(e);
            }
            NamespaceHelper helper = SchedulerStore.getNamespaceHelper(document);

            for (int i = 0; i < jobElements.length; i++) {
                wrappers.add(restoreJob(helper, jobElements[i], publication));
            }
        }
View Full Code Here

        try {
            File jobsFile = getJobsFile(publication);
            if (jobsFile.exists()) {
                Document document = DocumentHelper.readDocument(jobsFile);
                Element schedulerElement = document.getDocumentElement();
                NamespaceHelper helper = SchedulerStore.getNamespaceHelper(document);

                Element jobGroupElement =
                    helper.getFirstChild(schedulerElement, SchedulerStore.ELEMENT_JOB_GROUP);
                if (jobGroupElement == null) {
                    throw new SchedulerException("No <job-group> element found!");
                }

                String jobGroupAttribute = jobGroupElement.getAttribute("name");

                if (!jobGroupAttribute.equals(publication.getId())) {
                    throw new SchedulerException(
                        "The jobs.xml file contains a wrong job group: ["
                            + jobGroupAttribute
                            + "]");
                }
                jobElements = helper.getChildren(jobGroupElement, SchedulerStore.ELEMENT_JOB);

            } else {
                throw new SchedulerException(
                    "The jobs file [" + jobsFile.getAbsolutePath() + "] does not exist!");
            }
View Full Code Here

     * @return A job details object.
     */
    public JobDetail load(Element jobElement, String jobGroup, String servletContextPath) throws SchedulerException {
        JobDetail jobDetail = super.load(jobElement, jobGroup, servletContextPath);
       
        NamespaceHelper helper = SchedulerStore.getNamespaceHelper();
        DefaultTaskWrapper wrapper = new DefaultTaskWrapper(helper, jobElement);
        wrapper.getTaskParameters().setServletContextPath(servletContextPath);
       
        JobDataMap map = new JobDataMap(wrapper.getParameters());
        jobDetail.setJobDataMap(map);
View Full Code Here

            repoNode.setPersistable(this);
           
            if (repoNode.exists()) {
                org.w3c.dom.Document xml = DocumentHelper.readDocument(repoNode.getInputStream());

                NamespaceHelper helper = new NamespaceHelper(NAMESPACE, "", xml);
                Assert.isTrue("document element is site", xml.getDocumentElement().getLocalName()
                        .equals("site"));
                this.loading = true;
                reset();
                loadNodes(this.root, helper, xml.getDocumentElement());
View Full Code Here

TOP

Related Classes of org.apache.lenya.xml.NamespaceHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.