Example usage for org.dom4j Element addText

List of usage examples for org.dom4j Element addText

Introduction

In this page you can find the example usage for org.dom4j Element addText.

Prototype

Element addText(String text);

Source Link

Document

Adds a new Text node with the given text to this element.

Usage

From source file:org.opensha.commons.geo.RegionUtils.java

License:Apache License

private static Element addBorderStyle(Element e, Color c) {
    Element e_style = e.addElement("Style");
    e_style.addAttribute("id", Style.BORDER.toString());

    // line style
    Element e_lineStyle = e_style.addElement("LineStyle");
    Element e_color = e_lineStyle.addElement("color");
    e_color.addText(colorToHex(c));
    Element e_width = e_lineStyle.addElement("width");
    e_width.addText("3");

    // poly style
    Element e_polyStyle = e_style.addElement("PolyStyle");
    e_polyStyle.add((Element) e_color.clone());
    Element e_fill = e_polyStyle.addElement("fill");
    e_fill.addText("0");

    return e;//from   w  w w.java 2  s .c o m
}

From source file:org.opensha.commons.geo.RegionUtils.java

License:Apache License

private static Element addBorderVertexStyle(Element e) {
    Element e_style = e.addElement("Style");
    e_style.addAttribute("id", Style.BORDER_VERTEX.toString());

    // icon style
    Element e_iconStyle = e_style.addElement("IconStyle");
    Element e_color = e_iconStyle.addElement("color");
    e_color.addText(colorToHex(Color.RED));
    Element e_scale = e_iconStyle.addElement("scale");
    e_scale.addText("0.6");
    Element e_icon = e_iconStyle.addElement("Icon");
    Element e_href = e_icon.addElement("href");
    e_href.addText("http://maps.google.com/mapfiles/kml/shapes/open-diamond.png");
    return e;/*from  w  w  w  . j a v  a2 s . c o m*/
}

From source file:org.opensha.commons.geo.RegionUtils.java

License:Apache License

private static Element addGridNodeStyle(Element e, Color c) {
    Element e_style = e.addElement("Style");
    e_style.addAttribute("id", Style.GRID_NODE.toString());

    // icon style
    Element e_iconStyle = e_style.addElement("IconStyle");
    Element e_color = e_iconStyle.addElement("color");
    e_color.addText(colorToHex(c));
    Element e_scale = e_iconStyle.addElement("scale");
    e_scale.addText("0.6");
    Element e_icon = e_iconStyle.addElement("Icon");
    Element e_href = e_icon.addElement("href");
    e_href.addText("http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png");
    return e;//from  ww w  .jav  a2s  .co  m
}

From source file:org.orbeon.oxf.processor.impl.ProcessorOutputImpl.java

License:Open Source License

