org.jdom2.Namespace Java Examples

The following examples show how to use org.jdom2.Namespace. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IOProcessorImpl.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
private <T extends NamespaceUriAware,
        R extends NamespaceReader<? extends T>,
        P extends NamespacePersister<? super T>> Element persist(NamespaceIOFactory<T, R, P> factory, T entity,
                                                                 Namespace parentNamespace, Namespace... defaultNamespaces) {
    P persister;
    if (defaultNamespaces != null && defaultNamespaces.length > 0 && defaultNamespaces[0] != null
            && entity.getNamespaceUri().equals(parentNamespace.getURI()))
        persister = factory.produce((Class<T>) entity.getClass(), defaultNamespaces);
    else
        persister = factory.produce(entity);

    if (persister != null) {
        if (persister instanceof IOProcessorAware)
            ((IOProcessorAware) persister).setIOProcessor(this);
        Element element = persister.persist(entity, parentNamespace);
        installNamespace(element, entity.getNamespace(), element.getNamespace());
        return element;
    } else
        return null;
}
 
Example #2
Source File: DataSchemaBuilder.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Element createDataTypeElement(String varName, String dataType, Namespace defNS) {

        // internal types already have a definition 
        if (YInternalType.isType(dataType)) {
            return YInternalType.getSchemaFor(dataType, varName);
        }

        Element element = new Element("element", defNS);
        element.setAttribute("name", varName);

        // simple types are defined by attribute, user-defined types are defined by
        // sub elements
        if (isXSDType(dataType)) {
            element.setAttribute("type", prefix(dataType, defNS));
        }
        else {
            element = cloneUserDefinedType(element, dataType, defNS);
        }

        return element;
    }
 
Example #3
Source File: YDecompositionParser.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Adds parameter specific information to the YParameter argument (in &amp; out var).
 * @param paramElem the XML data
 * @param parameter the in &amp; out var.
 */
public static void parseParameter(Element paramElem, YParameter parameter,
                                  Namespace ns, boolean version2) {
    parseLocalVariable(paramElem, parameter, ns, version2);

    String orderStr = paramElem.getChildText("ordering");
    if ((orderStr != null) && (StringUtil.isIntegerString(orderStr))) 
        parameter.setOrdering(Integer.parseInt(orderStr));
    
    boolean isCutThroughParam = paramElem.getChild("isCutThroughParam", ns) != null;
    if (isCutThroughParam) {
        parameter.setIsCutThroughParam(isCutThroughParam);
    }

    String defaultValue = JDOMUtil.decodeEscapes(
            paramElem.getChildText("defaultValue", ns));
    if (defaultValue != null) parameter.setDefaultValue(defaultValue);

    parameter.setLogPredicate(parseLogPredicate(paramElem, ns));
}
 
Example #4
Source File: N2oRestInvocationPersister.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Override
public Element persist(N2oRestInvocation entity,Namespace namespace) {
    Element element = new Element(getElementName(), getNamespacePrefix(), getNamespaceUri());
    setAttribute(element, "method", entity.getMethod());
    setAttribute(element, "date-format", entity.getDateFormat());
    setElementString(element, "query", entity.getQuery());
    if (entity.getProxyHost() != null) setAttribute(element, "proxy-host", entity.getProxyHost());
    if (entity.getDateFormat() != null)
        setAttribute(element, "date-format", entity.getDateFormat());
    if (entity.getProxyPort() != null)
        setAttribute(element, "proxy-port", entity.getProxyPort().toString());
    if (entity.getErrorMapping() != null) {
        setChild(element, "error-mapping", entity.getErrorMapping(), new RestErrorMappingElementPersister(getNamespaceUri(), getNamespacePrefix()));
    }
    return element;
}
 
