Package net.sf.jpluck.xml

Examples of net.sf.jpluck.xml.ContextAdapter


        maxDepthSpinner.setValue(new Integer(document.getLinkDepth()));
        if (document.getReferrer() != null) {
            referrerText.setText(document.getReferrer());
        }

        ContextAdapter ctx = new ContextAdapter(document.getElement());

        List categoryList = new ArrayList();
        for (Iterator it = ctx.iterate("category"); it.hasNext();) {
            categoryList.add((String) it.next());
        }
        categories = (String[]) categoryList.toArray(new String[categoryList.size()]);
        if (categories.length > 0) {
            categoryText.setText(categories[0]);
        }
        categoryButton.setToolTipText("" + Arrays.asList(categories));

        String template = document.getTemplateID();
        templateCombo.setSelectedItem(template);

        if (document instanceof Feed) {
            Feed feed = (Feed) document;
            if (feed.isUsePageStructure()) {
                structureCombo.setSelectedIndex(0);
            } else if (feed.isUseListStructure()) {
                structureCombo.setSelectedIndex(1);
            } else {
                structureCombo.setSelectedIndex(2);
            }
            if (feed.getMaxAge() != -1) {
                maxAgeCheck.setSelected(true);
                maxAgeSpinner.setValue(new Integer(feed.getMaxAge()));
            }
        }

        Pointer p = ctx.getPointer("schedule/*");
        if (p != null) {
            Element element = (Element) p.getNode();
            String s = element.getNodeName();
            if (s.equals("cron")) {
                scheduleCombo.setSelectedItem("cron");
            } else {
                scheduleCombo.setSelectedItem(s);
            }
            if (s.equals("hourly")) {
                minuteSpinner.setValue(new Integer(Integer.parseInt(element.getAttribute("minute"))));
            } else if (s.equals("daily")) {
                Calendar cal = Calendar.getInstance();
                cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(element.getAttribute("hour")));
                cal.set(Calendar.MINUTE, Integer.parseInt(element.getAttribute("minute")));
                dailyTimeSpinner.setValue(cal.getTime());
            } else if (s.equals("weekly")) {
                String day = element.getAttribute("day");
                day = day.substring(0, 1).toUpperCase() + day.substring(1);
                dayCombo.setSelectedItem(day);

                Calendar cal = Calendar.getInstance();
                cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(element.getAttribute("hour")));
                cal.set(Calendar.MINUTE, Integer.parseInt(element.getAttribute("minute")));
                weeklyTimeSpinner.setValue(cal.getTime());
            } else if (s.equals("monthly")) {
                Calendar cal = Calendar.getInstance();
                String day = element.getAttribute("day");
                if (day.equals("last")) {
                    dayOfMonthCombo.setSelectedIndex(31);
                } else {
                    dayOfMonthCombo.setSelectedIndex(Integer.parseInt(day) - 1);
                }
                cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(element.getAttribute("hour")));
                cal.set(Calendar.MINUTE, Integer.parseInt(element.getAttribute("minute")));
                monthlyTimeSpinner.setValue(cal.getTime());
            } else if (s.equals("cron")) {
                cronText.setText(element.getFirstChild().getNodeValue());
            }
        }

        altTextCheck.setSelected(document.isIncludeAltText());
        p = ctx.getPointer("images/embedded");
        if (p != null) {
            Element embedded = (Element) p.getNode();
            setBppCombo(embeddedBppCombo, Integer.parseInt(embedded.getAttribute("bpp")));
            String width = embedded.getAttribute("maxWidth");
            embeddedWidthCheck.setSelected(width.length() > 0);
            embeddedWidthText.setText(width);
            String height = embedded.getAttribute("maxHeight");
            embeddedHeightText.setText(height);
            embeddedHeightCheck.setSelected(height.length() > 0);
            alternateCheck.setSelected(embedded.getAttribute("alternate").equals("yes"));
        }
        embeddedBppListener.itemStateChanged(null);
        p = ctx.getPointer("images/standalone");
        if (p != null) {
            Element standalone = (Element) p.getNode();
            setBppCombo(standaloneBppCombo, Integer.parseInt(standalone.getAttribute("bpp")));
            String width = standalone.getAttribute("maxWidth");
            standaloneWidthCheck.setSelected(width.length() > 0);
            standaloneWidthText.setText(width);
            String height = standalone.getAttribute("maxHeight");
            standaloneHeightText.setText(height);
            standaloneHeightCheck.setSelected(height.length() > 0);
        }
        if (ctx.getValue("@linkColor") != null) {
            linksCombo.setSelectedIndex(1);
            linkColorText.setText(ctx.getValue("@linkColor").toString());
        }
        if (document.isRemoveUnresolvedLinks()) {
            unresolvedLinksCombo.setSelectedIndex(1);
        } else if (ctx.getValue("@unresolvedLinkColor") != null) {
            unresolvedLinksCombo.setSelectedIndex(2);
            unresolvedLinkColorText.setText(ctx.getValue("@unresolvedLinkColor").toString());
        }

        inputEncodingCombo.setSelectedItem(document.getInputEncoding());
        outputEncodingCombo.setSelectedItem(document.getOutputEncoding());

        Iterator it = ctx.iterate("uriPatterns/include");
        while (it.hasNext()) {
            inclusionPanel.addPattern((String) it.next());
        }
        it = ctx.iterate("uriPatterns/exclude");
        while (it.hasNext()) {
            exclusionPanel.addPattern((String) it.next());
        }

        includeURIInfoCheck.setSelected(document.isIncludeURIInfo());
