Package org.dom4j

Examples of org.dom4j.Document


            throw new RuntimeException(ex);
        }
    }

    public Document createDocument() {
        Document document = DocumentHelper.createDocument();
        Element timefinderEl = document.addElement("timefinder"/*, "xmlnsValue"*/);
        timefinderEl.addAttribute("version", "4.1");

        writeElement(settings, timefinderEl);

        for (Dao<? extends DBInterface> dao : pool.getDaos()) {
View Full Code Here


    }

    public void doWork() {
        try {
            SAXReader saxReader = new SAXReader();
            Document document = saxReader.read(reader);

            List list = document.getRootElement().elements();
            Iterator iter = list.iterator();
            while (iter.hasNext()) {
                Element element = (Element) iter.next();
                if ("settings".equals(element.getName())) {
                    readElements(element, settings);
View Full Code Here

        return settingsFile;
    }

    public void save() throws IOException {
        File xmlFile = getSettingsFile();
        Document document = DocumentHelper.createDocument();
        Element settingsElement = document.addElement("settings");
        settingsElement.addAttribute("version", "4.1");

        for (Entry<String, Object> entry : settingsMap.entrySet()) {
            Class clazz = entry.getValue().getClass();
            Writing w = objWriting.getWriting(clazz);
View Full Code Here

    public void load() throws IOException {
        File xmlFile = getSettingsFile();
        SAXReader saxReader = new SAXReader();
        try {
            Document document = saxReader.read(new FileInputStream(xmlFile));

            List list = document.getRootElement().elements();
            Iterator iter = list.iterator();
            while (iter.hasNext()) {
                Element element = (Element) iter.next();
                try {
                    Class clazz = Class.forName(element.attributeValue("class"));
View Full Code Here

    _catalinaBase = FileUtils.createFolder(_project, "tomcat");
    _catalinaLibdir = FileUtils.createFolder(_catalinaBase, "lib");
    _catalinaConf = FileUtils.createFolder(_catalinaBase, CATALINA_CONF_DIRNAME);

    // create default auth.xml
    Document auth = DocumentFactory.getInstance().createDocument();
    Element users = auth.addElement("users");
    users.addAttribute("allowanonymous", "true");
    Element designer = users.addElement("user");
    designer.addAttribute("name", "designer");
    designer.addAttribute("password", "wga");
    designer.addAttribute("mail", "designer@example.com");
View Full Code Here

    IFile dirlink = dirlinkFolder.getFile(WGUtils.DIRLINK_FILE);
    String linkTarget = computeDirLinkTarget(dirlinkFolder, target);
    SAXReader saxReader = new SAXReader();
    try {
      File dirlinkFile = new File(dirlink.getLocationURI().getPath());
      Document document = saxReader.read(dirlinkFile);
      Element ele = (Element)document.selectSingleNode("/dirlink/path");    //TODO use statics
      ele.addAttribute("location", linkTarget);                //TODO use statics
        XMLWriter output = new XMLWriter(new FileWriter(dirlinkFile));
        try {
          output.write( document );
        } finally {
View Full Code Here

          // determine serverport and shutdown command from tomcat config
          File catalinaBase = new File(WGADesignerPlugin.getDefault().getStateLocation().toFile(), "tomcat_current");
          File conf = new File(catalinaBase, "conf");
          File serverXML = new File(conf, "server.xml");
          SAXReader reader = new SAXReader();
          Document doc = reader.read(serverXML);
          Element serverElement = (Element) doc.selectSingleNode("/Server");
          String serverPort = serverElement.attributeValue("port", "8005");
          String shutdownCommand = serverElement.attributeValue("shutdown", "SHUTDOWN");
         
          // send shutdown command to specified port
          Socket socket = new Socket();
View Full Code Here

      // ensure when we marshal/unmarshal the values in the map remain the same     
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      wrapper.marshal(out);
     
      SAXReader xmlReader = new SAXReader();
      Document doc = xmlReader.read( new ByteArrayInputStream(out.toByteArray()) );    
     
      Element root = doc.getRootElement();     
     
      MapWrapper other = new MapWrapper();
      other.setCallContext(new CallContext());
      other.setElement(root);
     
View Full Code Here

         c.setConstraints(Arrays.asList(new String[] { "secret" }));
         c.setResult(result);
         MarshalUtils.marshalResult(c, out);

         SAXReader xmlReader = new SAXReader();
         Document doc = xmlReader.read(new StringReader(new String(out
               .toByteArray())));

         Widget widget = (Widget) ParserUtils.unmarshalResult(doc
               .getRootElement());

         // value field should equal "foo"
         assert "foo".equals(widget.getValue());

         // secret field should be null
         assert widget.getSecret() == null;

         // Now extend our object graph a little further
         result.setChild(new Widget());
         result.getChild().setValue("foo");
         result.getChild().setSecret("bar");

         // Reset our output stream so we can re-use it
         out.reset();

         // Now we're going to constrain result.child's secret field
         c.setConstraints(Arrays.asList(new String[] { "child.secret" }));
         MarshalUtils.marshalResult(c, out);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
         assert "foo".equals(widget.getValue());
         assert "bar".equals(widget.getSecret());
         assert "foo".equals(widget.getChild().getValue());
         assert widget.getChild().getSecret() == null;

         // Add a map to our result
         result.setWidgetMap(new HashMap<String, Widget>());
         Widget val = new Widget();
         val.setValue("foo");
         val.setSecret("bar");
         result.getWidgetMap().put("foo", val);

         // Reset our output stream again
         out.reset();

         // Constrain the "secret" field of the widgetMap map's values (sounds
         // confusing, I know...)
         c.setConstraints(Arrays.asList(new String[] { "widgetMap[value].secret" }));
         MarshalUtils.marshalResult(c, out);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
         val = widget.getWidgetMap().get("foo");
         assert val != null;
         assert "foo".equals(val.getValue());
         assert val.getSecret() == null;

         // Reset our output stream
         out.reset();

         // Add a list to our result
         result.setWidgetList(new ArrayList<Widget>());
         Widget item = new Widget();
         item.setValue("foo");
         item.setSecret("bar");
         result.getWidgetList().add(item);

         // Constraint the "secret" field of widgetList
         c.setConstraints(Arrays.asList(new String[] { "widgetList.secret" }));
         MarshalUtils.marshalResult(c, out);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
         item = widget.getWidgetList().get(0);
         assert item != null;
         assert "foo".equals(item.getValue());
         assert item.getSecret() == null;

         // Reset our output stream
         out.reset();

         // Now constrain all secrets
         c.setConstraints(Arrays.asList(new String[] { "[" + Widget.class.getName() + "].secret" }));
         MarshalUtils.marshalResult(c, out);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());

         val = widget.getWidgetMap().get("foo");
         item = widget.getWidgetList().get(0);

         assert "foo".equals(widget.getValue());
View Full Code Here

        Component component = null;
        try {
            File componentConfig = new File(componentDir, "component.xml");
            if (componentConfig.exists()) {
                SAXReader saxReader = new SAXReader();
                Document componentXML = saxReader.read(componentConfig);
                ComponentClassLoader classLoader = new ComponentClassLoader(componentDir);
                String className = componentXML.selectSingleNode("/component/class").getText();
                String subdomain = componentXML.selectSingleNode("/component/subdomain").getText();
                //component = (Component)classLoader.loadClass(className).newInstance();
                Class aClass = classLoader.loadClass(className);
                component = (Component)aClass.newInstance();

                manager.addComponent(subdomain, component);

                components.put(componentDir.getName(), component);
                componentDirs.put(component, componentDir);
                classloaders.put(component, classLoader);
                componentDomains.put(component, subdomain);
                // Load any JSP's defined by the component.
                File webXML = new File(componentDir, "web" + File.separator + "web.xml");
                if (webXML.exists()) {
                    ComponentServlet.registerServlets(this, component, webXML);
                }
                // If there a <adminconsole> section defined, register it.
                Element adminElement = (Element)componentXML.selectSingleNode("/component/adminconsole");
                if (adminElement != null) {
                    // If global images are specified, override their URL.
                    Element imageEl = (Element)adminElement.selectSingleNode(
                            "/component/adminconsole/global/logo-image");
                    if (imageEl != null) {
View Full Code Here

TOP

Related Classes of org.dom4j.Document

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.