Example #5
Source File: TreeXmlPersister.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Override
public Element getWidget(N2oTree n2o, Namespace namespace) {
    Element rootElement = new Element(getElementName(), namespace);
    persistWidget(rootElement, n2o, namespace);
    if (n2o.getAjax() != null) {
        Element ajax = new Element("ajax", namespace);
        ajax.addContent(n2o.getAjax().toString());
        rootElement.addContent(ajax);
    }
    if (n2o.getCheckboxes() != null) {
        Element checkboxes = new Element("checkboxes", namespace);
        checkboxes.addContent(n2o.getCheckboxes().toString());
        rootElement.addContent(checkboxes);
    }

    Element inheritanceNodes = new Element("inheritance-nodes", namespace);
    inheritanceNodes.setAttribute("parent-field-id", n2o.getParentFieldId());
    inheritanceNodes.setAttribute("label-field-id", n2o.getLabelFieldId());
    if (n2o.getHasChildrenFieldId() != null)
        inheritanceNodes.setAttribute("has-children-field-id", n2o.getHasChildrenFieldId());
    if (n2o.getIconFieldId() != null)
        inheritanceNodes.setAttribute("icon-field-id", n2o.getIconFieldId());
    rootElement.addContent(inheritanceNodes);
    return rootElement;
}
 
Example #6
Source File: N2oCheckboxGridPersister.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Override
public Element persist(N2oCheckboxGrid control, Namespace namespace) {
    Element element = new Element(getElementName(), namespacePrefix, namespaceUri);
    setControl(element, control);
    setField(element, control);
    setListField(element, control);
    setListQuery(element, control);
    setOptionsList(element, control.getOptions());

    setSubChild(element, "columns", "column", control.getColumns(), (column, n) -> {
        Element itemElement = new Element("column", namespacePrefix, namespaceUri);
        setAttribute(itemElement, "name", column.getName());
        setAttribute(itemElement, "column-field-id", column.getColumnFieldId());
        return itemElement;
    });
    return element;
}
 
Example #7
Source File: N2oSelectXmlReaderV1.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Override
public N2oSelect read(Element element, Namespace namespace) {
    N2oSelect select = new N2oSelect();
    select.setType(getAttributeEnum(element, "type", ListType.class));
    Element showModalElement = element.getChild("show-modal", namespace);
    if (showModalElement != null)
        select.setShowModal(ShowModalFromClassifierReaderV1.getInstance().read(showModalElement));
    select.setSearchAsYouType(getAttributeBoolean(element, "search-as-you-type", "search-are-you-type"));
    select.setSearch(getAttributeBoolean(element, "search"));
    select.setWordWrap(getAttributeBoolean(element, "word-wrap"));
    boolean quick = select.getQueryId() != null;
    boolean advance = select.getShowModal() != null;
    N2oClassifier.Mode mode = quick && !advance ? N2oClassifier.Mode.quick
            : advance && !quick ? N2oClassifier.Mode.advance
            : N2oClassifier.Mode.combined;
    select.setMode(mode);
    return (N2oSelect) getQueryFieldDefinition(element, select);
}
 
Example #8
Source File: DataSchemaBuilder.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Element createPreamble(String rootName, Namespace defNS) {

        // create a new doc with a root element called 'schema'
        Element root = new Element("schema", defNS);
        root.setAttribute("elementFormDefault", "qualified");
        new Document(root);     // attaches a default doc as parent of root element

        // attach an element set to the supplied root name
        Element taskElem = new Element("element", defNS);
        taskElem.setAttribute("name", rootName);
        root.addContent(taskElem);

        Element complex = new Element("complexType", defNS);
        Element sequence = new Element("sequence", defNS);
        taskElem.addContent(complex);
        complex.addContent(sequence);

        return sequence;
    }
 
Example #9
Source File: PageXmlReaderV1.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Override
public N2oStandardPage read(Element root, Namespace namespace) {
    String elementName = root.getName();
    if (!elementName.equals("page")) throw new MetadataReaderException("element <page> not found");
    N2oStandardPage n2oPage = new N2oStandardPage();
    n2oPage.setObjectId(ReaderJdomUtil.getElementString(root, "object-id"));
    n2oPage.setName(ReaderJdomUtil.getElementString(root, "name"));
    n2oPage.setSrc(ReaderJdomUtil.getElementString(root, "src"));
    List<N2oRegion> regions = new ArrayList<>();
    Element containers = root.getChild("containers", namespace);
    if (containers != null) {
        readContainers(n2oPage, regions, containers);
    }
    Element regionsElem = root.getChild("regions", namespace);
    if (regionsElem != null) {
        readRegions(n2oPage, regions, regionsElem);
    }
    n2oPage.setRegions(regions.toArray(new N2oRegion[regions.size()]));
    n2oPage.setModalWidth(ReaderJdomUtil.getElementString(root, "modal-width"));
    n2oPage.setMinModalWidth(ReaderJdomUtil.getElementString(root, "modal-min-width"));
    n2oPage.setMaxModalWidth(ReaderJdomUtil.getElementString(root, "modal-max-width"));
    return n2oPage;
}
 