private RuntimeOutputFilter createFilter() {

    // Get inspector instance

    // Final filter (i.e. at the top, executed last)
    RuntimeOutputFilter outputFilter = new TopLevelOutputFilter();

    // Handle debug
    if (getDebugMessage() != null || (getInput() != null && getInput().getDebugMessage() != null)) {
        ProcessorFactory debugProcessorFactory = ProcessorFactoryRegistry
                .lookup(XMLConstants.DEBUG_PROCESSOR_QNAME);
        if (debugProcessorFactory == null)
            throw new OXFException(
                    "Cannot find debug processor factory for QName: " + XMLConstants.DEBUG_PROCESSOR_QNAME);

        for (int i = 0; i < 2; i++) {
            String debugMessage = i == 0 ? getDebugMessage()
                    : getInput() == null ? null : getInput().getDebugMessage();
            LocationData debugLocationData = i == 0 ? getLocationData()
                    : getInput() == null ? null : getInput().getLocationData();
            if (debugMessage != null) {
                Processor debugProcessor = debugProcessorFactory.createInstance();
                debugProcessor.createInput(ProcessorImpl.INPUT_DATA);
                debugProcessor.createOutput(ProcessorImpl.OUTPUT_DATA);

                // Create config document for Debug processor
                final org.dom4j.Document debugConfigDocument;
                {/* ww w  . j a  v  a2  s  . co m*/
                    debugConfigDocument = new NonLazyUserDataDocument();
                    Element configElement = debugConfigDocument.addElement("config");
                    configElement.addElement("message").addText(debugMessage);
                    if (debugLocationData != null) {
                        Element systemIdElement = configElement.addElement("system-id");
                        if (debugLocationData.getSystemID() != null)
                            systemIdElement.addText(debugLocationData.getSystemID());
                        configElement.addElement("line").addText(Integer.toString(debugLocationData.getLine()));
                        configElement.addElement("column")
                                .addText(Integer.toString(debugLocationData.getCol()));
                    }
                }
                final DOMGenerator dg = new DOMGenerator(debugConfigDocument, "debug filter",
                        DOMGenerator.ZeroValidity, DOMGenerator.DefaultContext);
                PipelineUtils.connect(dg, "data", debugProcessor, "config");
                final ProcessorOutput dbgOut = debugProcessor.getOutputByName(ProcessorImpl.OUTPUT_DATA);
                final ProcessorInput dbgIn = debugProcessor.getInputByName(ProcessorImpl.INPUT_DATA);
                outputFilter = new ConcreteRuntimeOutputFilter(dbgIn, dbgOut, outputFilter);
            }
        }
    }

    // The PropertySet can be null during properties initialization. This should be one of the
    // rare places where this should be tested on.
    final PropertySet propertySet = Properties.instance().getPropertySet();

    // Create and hook-up output validation processor if needed
    final Boolean isUserValidation = (propertySet == null) ? null
            : propertySet.getBoolean(ProcessorImpl.USER_VALIDATION_FLAG, true);
    if (isUserValidation != null && isUserValidation.booleanValue() && getSchema() != null) {
        final Processor outputValidator = new MSVValidationProcessor(getSchema());
        // Create data input and output
        final ProcessorInput input = outputValidator.createInput(ProcessorImpl.INPUT_DATA);
        final ProcessorOutput output = outputValidator.createOutput(ProcessorImpl.OUTPUT_DATA);
        // Create and connect config input
        final Processor resourceGenerator = PipelineUtils.createURLGenerator(getSchema());
        PipelineUtils.connect(resourceGenerator, ProcessorImpl.OUTPUT_DATA, outputValidator,
                MSVValidationProcessor.INPUT_SCHEMA);
        PipelineUtils.connect(MSVValidationProcessor.NO_DECORATION_CONFIG, ProcessorImpl.OUTPUT_DATA,
                outputValidator, ProcessorImpl.INPUT_CONFIG);
        outputFilter = new ConcreteRuntimeOutputFilter(input, output, outputFilter);
    }

    // Hook-up input validation processor if needed
    if (isUserValidation != null && isUserValidation.booleanValue() && getInput() != null
            && getInput().getSchema() != null) {
        final Processor inputValidator = new MSVValidationProcessor(getInput().getSchema());
        // Create data input and output
        final ProcessorInput input = inputValidator.createInput(ProcessorImpl.INPUT_DATA);
        final ProcessorOutput output = inputValidator.createOutput(ProcessorImpl.OUTPUT_DATA);
        // Create and connect config input

        final Processor resourceGenerator = PipelineUtils.createURLGenerator(getInput().getSchema());
        PipelineUtils.connect(resourceGenerator, ProcessorImpl.OUTPUT_DATA, inputValidator,
                MSVValidationProcessor.INPUT_SCHEMA);
        PipelineUtils.connect(MSVValidationProcessor.NO_DECORATION_CONFIG, ProcessorImpl.OUTPUT_DATA,
                inputValidator, ProcessorImpl.INPUT_CONFIG);
        outputFilter = new ConcreteRuntimeOutputFilter(input, output, outputFilter);
    }

    // Perform basic inspection of SAX events
    Boolean isSAXInspection = (propertySet == null) ? null
            : propertySet.getBoolean(ProcessorImpl.SAX_INSPECTION_FLAG, false);
    if (isSAXInspection != null && isSAXInspection.booleanValue()) {
        final RuntimeOutputFilter previousOutputFilter = outputFilter;
        outputFilter = new RuntimeOutputFilter() {
            @Override
            public void read(PipelineContext pipelineContext, XMLReceiver xmlReceiver) {
                InspectingXMLReceiver inspectingXMLReceiver = new InspectingXMLReceiver(xmlReceiver);
                previousOutputFilter.read(pipelineContext, inspectingXMLReceiver);
            }

            public OutputCacheKey getKey(PipelineContext pipelineContext) {
                return previousOutputFilter.getKey(pipelineContext);
            }

            public Object getValidity(PipelineContext pipelineContext) {
                return previousOutputFilter.getValidity(pipelineContext);
            }
        };
    }

    return outputFilter;
}

From source file:org.pentaho.platform.uifoundation.component.xml.LoadDBRepositoryUIComponent.java

License:Open Source License

