Example usage for org.dom4j DocumentHelper createElement

List of usage examples for org.dom4j DocumentHelper createElement

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createElement.

Prototype

public static Element createElement(String name) 

Source Link

Usage

From source file:Main2.java

License:Open Source License

public static void main(String[] args) throws IOException {
    boolean printTokens = false;
    boolean showTree = false;
    boolean produceXml = false;
    boolean produceSource = false;
    for (int i = 2; i < args.length; i++) {
        if (args[i].length() == 2) {
            switch (args[i].charAt(1)) {
            case 't':
                printTokens = true;//from   ww w  . ja v  a  2 s .co m
                break;
            case 'v':
                showTree = true;
                break;
            case 'x':
                produceXml = true;
                break;
            case 's':
                produceSource = true;
                break;
            }
        }
    }
    ASTWindow window = showTree ? new ASTWindow("AST") : null;
    Document doc = null;
    if (produceXml) {
        doc = DocumentHelper.createDocument(DocumentHelper.createElement("asp"));
    }
    try {
        File f = new File(args[0]);
        File base = new File(args[1]);
        if (printTokens) {
            AspStreamSelector selector = new AspStreamSelector(f, base);
            printApsTokens(selector);
            if (!(showTree || produceXml)) {
                return;
            }
        }
        AspParser asp = new AspParser(base, new File("out"));
        asp.setGenerateCode(produceSource);
        Map vbTokens = null;
        Map jsTokens = null;
        Map tokens = null;
        List astList = asp.parseFile(f, true);
        for (Iterator it = astList.iterator(); it.hasNext();) {
            Object[] val = (Object[]) it.next();
            boolean isVb = ((Boolean) val[0]).booleanValue();
            if (showTree) {
                if (isVb) {
                    window.addAST("Original VB", createRoot("VB ASP", (AST) val[1]));
                    if (val.length > 2) {
                        window.addAST("VB Generated", createRoot("VB", (AST) val[2]));
                    }
                } else {
                    window.addAST("ASP JS", createRoot("JS", (AST) val[1]));
                    window.addAST("JS Generated", createRoot("JS", (AST) val[2]));
                }
            }
            if (produceXml) {
                String rootName;
                if (isVb) {
                    rootName = "vb";
                    if (vbTokens == null) {
                        vbTokens = new HashMap();
                        putTokens(new VbsTree(), vbTokens);
                    }
                    tokens = vbTokens;
                } else {
                    rootName = "js";
                    if (jsTokens == null) {
                        jsTokens = new HashMap();
                        putTokens(new JsTree(), jsTokens);
                    }
                    tokens = jsTokens;
                }
                Element nodeEl = doc.getRootElement().addElement(rootName);
                Element orig = nodeEl.addElement("original");
                new XmlTestBuilder(orig, tokens).visit((AST) val[1]);
                Element trans = nodeEl.addElement("translated");
                new XmlTestBuilder(trans, tokens).visit((AST) val[2]);
            }
        }
        if (produceXml) {
            OutputFormat of = OutputFormat.createPrettyPrint();
            of.setEncoding("ISO-8859-7");
            XMLWriter xwriter = new XMLWriter(new FileWriter("asp.xml"), of);
            xwriter.write(doc);
            xwriter.close();
        }
        if (showTree && window.hasAST()) {
            window.pack();
            window.setVisible(true);
            window.setExtendedState(Frame.MAXIMIZED_BOTH);
        }
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
        System.err.println("Error");
    }
}

From source file:android.apn.androidpn.server.xmpp.handler.IQAuthHandler.java

License:Open Source License

/**
 * Constructor.//from  www . ja  va2  s . c  o m
 */
public IQAuthHandler() {
    probeResponse = DocumentHelper.createElement(QName.get("query", NAMESPACE));
    probeResponse.addElement("username");
    if (AuthManager.isPlainSupported()) {
        probeResponse.addElement("password");
    }
    if (AuthManager.isDigestSupported()) {
        probeResponse.addElement("digest");
    }
    probeResponse.addElement("resource");
}

From source file:android.apn.androidpn.server.xmpp.handler.IQRegisterHandler.java

License:Open Source License

/**
 * Constructor.//  w  w w.ja  v  a  2  s  .  c o  m
 */
public IQRegisterHandler() {
    userService = ServiceLocator.getUserService();
    probeResponse = DocumentHelper.createElement(QName.get("query", NAMESPACE));
    probeResponse.addElement("username");
    probeResponse.addElement("password");
    probeResponse.addElement("email");
    probeResponse.addElement("name");
}