Example #10
Source File: MCRMetaHistoryDate.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method reads the XML input stream part from a DOM part for the
 * metadata of the document.
 * 
 * @param element
 *            a relevant JDOM element for the metadata
 */
@Override
public void setFromDOM(Element element) {
    super.setFromDOM(element);
    texts.clear(); // clear

    for (Element textElement : element.getChildren("text")) {
        String text = textElement.getText();
        String lang = textElement.getAttributeValue("lang", Namespace.XML_NAMESPACE);
        if (lang != null) {
            setText(text, lang);
        } else {
            setText(text);
        }
    }
    setCalendar(element.getChildTextTrim("calendar"));
    setVonDate(element.getChildTextTrim("von"), calendar);
    setBisDate(element.getChildTextTrim("bis"), calendar);
    /** 
     * If dates higher than 1582 and calendar is Julian the calendar must switch to 
     * Gregorian cause the date transforming is implicit in the calendar methods. In
     * other cases before 1582 both calendar are equal.
     * */
    if (calendar.equals(MCRCalendar.TAG_JULIAN)) {
        calendar = MCRCalendar.TAG_GREGORIAN;
    }
}
 
Example #11
Source File: N2oRadioButtonsPersister.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Element persist(N2oRadioButtons control, Namespace namespace) {
    Element element = new Element(getElementName(), namespacePrefix, namespaceUri);
    PersisterJdomUtil.setAttribute(element, "color-field-id", control.getColorFieldId());
    setControl(element, control);
    setField(element, control);
    setListField(element, control);
    setListQuery(element, control);
    element.setAttribute("data-toggle", "buttons-radio");
    setOptionsList(element, control.getOptions());
    return element;
}
 
Example #12
Source File: N2oTextAreaPersister.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
public Element persist(N2oTextArea textArea, Namespace namespace) {
    Element textAreaElement = new Element(getElementName(), getNamespacePrefix(), getNamespaceUri());
    setControl(textAreaElement, textArea);
    setField(textAreaElement, textArea);
    setText(textAreaElement, textArea);
    return textAreaElement;
}
 
Example #13
Source File: SpringInvocationPersister.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Element persist(SpringInvocation entity, Namespace namespace) {
    Element root = super.persist(entity,namespace);
    Element spring = setElement(root, "spring");
    setAttribute(spring, "bean", entity.getBeanId());
    return root;
}
 
Example #14
Source File: DataSchemaBuilder.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String completeSchema(Document doc) {

        // add all the namespaces referred to in the schema to the root element
        for (Namespace ns : _nsList.values()) {
            doc.getRootElement().addNamespaceDeclaration(ns);
        }

        return JDOMUtil.documentToString(doc);
    }
 
Example #15
Source File: N2oSelectTreeXmlReaderV1.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@Override
public N2oSelectTree read(Element element, Namespace namespace) {
    N2oSelectTree selectTree = new N2oSelectTree();
    getControlFieldDefinition(element, selectTree);
    getTreeDefinition(element, namespace, selectTree);
    return selectTree;
}
 
Example #16
Source File: MCRURIResolver.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Source resolve(String href, String base) throws TransformerException {
    String target = href.substring(href.indexOf(":") + 1);

    try {
        return MCRURIResolver.instance().resolve(target, base);
    } catch (Exception ex) {
        LOGGER.debug("Caught {}. Put it into XML to process in XSL!", ex.getClass().getName());
        Element exception = new Element("exception");
        Element message = new Element("message");
        Element stacktraceElement = new Element("stacktrace");

        stacktraceElement.setAttribute("space", "preserve", Namespace.XML_NAMESPACE);

        exception.addContent(message);
        exception.addContent(stacktraceElement);

        message.setText(ex.getMessage());

        try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) {
            ex.printStackTrace(pw);
            stacktraceElement.setText(pw.toString());
        } catch (IOException e) {
            throw new MCRException("Error while writing Exception to String!", e);
        }

        return new JDOMSource(exception);
    }
}
 