private Document doLoad(final String solutionRoot, final boolean deleteOrphans) {

    Document document = DocumentHelper.createDocument();
    document.setName(LoadDBRepositoryUIComponent.PATH_STR);
    Element root = document.addElement(LoadDBRepositoryUIComponent.ROOT);
    Element result = root.addElement(LoadDBRepositoryUIComponent.RESULT);
    boolean usingDbRepository = true;
    try {//from   www .j av a  2s.co  m
        ISolutionRepository repository = PentahoSystem.get(ISolutionRepository.class, session);
        if (!(repository instanceof DbBasedSolutionRepository)) {
            usingDbRepository = false;
            repository = new DbBasedSolutionRepository();
        }
        List orphanedFiles = ((DbBasedSolutionRepository) repository).loadSolutionFromFileSystem(this.session,
                solutionRoot, deleteOrphans);
        result.addAttribute(LoadDBRepositoryUIComponent.TYPE_ATTRIBUTE, LoadDBRepositoryUIComponent.SUCCESS);
        if (usingDbRepository) {
            result.addText(Messages.getString("LoadDBRepositoryUIComponent.INFO_0001_SUCCESS")); //$NON-NLS-1$
        } else {
            result.addText(Messages.getString("LoadDBRepositoryUIComponent.INFO_0002_SUCCESS_NEED_CONFIG")); //$NON-NLS-1$
        }
        if ((orphanedFiles != null) && (orphanedFiles.size() > 0)) {
            Iterator iter = orphanedFiles.iterator();
            Element orphans = result.addElement(LoadDBRepositoryUIComponent.ORPHANED);
            orphans.addElement(LoadDBRepositoryUIComponent.ORPHANHANDLING)
                    .addText(deleteOrphans
                            ? Messages.getString("LoadDBRepositoryUIComponent.INFO_0004_ORPHANED_DELETED") //$NON-NLS-1$
                            : Messages.getString("LoadDBRepositoryUIComponent.INFO_0005_ORPHANED_IGNORED")); //$NON-NLS-1$
            while (iter.hasNext()) {
                orphans.addElement(LoadDBRepositoryUIComponent.FILENAME).addText(((String) iter.next()));
            }
        }
    } catch (Exception e) {
        result.addAttribute(LoadDBRepositoryUIComponent.TYPE_ATTRIBUTE, LoadDBRepositoryUIComponent.FAILURE);
        result.addText(Messages.getString("LoadDBRepositoryUIComponent.ERROR_0001_LOAD_ERROR") + solutionRoot); //$NON-NLS-1$
        e.printStackTrace();
    }
    return document;
}

From source file:org.pentaho.platform.web.refactor.SubscriptionAdminUIComponent.java

License:Open Source License

Element getReturnURL() {
    Element ele = DocumentHelper.createElement(SubscriptionAdminUIComponent.NODE_RETURN_URL);
    IParameterProvider parameterProvider = (IParameterProvider) getParameterProviders()
            .get(HttpRequestParameterProvider.SCOPE_REQUEST);
    String str = ""; //$NON-NLS-1$
    for (Iterator nameItr = parameterProvider.getParameterNames(); nameItr.hasNext();) {
        String name = (String) nameItr.next();
        String value = parameterProvider.getStringParameter(name, null);
        if (value != null) {
            str += "&" + name + "=" + value; //$NON-NLS-1$ //$NON-NLS-2$
        }/*from w  w  w .j  a  va2 s .  com*/
    }
    ele.addText(str);
    return (ele);
}

From source file:org.projectforge.web.FavoritesMenu.java

License:Open Source License

private void buildElement(final Element element, final MenuEntry menuEntry) {
    if (menuEntry.getId() != null) {
        element.addAttribute("id", menuEntry.getId());
    }/*  w ww .  j a  v  a  2s  .c  o m*/
    if (menuEntry.getName() != null) {
        element.addText(menuEntry.getName());
    }
    if (menuEntry.hasSubMenuEntries() == true) {
        for (final MenuEntry subMenuEntry : menuEntry.getSubMenuEntries()) {
            buildElement(element.addElement("item"), subMenuEntry);
        }
    }
}

From source file:org.richie.codeGen.ui.util.XmlParse.java

License:Apache License

private void setElements(T o, Class<T> clazz, Element parent) throws Exception {
    Method[] methods = clazz.getMethods();
    for (Method method : methods) {
        if (method.getName().startsWith("get") && !method.getName().equals("getClass")) {
            Element fieldElement = parent.addElement(getFieldName(method.getName()));
            Object result = method.invoke(o, new Object[] {});
            fieldElement.addText(result != null ? result.toString() : "");
        }/* ww w . j a v a2  s  . com*/
    }
}

From source file:org.sipfoundry.sipxconfig.domain.DomainDialingRule.java

License:Contributor Agreement License