From source file:android.apn.androidpn.server.xmpp.push.NotificationManager.java

License:Open Source License

/**
 * Creates a new notification IQ and returns it.
 *//*from   w w  w.j a v a  2  s.  co m*/
private IQ createNotificationIQ(String apiKey, String title, String message, String uri) {
    Random random = new Random();
    String id = Integer.toHexString(random.nextInt());
    // String id = String.valueOf(System.currentTimeMillis());

    Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE));
    notification.addElement("id").setText(id);
    notification.addElement("apiKey").setText(apiKey);
    notification.addElement("title").setText(title);
    notification.addElement("message").setText(message);
    notification.addElement("uri").setText(uri);

    IQ iq = new IQ();
    iq.setType(IQ.Type.set);
    iq.setChildElement(notification);

    return iq;
}

From source file:ca.qc.cegepoutaouais.tge.pige.server.report.ReportHelper.java

License:Open Source License

/**
 * Applique un style CSS  un document HTML.
 * La section 'head' du document HTML est extraite afin d'y insrer
 * le style CSS.//from  www .  ja  va  2  s.c  o  m
 *
 * @param htmlDoc document HTML  traiter
 * @param style style CSS  insrer
 * @throws ReportException
 */
public static void applyStyleToHTML(Document htmlDoc, String style) throws ReportException {
    Element headerTag = (Element) htmlDoc.selectSingleNode("//head");
    Element styleTag = DocumentHelper.createElement("style");
    styleTag.addText(style);
    headerTag.add(styleTag);
}

From source file:cc.warlock.core.client.logging.LoggingConfiguration.java

License:Open Source License

public List<Element> getTopLevelElements() {
    Element logging = DocumentHelper.createElement("logging");
    logging.addAttribute("enabled", enableLogging + "");
    logging.addAttribute("format", logFormat);

    Element dir = DocumentHelper.createElement("dir");
    logging.add(dir);//from w w w  .j  a va  2 s. c  o  m
    dir.setText(logDirectory.getAbsolutePath());

    return Arrays.asList(new Element[] { logging });
}

From source file:cc.warlock.core.client.settings.internal.ClientConfigurationProvider.java

License:Open Source License

protected Element fontToElement(WarlockFont font, String elementName) {
    Element fontEl = DocumentHelper.createElement(elementName);
    addFontAttributes(font, fontEl);// w  w  w  . ja  v  a 2  s .  c  o m

    return fontEl;
}

From source file:cc.warlock.core.client.settings.internal.ClientSettings.java

License:Open Source License

@Override
protected void saveTo(List<Element> elements) {
    Element element = DocumentHelper.createElement("client-settings");
    element.addAttribute("version", version + "");
    element.addAttribute("client-id", client.getClientId());

    elements.add(element);/*from  www.j  a  va 2  s.  co  m*/

    for (IConfigurationProvider provider : childProviders) {
        for (Element childElement : provider.getTopLevelElements()) {
            element.add(childElement);
        }
    }
}

From source file:cc.warlock.core.client.settings.internal.HighlightConfigurationProvider.java

License:Open Source License

@Override
protected void saveTo(List<Element> elements) {
    //System.out.println("Saving highlights");
    Element highlightsElement = DocumentHelper.createElement("highlights");

    for (IHighlightString string : highlights) {
        Element hElement = highlightsElement.addElement("highlight");
        fillElement(hElement, string);//from  w  w w .  j av  a2s.  co m

        createStyleElement(hElement, string.getStyle());
    }

    for (Map.Entry<String, IWarlockStyle> entry : namedStyles.entrySet()) {
        highlightsElement.add(createStyleElement(entry.getValue()));
    }

    elements.add(highlightsElement);
}

From source file:cc.warlock.core.client.settings.internal.HighlightConfigurationProvider.java

License:Open Source License

protected Element createStyleElement(Element parent, IWarlockStyle style) {
    Element element = null;/*www  .ja v a2  s. co m*/
    if (parent != null) {
        element = parent.addElement("style");
    } else {
        element = DocumentHelper.createElement("style");
    }

    if (style.getName() != null)
        element.addAttribute("name", style.getName());

    element.addAttribute("background", colorString(style.getBackgroundColor()));
    element.addAttribute("foreground", colorString(style.getForegroundColor()));

    for (IWarlockStyle.StyleType styleType : style.getStyleTypes()) {
        Element sElement = element.addElement("styleType");
        sElement.setText(styleType.name());
    }

    element.addAttribute("full-line", "" + style.isFullLine());
    //System.out.println("saving sound " + style.getSound());
    element.addAttribute("sound", style.getSound());
    return element;
}