Example #17
Source File: WildFlyCamelConfigPlugin.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private static void addProperty(Element systemProperties, Map<String, Element> propertiesByName, String name, String value) {
    Namespace namespace = systemProperties.getNamespace();
    if (!propertiesByName.containsKey(name)) {
        systemProperties.addContent(new Text("   "));
        systemProperties.addContent(new Element("property", namespace).setAttribute("name", name).setAttribute("value", value));
        systemProperties.addContent(new Text("\n    "));
    }
}
 
Example #18
Source File: N2oCheckboxButtonsPersister.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Element persist(N2oCheckboxButtons control, Namespace namespace) {
    Element element = new Element(getElementName(), namespacePrefix, namespaceUri);
    PersisterJdomUtil.setAttribute(element, "color-field-id", control.getColorFieldId());
    element.setAttribute("data-toggle", "buttons-checkbox");
    setControl(element, control);
    setField(element, control);
    setListField(element, control);
    setListQuery(element, control);
    setOptionsList(element, control.getOptions());
    return element;
}
 
Example #19
Source File: OpenPagePersister.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Element persist(N2oOpenPage openPage, Namespace namespaceElement) {
    Namespace namespace = Namespace.getNamespace(namespacePrefix, namespaceUri);
    Element root = new Element(getElementName(), namespace);
    persistOpenPage(openPage, root, namespace);
    super.persistShowModalPage(openPage, root, namespace);
    return root;
}
 
Example #20
Source File: MCRXMLHelper.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
private static String getCononicalizedPrefix(Namespace namespace) {
    return MCRConstants
        .getStandardNamespaces()
        .parallelStream()
        .filter(namespace::equals)
        .findAny()
        .map(Namespace::getPrefix)
        .orElse(namespace.getPrefix());
}
 
Example #21
Source File: MCRRestAPIClassifications.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * output children in JSON format used as input for a jsTree
 *
 * @param eParent - the parent xml element
 * @param writer - the JSON writer
 * @param lang - the language to be filtered or null if all languages should be displayed
 * @param opened - true, if all leaf nodes should be displayed
 * @param disabled - true, if all nodes should be disabled
 * @param selected - true, if all node should be selected
 *
 * @throws IOException
 */
private static void writeChildrenAsJSONJSTree(Element eParent, JsonWriter writer, String lang, boolean opened,
    boolean disabled, boolean selected) throws IOException {
    writer.beginArray();
    for (Element e : eParent.getChildren("category")) {
        writer.beginObject();
        writer.name("id").value(e.getAttributeValue("ID"));
        for (Element eLabel : e.getChildren("label")) {
            if (lang == null || lang.equals(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE))) {
                writer.name("text").value(eLabel.getAttributeValue("text"));
            }
        }
        if (opened || disabled || selected) {
            writer.name("state");
            writer.beginObject();
            if (opened) {
                writer.name("opened").value(true);
            }
            if (disabled) {
                writer.name("disabled").value(true);
            }
            if (selected) {
                writer.name("selected").value(true);
            }
            writer.endObject();
        }
        if (e.getChildren("category").size() > 0) {
            writer.name("children");
            writeChildrenAsJSONJSTree(e, writer, lang, opened, disabled, selected);
        }
        writer.endObject();
    }
    writer.endArray();
}
 
Example #22
Source File: DataSchemaBuilder.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructs a data schema for a single variable name and data type
 * @param rootName the name to give to the root element
 * @param varName the name to give to the data element
 * @param dataType the datatype for the data element
 * @return a schema for the datatype that variables of the name supplied can be
 * validated against
 */
public String buildSchema(String rootName, String varName, String dataType) {
    Namespace defNS = getDefaultNamespace();

    // create a new schema doc preamble (down to first sequence element)
    Element sequence = createPreamble(rootName, defNS);

    // build an appropriate element for the data type
    sequence.addContent(createDataTypeElement(varName, dataType, defNS));

    return completeSchema(sequence.getDocument());
}
 
Example #23
Source File: N2oDebugPersister.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Element persist(N2oDebug control, Namespace namespace) {
    Element element = PersisterJdomUtil.setElement(getElementName(), namespacePrefix, namespaceUri);
    setControl(element, control);
    setField(element, control);
    return element;
}
 
Example #24
Source File: SimpleMenuPersister.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Persist separate menu based on external namespace
 *
 * @param menu      simple menu
 * @param namespace external namespace
 * @return menu element
 */