View Full Code Here


    }

    private void update(Document document) {
        Element element = document.getElement();
        org.w3c.dom.Document dom = element.getOwnerDocument();
        ContextAdapter ctx = new ContextAdapter(JXPathContext.newContext(element));
        if (!editingDefault) {
            ctx.setValue("name", nameText.getText());
        }
        ctx.removeAll("category");

        Pointer p = ctx.getPointer("description|schedule|transform|autoBookmark");
        for (int i = 0; i < categories.length; i++) {
            Element category = (Element) dom.createElement("category");
            category.appendChild(dom.createTextNode(categories[i]));
            if (p != null) {
                element.insertBefore(category, (Element) p.getNode());
            } else {
                element.appendChild(category);
            }
        }

        if (!editingDefault) {
            String template = (String) templateCombo.getSelectedItem();
            if (template.equals("_default")) {
                ctx.remove("@template");
            } else {
                ctx.setValue("@template", template);
            }
        }

        if (!editingDefault) {
            ctx.setValue("uri", uriText.getText());
        }

        int depth = ((Integer) maxDepthSpinner.getValue()).intValue();
        if (depth > 0) {
            ctx.setValue("uri/@maxDepth", String.valueOf(depth));
        } else {
            ctx.remove("uri/@maxDepth");
        }
        document.resetStartingURI();

        String restrict = (String) restrictCombo.getSelectedItem();
        if (restrict.equals("none")) {
            ctx.remove("uri/@restrict");
        } else {
            ctx.setValue("uri/@restrict", restrict);
        }
    if (referrerText.getText().length() > 0) {
      ctx.setValue("uri/@referrer", referrerText.getText());
    } else {
      ctx.remove("uri/@referrer");
    }

        if (element.getNodeName().equals("feed")) {
            populateFeedStructure(element);
        }

        String s = (String) scheduleCombo.getSelectedItem();
        if (s.equals("none")) {
            ctx.removeAll("schedule");
        } else {
            p = ctx.getPointer("schedule");

            Element schedule;
            if (p != null) {
                schedule = (Element) p.getNode();
                ctx.removeAll("schedule/*");
            } else {
                schedule = dom.createElement("schedule");
                p = ctx.getPointer("transform|autoBookmark");
                if (p != null) {
                    element.insertBefore(schedule, (Element) p.getNode());
                } else {
                    element.appendChild(schedule);
                }
            }

            populateSchedule(dom, schedule);
        }

        if (altTextCheck.isSelected() && (embeddedBppCombo.getSelectedIndex() == 0) &&
                    (standaloneBppCombo.getSelectedIndex() == 0)) {
            ctx.removeAll("images");
        }

        if (altTextCheck.isSelected()) {
            ctx.removeAll("images/@includeAltText");
        } else {
            p = ctx.getPointer("images");
            if (p != null) {
                Element images = (Element) p.getNode();
                images.setAttribute("includeAltText", "no");
            } else {
                Element images = dom.createElement("images");
                images.setAttribute("includeAltText", "no");
                p = ctx.getPointer("category|description|schedule|transform|autoBookmark");
                if (p != null) {
                    element.insertBefore(images, (Element) p.getNode());
                } else {
                    element.appendChild(images);
                }
            }
        }

        if (embeddedBppCombo.getSelectedIndex() == 0) {
            ctx.removeAll("images/embedded");
        } else {
            p = ctx.getPointer("images/embedded");
            Element embedded;
            if (p != null) {
                embedded = (Element) p.getNode();
            } else {
                embedded = dom.createElement("embedded");
                p = ctx.getPointer("images");
                if (p != null) {
                    Element images = (Element) p.getNode();
                    p = ctx.getPointer("images/standalone");
                    if (p != null) {
                        Element standalone = (Element) p.getNode();
                        images.insertBefore(embedded, standalone);
                    } else {
                        images.appendChild(embedded);
                    }
                } else {
                    Element images = dom.createElement("images");
                    p = ctx.getPointer("category|description|schedule|transform|autoBookmark");
                    if (p != null) {
                        element.insertBefore(images, (Element) p.getNode());
                    } else {
                        element.appendChild(images);
                    }
                    images.appendChild(embedded);
                }
            }
            populateEmbedded(embedded);
        }
        if (standaloneBppCombo.getSelectedIndex() == 0) {
            ctx.removeAll("images/standalone");
        } else {
            p = ctx.getPointer("images/standalone");
            Element standalone;
            if (p != null) {
                standalone = (Element) p.getNode();
            } else {
                standalone = dom.createElement("standalone");
                p = ctx.getPointer("images");
                if (p != null) {
                    Element images = (Element) p.getNode();
                    images.appendChild(standalone);
                } else {
                    Element images = dom.createElement("images");
                    p = ctx.getPointer("category|description|schedule|transform|autoBookmark");
                    if (p != null) {
                        element.insertBefore(images, (Element) p.getNode());
                    } else {
                        element.appendChild(images);
                    }
                    images.appendChild(standalone);
                }
            }
            populateStandalone(standalone);
        }

        String[] inclusionPatterns = inclusionPanel.getPatterns();
    String[] exclusionPatterns = exclusionPanel.getPatterns();
        if (inclusionPatterns.length > 0 || exclusionPatterns.length > 0) {
            Element uriPatterns;
            p = ctx.getPointer("uriPatterns");
            if (p != null) {
                uriPatterns = (Element) p.getNode();
            } else {
                p = ctx.getPointer("images|category|description|schedule|transform|autoBookmark");
                uriPatterns = dom.createElement("uriPatterns");
                if (p != null) {
                    element.insertBefore(uriPatterns, (Element) p.getNode());
                } else {
                    element.appendChild(uriPatterns);
                }
            }
            ctx.removeAll("uriPatterns/*");
            for (int i = 0; i < inclusionPatterns.length; i++) {
                Element include = dom.createElement("include");
                include.appendChild(dom.createTextNode(inclusionPatterns[i]));
                uriPatterns.appendChild(include);
            }
      for (int i = 0; i < exclusionPatterns.length; i++) {
        Element exclude = dom.createElement("exclude");
        exclude.appendChild(dom.createTextNode(exclusionPatterns[i]));
        uriPatterns.appendChild(exclude);
      }
        } else {
            ctx.remove("uriPatterns");
        }
        ctx.remove("filename");
        if (filenameText.getText().length() > 0) {
            Element filename = dom.createElement("filename");
            filename.appendChild(dom.createTextNode(filenameText.getText()));
            element.insertBefore(filename, (Element) ctx.getPointer("uri").getNode());
        }

        populateAttributes(element);

        document.configureParentTemplate();
View Full Code Here

  private CronTrigger createTrigger() {
    try {
      CronTrigger trigger = new CronTrigger();
      trigger.setTimeZone(TimeZone.getDefault());

      ContextAdapter context = new ContextAdapter(JXPathContext.newContext(resolvePointer("schedule").getNode()));
      Pointer p = context.getPointer("hourly");
      if (p != null) {
        String minute = (String) context.getValue("hourly/@minute");
        trigger.setCronExpression("0 " + minute + " * ? * *");
      } else {
        p = context.getPointer("daily");
        if (p != null) {
          String hour = (String) context.getValue("daily/@hour");
          String minute = (String) context.getValue("daily/@minute");
          trigger.setCronExpression("0 " + minute + " " + hour + " ? * *");
        } else {
          p = context.getPointer("weekly");
          if (p != null) {
            String day = (String) context.getValue("weekly/@day");
            String hour = (String) context.getValue("weekly/@hour");
            String minute = (String) context.getValue("weekly/@minute");
            trigger.setCronExpression("0 " + minute + " " + hour + " ? * " + getWeekDay(day));
          } else {
            p = context.getPointer("monthly");
            if (p != null) {
              String day = (String) context.getValue("monthly/@day");
              if (day.equalsIgnoreCase("last")) {
                day = "L";
              }

              String hour = (String) context.getValue("monthly/@hour");
              String minute = (String) context.getValue("monthly/@minute");
              trigger.setCronExpression("0 " + minute + " " + hour + " " + day + " * ?");
            } else {
              p = context.getPointer("cron");
              if (p != null) {
                trigger.setCronExpression((String) p.getValue());
              }
            }
          }
View Full Code Here

        TransformerFactory tfactory = TransformerFactory.newInstance();
        tfactory.setURIResolver(new Resolver());
        for (Iterator it = resolveIteratePointers("transform"); it.hasNext();) {
            Pointer p = (Pointer) it.next();
            Element transformElement = (Element) p.getNode();
            ContextAdapter transformContext = new ContextAdapter(transformElement);
            List xslList = new ArrayList();
            for (Iterator it2 = transformContext.iteratePointers("xslt"); it2.hasNext();) {
                Pointer p2 = (Pointer) it2.next();
                Element xslElement = (Element) p2.getNode();
                Source source;
                String href = xslElement.getAttribute("href");
                if (href.length() > 0) {
                    source = new StreamSource(jxl.resolve(href));
                } else {
                    NodeList nodeList = xslElement.getElementsByTagNameNS(NamespaceURI.XSL, "stylesheet");
                    if (nodeList.getLength() == 1) {
                        source = new DOMSource((Element) nodeList.item(0));
                    } else {
                        throw new RuntimeException("No <xsl:stylesheet> specified inside <xslt> element.");
                    }
                }

                Templates templates = tfactory.newTemplates(source);

                ContextAdapter xslContext = new ContextAdapter(xslElement);
                List parameterList = new ArrayList();
                for (Iterator it3 = xslContext.iteratePointers("param"); it3.hasNext();) {
                    Pointer p3 = (Pointer) it3.next();
                    Element paramElement = (Element) p3.getNode();
                    parameterList.add(new Parameter(paramElement.getAttribute("name"),
                                                    paramElement.getAttribute("value")));
                }
View Full Code Here

TOP

Related Classes of net.sf.jpluck.xml.ContextAdapter

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.