@Override
public Transform[] getTransforms() {
    Transform hostTransform = new Transform() {
        @Override/*w  ww  .j  a  v  a  2s  . c  o m*/
        protected void addChildren(Element transform) {
            Element host = transform.addElement("host");
            host.addText(m_domain.getName());
        }
    };
    return new Transform[] { hostTransform };
}

From source file:org.snipsnap.util.XMLSnipRepair.java

License:Open Source License

private static Document repair(Document document, File webAppRoot) {
    Map userData = new TreeMap();
    Map snipData = new TreeMap();
    Map unknown = new TreeMap();

    Element rootEl = document.getRootElement();
    Iterator elementIt = rootEl.elementIterator();

    System.err.println("STEP 2.1: checking for duplicates ...");
    long identDup = 0;
    long oldDup = 0;
    long newDup = 0;
    while (elementIt.hasNext()) {
        Element element = (Element) elementIt.next();
        Element idElement = null;
        Map data = null;//w  w w.  j  a  va2s  . c  o m
        if ("user".equals(element.getName())) {
            idElement = element.element("login");
            data = userData;
        } else if ("snip".equals(element.getName())) {
            idElement = element.element("name");
            data = snipData;
        }

        if (null != data && null != idElement) {
            String id = element.getName() + "[" + idElement.getText() + "]";
            long mtime = Long.parseLong(element.element("mTime").getTextTrim());

            Element existingElement = (Element) data.get(id);
            if (existingElement != null) {
                long lastmtime = Long.parseLong(existingElement.element("mTime").getTextTrim());
                if (mtime > lastmtime) {
                    newDup++;
                    System.err.println(
                            "Replacing duplicate by newer element: " + id + " (" + (mtime - lastmtime) + "ms)");
                    data.put(id, element);
                } else if (mtime == lastmtime) {
                    identDup++;
                    System.err.println("Identical duplicate found: " + id);
                } else {
                    oldDup++;
                    System.err.println("Older duplicate found: " + id);
                }
                if (snipData == data) {
                    String name = idElement.getText();
                    if (name.startsWith("comment-") && name.lastIndexOf("-") != -1) {
                        String commentSnip = name.substring("comment-".length(), name.lastIndexOf("-"));
                        Element commentEl = element.element("commentSnip");
                        if (commentEl == null) {
                            commentEl = element.addElement("commentSnip");
                        }
                        //            System.out.println("commentSnip='" + commentSnip.toUpperCase() + "' commentEl='" + commentEl.getText().toUpperCase() + "'");
                        if (!commentSnip.toUpperCase().equals(commentEl.getText().toUpperCase())) {
                            commentEl.addText(commentSnip);
                            System.err
                                    .println("Fixing commented snip for '" + name + "' (" + commentSnip + ")");
                        }
                    } else if (name.matches("\\d\\d\\d\\d-\\d\\d-\\d\\d")) {
                        Element parentEl = element.element("parentSnip");
                        if (null == parentEl) {
                            parentEl = element.addElement("parentSnip");
                        }
                        if (!"start".equals(parentEl.getText())) {
                            parentEl.addText("start");
                            System.err.println("Fixing parent snip for '" + name + "'");
                        }
                    }
                }
            } else {
                data.put(id, element);
            }
        } else {
            System.err.println("Unknown element '" + element.getName() + "', ignoring ...");
            unknown.put(element, element);
        }
    }

    System.err.println(
            "Found " + identDup + " identical duplicates, replaced " + newDup + ", ignored " + oldDup + ".");
    if (unknown.size() > 0) {
        System.err.println("Found " + unknown.size() + " unknown xml elements.");
    }

    Document outputDocument = DocumentHelper.createDocument();
    outputDocument.addElement(rootEl.getName());
    rootEl = outputDocument.getRootElement();

    System.err.println("STEP 2.2: finishing user data (" + userData.size() + ")...");
    Iterator userIt = userData.values().iterator();
    while (userIt.hasNext()) {
        Element userEl = (Element) userIt.next();
        rootEl.add(userEl.detach());
    }

    int attCount = 0;
    System.err.print("STEP 2.3: fixing snip data (" + snipData.size() + ")");
    if (webAppRoot != null) {
        System.out.println(" and attachments ...");
    } else {
        System.out.println();
    }
    Iterator snipIt = snipData.values().iterator();
    while (snipIt.hasNext()) {
        Element snipEl = (Element) snipIt.next();
        if (webAppRoot != null) {
            attCount += storeAttachments(snipEl, new File(webAppRoot, "/WEB-INF/files"));
            attCount += storeOldImages(snipEl, new File(webAppRoot, "/images"));
        }
        rootEl.add(snipEl.detach());
    }
    System.err.println("Added " + attCount + " attachments.");
    return outputDocument;
}