public Element persistSeparateMenu(N2oSimpleMenu menu, Namespace namespace) {
    Element menuElement = new Element("menu", namespace);
    String refId = menu.getRefId();
    if (refId != null) setAttribute(menuElement, "ref-id", menu.getRefId());
    setAttribute(menuElement, "src", menu.getSrc());
    setChildren(menuElement, menu.getMenuItems(),
            new SubMenuItemPersister(namespace));
    return menuElement;
}
 
Example #25
Source File: PodcastService.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
private String getITunesAttribute(Element element, String childName, String attributeName) {
    for (Namespace ns : ITUNES_NAMESPACES) {
        Element elem = element.getChild(childName, ns);
        if (elem != null) {
            return StringUtils.trimToNull(elem.getAttributeValue(attributeName));
        }
    }
    return null;
}
 
Example #26
Source File: WizardXmlPersister.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Element getWidget(N2oWizard n2o, Namespace namespace) {
    Element element = new Element(getElementName(), namespace);
    persistWidget(element, n2o, namespace);
    NamespacePersister fieldSetPersister = persisterFactory.produce(N2oFieldSet.class, namespace);
    PersisterJdomUtil.setChildren(element, "steps", "step", n2o.getSteps(), (s, n) -> {
        Element step = new Element("step", n.getURI());
        PersisterJdomUtil.setAttribute(step, "name", s.getName());
        PersisterJdomUtil.setAttribute(step, "description", s.getDescription());
        PersisterJdomUtil.setAttribute(step, "icon", s.getIcon());
        PersisterJdomUtil.setAttribute(step, "condition", s.getCondition());
        PersisterJdomUtil.setAttribute(step, "next-action-id", s.getNextActionId());
        PersisterJdomUtil.setAttribute(step, "next-label", s.getNextLabel());
        PersisterJdomUtil.setChildren(step, s.getFieldSets(), fieldSetPersister);
        return step;
    });
    PersisterJdomUtil.setChild(element, "finish", n2o.getFinish(), (f, n) -> {
        Element finish = new Element("finish", n.getURI());
        PersisterJdomUtil.setAttribute(finish, "name", f.getName());
        PersisterJdomUtil.setAttribute(finish, "finish-label", f.getFinishLabel());
        PersisterJdomUtil.setAttribute(finish, "finish-action-id", f.getActionId());
        PersisterJdomUtil.setChildren(finish, f.getFieldSets(), fieldSetPersister);
        return finish;
    });

    return element;
}
 
Example #27
Source File: LyricsService.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
private LyricsInfo parseSearchResult(String xml) throws Exception {
    SAXBuilder builder = createSAXBuilder();
    Document document = builder.build(new StringReader(xml));

    Element root = document.getRootElement();
    Namespace ns = root.getNamespace();

    String lyric = StringUtils.trimToNull(root.getChildText("Lyric", ns));
    String song = root.getChildText("LyricSong", ns);
    String artist = root.getChildText("LyricArtist", ns);

    return new LyricsInfo(lyric, artist, song);
}
 
Example #28
Source File: OfferInteraction.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void parseFamiliarTask(Element e, Namespace nsYawl) {

        // finally, get the familiar participant task
        Element eFamTask = e.getChild("familiarParticipant", nsYawl);
        if (eFamTask != null)
            _familiarParticipantTask = eFamTask.getAttributeValue("taskID");

    }
 
Example #29
Source File: NamespaceIOFactoryByMap.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@Override
public P produce(Class<T> clazz, Namespace... namespaces) {
    for (Namespace namespace : namespaces) {
        if (classes.containsKey(namespace.getURI()) && classes.get(namespace.getURI()).containsKey(clazz))
            return classes.get(namespace.getURI()).get(clazz);
    }
    return (P) persisterFactory.produce(clazz, namespaces);
}
 
Example #30
Source File: N2oOutputTextXmlReaderV1.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@Override
public N2oOutputText read(Element element, Namespace namespace) {
    N2oOutputText outputText = new N2oOutputText();
    getControlFieldDefinition(element, outputText);
    outputText.setType(getAttributeEnum(element, "type", IconType.class));
    outputText.setIcon(getAttributeString(element, "icon"));
    outputText.setPosition(getAttributeEnum(element, "position", Position.class));
    return outputText;
}