org.jaxen.JaxenException Java Examples

The following examples show how to use org.jaxen.JaxenException. 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: PubchemParser.java    From act with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initializes a PubchemParser.  Must be called before the PubchemParser can be used.
 * @throws XPathExpressionException
 * @throws ParserConfigurationException
 */
public void init() throws ParserConfigurationException, JaxenException {
  // Would rather do this in its own block, but have to handle the XPath exception. :(
  for (PC_XPATHS x : PC_XPATHS.values()) {
    xpaths.put(x, x.compile());
  }

  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  documentBuilder = factory.newDocumentBuilder();

  xmlInputFactory = XMLInputFactory.newInstance();

  /* Configure the XMLInputFactory to return event streams that coalesce consecutive character events.  Without this
   * we can end up with malformed names and InChIs, as XPath will only fetch the first text node if there are several
   * text children under one parent. */
  xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, ENABLE_XML_STREAM_TEXT_COALESCING);
  if ((Boolean) xmlInputFactory.getProperty(XMLInputFactory.IS_COALESCING)) {
    LOGGER.info("Successfully configured XML stream to coalesce character elements.");
  } else {
    LOGGER.error("Unable to configure XML stream to coalesce character elements.");
  }
}
 
Example #2
Source File: OpenImmo_1_2_3.java    From OpenEstate-IO with Apache License 2.0 6 votes vote down vote up
/**
 * Downgrade <wohnung> elements to OpenImmo 1.2.2.
 * <p>
 * The options "APARTMENT", "FERIENWOHNUNG", "GALERIE" for the "wohnungtyp"
 * attribute of &lt;wohnung&gt; elements are not available in version 1.2.2.
 * <p>
 * Any occurence of these values is replaced by the "KEINE_ANGABE" value.
 *
 * @param doc OpenImmo document in version 1.2.3
 * @throws JaxenException if xpath evaluation failed
 */
protected void downgradeWohnungElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:wohnung[@wohnungtyp]",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        String value = StringUtils.trimToNull(node.getAttribute("wohnungtyp"));
        if ("APARTMENT".equalsIgnoreCase(value))
            node.setAttribute("wohnungtyp", "KEINE_ANGABE");
        else if ("FERIENWOHNUNG".equalsIgnoreCase(value))
            node.setAttribute("wohnungtyp", "KEINE_ANGABE");
        else if ("GALERIE".equalsIgnoreCase(value))
            node.setAttribute("wohnungtyp", "KEINE_ANGABE");
    }
}
 
Example #3
Source File: NodeServiceXPath.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Jaxen has some magic with its IdentitySet, which means that we can get different results
 * depending on whether we cache {@link ChildAssociationRef } instances or not.
 * <p>
 * So, duplicates are eliminated here before the results are returned.
 */
@SuppressWarnings("unchecked")
@Override
public List selectNodes(Object arg0) throws JaxenException
{
    if (logger.isDebugEnabled())
    {
        logger.debug("Selecting using XPath: \n" +
                "   XPath: " + this + "\n" +
                "   starting at: " + arg0);
    }
    
    List<Object> resultsWithDuplicates = super.selectNodes(arg0);
    
    Set<Object> set = new HashSet<Object>(resultsWithDuplicates);
    
    // return new list without duplicates
    List<Object> results = new ArrayList<>();
    results.addAll(set);
    
    // done
    return results;
}
 
Example #4
Source File: MCRSwapInsertTargetTest.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testSwapParameter() throws JaxenException, JDOMException {
    Element template = new MCRNodeBuilder().buildElement("parent[name='aa'][name='ab'][name='bc'][name='ac']", null,
        null);
    Document doc = new Document(template);
    MCRBinding root = new MCRBinding(doc);

    MCRRepeatBinding repeat = new MCRRepeatBinding("parent/name[contains(text(),'a')]", root, 0, 0, "build");
    assertEquals(3, repeat.getBoundNodes().size());

    repeat.bindRepeatPosition();
    repeat.bindRepeatPosition();
    assertEquals("/parent|1|build|name[contains(text(), \"a\")]",
        MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_UP));
    assertEquals("/parent|2|build|name[contains(text(), \"a\")]",
        MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_DOWN));
}
 
Example #5
Source File: MCRNodeBuilderTest.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBuildingValues() throws JaxenException, JDOMException {
    Attribute built = new MCRNodeBuilder().buildAttribute("@attribute='A \"test\"'", "ignore", null);
    assertNotNull(built);
    assertEquals("attribute", built.getName());
    assertEquals("A \"test\"", built.getValue());

    built = new MCRNodeBuilder().buildAttribute("@attribute=\"O'Brian\"", null, null);
    assertNotNull(built);
    assertEquals("attribute", built.getName());
    assertEquals("O'Brian", built.getValue());

    built = new MCRNodeBuilder().buildAttribute("@mime=\"text/plain\"", null, null);
    assertNotNull(built);
    assertEquals("mime", built.getName());
    assertEquals("text/plain", built.getValue());

    Element element = new MCRNodeBuilder().buildElement("name=\"O'Brian\"", null, null);
    assertNotNull(element);
    assertEquals("name", element.getName());
    assertEquals("O'Brian", element.getText());
}
 
Example #6
Source File: MCRChangeTrackerTest.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAddElement() throws JaxenException {
    Document doc = new Document(new MCRNodeBuilder().buildElement("document[title][title[2]]", null, null));
    MCRChangeTracker tracker = new MCRChangeTracker();

    Element title = new Element("title");
    doc.getRootElement().getChildren().add(1, title);
    assertEquals(3, doc.getRootElement().getChildren().size());
    assertTrue(doc.getRootElement().getChildren().contains(title));

    tracker.track(MCRAddedElement.added(title));
    tracker.undoChanges(doc);

    assertEquals(2, doc.getRootElement().getChildren().size());
    assertFalse(doc.getRootElement().getChildren().contains(title));
}
 
Example #7
Source File: OpenImmo_1_2_2.java    From OpenEstate-IO with Apache License 2.0 6 votes vote down vote up
/**
 * Downgrade &lt;buero_praxen&gt; elements to OpenImmo 1.2.1.
 * <p>
 * The options "BUEROZENTRUM", "LOFT_ATELIER", "PRAXISFLAECHE", "PRAXISHAUS"
 * for the "buero_typ" attribute of &lt;buero_praxen&gt; elements are not
 * available in version 1.2.1.
 * <p>
 * Any occurence of these values is replaced by the general "BUEROFLAECHE"
 * value.
 *
 * @param doc OpenImmo document in version 1.2.2
 * @throws JaxenException if xpath evaluation failed
 */
protected void downgradeBueroPraxenElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:buero_praxen[@buero_typ]",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        String value = StringUtils.trimToNull(node.getAttribute("buero_typ"));
        if ("BUEROZENTRUM".equalsIgnoreCase(value))
            node.setAttribute("buero_typ", "BUEROFLAECHE");
        else if ("LOFT_ATELIER".equalsIgnoreCase(value))
            node.setAttribute("buero_typ", "BUEROFLAECHE");
        else if ("PRAXISFLAECHE".equalsIgnoreCase(value))
            node.setAttribute("buero_typ", "BUEROFLAECHE");
        else if ("PRAXISHAUS".equalsIgnoreCase(value))
            node.setAttribute("buero_typ", "BUEROFLAECHE");
    }
}
 
Example #8
Source File: MCRChangeTrackerTest.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testRemoveElement() throws JaxenException {
    String template = "document[title][title[2][@type='main'][subTitle]][title[3]]";
    Document doc = new Document(new MCRNodeBuilder().buildElement(template, null, null));
    MCRChangeTracker tracker = new MCRChangeTracker();

    Element title = doc.getRootElement().getChildren().get(1);
    tracker.track(MCRRemoveElement.remove(title));
    assertEquals(2, doc.getRootElement().getChildren().size());
    assertFalse(doc.getRootElement().getChildren().contains(title));

    tracker.undoChanges(doc);

    assertEquals(3, doc.getRootElement().getChildren().size());
    assertEquals("main", doc.getRootElement().getChildren().get(1).getAttributeValue("type"));
    assertNotNull(doc.getRootElement().getChildren().get(1).getChild("subTitle"));
}
 
Example #9
Source File: MCRNodeBuilder.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Object buildNameStep(NameStep nameStep, String value, Parent parent) throws JaxenException {
    String name = nameStep.getLocalName();
    String prefix = nameStep.getPrefix();
    Namespace ns = prefix.isEmpty() ? Namespace.NO_NAMESPACE : MCRConstants.getStandardNamespace(prefix);

    if (nameStep.getAxis() == Axis.CHILD) {
        if (parent instanceof Document) {
            return buildPredicates(nameStep.getPredicates(), ((Document) parent).getRootElement());
        } else {
            return buildPredicates(nameStep.getPredicates(), buildElement(ns, name, value, (Element) parent));
        }
    } else if (nameStep.getAxis() == Axis.ATTRIBUTE) {
        return buildAttribute(ns, name, value, (Element) parent);
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("ignoring axis, can not be built: {} {}{}", nameStep.getAxis(),
                prefix.isEmpty() ? "" : prefix + ":", name);
        }
        return null;
    }
}
 
Example #10
Source File: MCRNodeBuilderTest.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testSimplePredicates() throws JaxenException, JDOMException {
    Element built = new MCRNodeBuilder().buildElement("element[child]", null, null);
    assertNotNull(built);
    assertEquals("element", built.getName());
    assertNotNull(built.getChild("child"));

    built = new MCRNodeBuilder().buildElement("element[child/grandchild]", null, null);
    assertNotNull(built);
    assertEquals("element", built.getName());
    assertNotNull(built.getChild("child"));
    assertNotNull(built.getChild("child").getChild("grandchild"));

    built = new MCRNodeBuilder().buildElement("parent[child1]/child2", null, null);
    assertNotNull(built);
    assertEquals("child2", built.getName());
    assertNotNull(built.getParentElement());
    assertEquals("parent", built.getParentElement().getName());
    assertNotNull(built.getParentElement().getChild("child1"));
}
 
Example #11
Source File: MCRBindingTest.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testSimpleBindings() throws JDOMException, JaxenException {
    binding = new MCRBinding("document", true, binding);
    binding = new MCRBinding("title", true, binding);
    assertEquals("title1", binding.getValue());
    binding = binding.getParent();
    binding = binding.getParent();

    binding = new MCRBinding("document/title[2]", true, binding);
    assertEquals("title2", binding.getValue());
    binding = binding.getParent();

    binding = new MCRBinding("document/title[@type='main']", true, binding);
    assertEquals("title1", binding.getValue());
    binding = binding.getParent();

    binding = new MCRBinding("document/title[@type='alternative']", true, binding);
    assertEquals("title2", binding.getValue());
    binding = binding.getParent();

    binding = new MCRBinding("document/author", true, binding);
    binding = new MCRBinding("firstName", true, binding);
    assertEquals("John", binding.getValue());
    binding = binding.getParent();
    binding = binding.getParent();
}
 
Example #12
Source File: MCRNodeBuilderTest.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBuildingAttributes() throws JaxenException, JDOMException {
    Attribute built = new MCRNodeBuilder().buildAttribute("@attribute", null, null);
    assertNotNull(built);
    assertEquals("attribute", built.getName());
    assertTrue(built.getValue().isEmpty());

    built = new MCRNodeBuilder().buildAttribute("@attribute", "value", null);
    assertNotNull(built);
    assertEquals("attribute", built.getName());
    assertEquals("value", built.getValue());

    Element parent = new Element("parent");
    built = new MCRNodeBuilder().buildAttribute("@attribute", null, parent);
    assertNotNull(built);
    assertEquals("attribute", built.getName());
    assertNotNull(built.getParent());
    assertEquals("parent", built.getParent().getName());
}
 
Example #13
Source File: AbstractChartJrxmlHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private void handleChartBackgroundColor(String chartText) throws JaxenException {
    AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:band//a:" + chartText + "//a:chart//a:reportElement");
    xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports");
    OMElement documentElement = document.getOMDocumentElement();
    List nodeList = xpathExpression.selectNodes(documentElement);
    OMElement element = (OMElement) nodeList.get(0);
    element.getAttribute(new QName("backcolor")).setAttributeValue(chart.getChartBackColor());
}
 
Example #14
Source File: MCRJaxenXPathFactoryTest.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testExternalJavaTest() throws JaxenException, JDOMException {
    assertTrue(evaluator.test("xed:call-java('org.mycore.common.xml.MCRXMLFunctions','isCurrentUserGuestUser')"));
    assertFalse(evaluator.test("xed:call-java('org.mycore.common.xml.MCRXMLFunctions','isCurrentUserSuperUser')"));
    assertFalse(
        evaluator.test("xed:call-java('org.mycore.common.xml.MCRXMLFunctions','isCurrentUserInRole','admins')"));
}
 
Example #15
Source File: TableTemplateJrxmlHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private TableReportDTO setTableOutlines() throws JaxenException {
    AXIOMXPath xpathExpression = new AXIOMXPath("//a:style//a:box//a:pen");
    xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports");
    OMElement documentElement = document.getOMDocumentElement();
    List nodeList = xpathExpression.selectNodes(documentElement);
    OMElement penElement = (OMElement) nodeList.get(0);

    tableReport.setOutLineThickness(Double.parseDouble(penElement.getAttributeValue(new QName("lineWidth"))));
    tableReport.setOutLineColor(penElement.getAttributeValue(new QName("lineColor")));

    return tableReport;
}
 
Example #16
Source File: OpenImmo_1_2_1.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Remove &lt;objektart_zusatz&gt; elements.
 * <p>
 * OpenImmo 1.2.0 does not support &lt;objektart_zusatz&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.1
 * @throws JaxenException if xpath evaluation failed
 */
protected void removeObjektartZusatzElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:objektart_zusatz",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}
 
Example #17
Source File: MCRBindingTest.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCollectorVariables() throws JDOMException, JaxenException {
    Map<String, Object> variables = new HashMap<>();
    variables.put("type", "main");

    binding = new MCRBinding("document", true, binding);
    binding.setVariables(variables);
    binding = new MCRBinding("title[@type=$type]", true, binding);
    assertTrue(binding.hasValue("title1"));
    assertEquals(1, binding.getBoundNodes().size());
}
 
Example #18
Source File: OpenImmo_1_2_0.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Downgrade &lt;mieteinnahmen_ist&gt;, &lt;mieteinnahmen_soll&gt; elements
 * to OpenImmo 1.1.
 * <p>
 * The "periode" attribute of the &lt;mieteinnahmen_ist&gt; and
 * &lt;mieteinnahmen_soll&gt; elements is not available in version 1.1.
 * <p>
 * Any occurences of these values is removed.
 * <p>
 * The numeric value within the &lt;mieteinnahmen_ist&gt; and
 * &lt;mieteinnahmen_soll&gt; elements is converted according to the value of
 * the "periode" attribute.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException if xpath evaluation failed
 */
protected void downgradeMieteinnahmenElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_ist[@periode] |" +
                    "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_soll[@periode]",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;

        String value = StringUtils.trimToNull(node.getTextContent());
        Double numericValue = null;
        try {
            numericValue = (value != null) ? DatatypeConverter.parseDouble(value) : null;
        } catch (Exception ex) {
            String tagName = node.getTagName();
            LOGGER.warn("Can't parse <" + tagName + ">" + value + "</" + tagName + "> as number!");
            LOGGER.warn("> " + ex.getLocalizedMessage(), ex);
        }

        if (numericValue != null && numericValue > 0) {
            String periode = StringUtils.trimToNull(node.getAttribute("periode"));
            if ("MONAT".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 12));
            } else if ("WOCHE".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 52));
            } else if ("TAG".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 365));
            }
        }

        node.removeAttribute("periode");
    }
}
 
Example #19
Source File: MCRNodeBuilderTest.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAlreadyExisting() throws JaxenException, JDOMException {
    Element existingChild = new MCRNodeBuilder().buildElement("parent/child", null, null);
    Element existingParent = existingChild.getParentElement();
    assertEquals(existingChild, new MCRNodeBuilder().buildNode("child", null, existingParent));

    Attribute existingAttribute = new MCRNodeBuilder().buildAttribute("parent/@attribute", null, null);
    existingParent = existingAttribute.getParent();
    Attribute resolvedAttribute = new MCRNodeBuilder().buildAttribute("@attribute", null, existingParent);
    assertEquals(existingAttribute, resolvedAttribute);
    assertEquals(existingParent, resolvedAttribute.getParent());

    Element child = new MCRNodeBuilder().buildElement("root/parent/child", null, null);
    Element root = child.getParentElement().getParentElement();
    Attribute attribute = new MCRNodeBuilder().buildAttribute("parent/child/@attribute", null, root);
    assertEquals(child, attribute.getParent());
    Element foo = new MCRNodeBuilder().buildElement("parent[child]/foo", null, root);
    assertEquals(child, foo.getParentElement().getChild("child"));

    Element parentWithChildValueX = new MCRNodeBuilder().buildElement("parent[child='X']", null, root);
    assertNotSame(child.getParentElement(), parentWithChildValueX);
    Element resolved = new MCRNodeBuilder().buildElement("parent[child='X']", null, root);
    assertEquals(parentWithChildValueX, resolved);

    child = new MCRNodeBuilder().buildElement("parent/child='X'", null, root);
    assertNotNull(child);
    assertEquals(parentWithChildValueX.getChild("child"), child);
}
 
Example #20
Source File: MCRXEditorTransformerTest.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testConditions() throws IOException, URISyntaxException, TransformerException, JDOMException,
    SAXException, JaxenException {
    MCRSessionMgr.getCurrentSession().put("switch", "on");
    MCRSessionMgr.getCurrentSession().put("case", "2");
    testTransformation("testConditions-editor.xml", "testBasicInputComponents-source.xml",
        "testConditions-transformed.xml");
}
 
Example #21
Source File: OpenImmo_1_2_4.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Downgrade &lt;wohnung&gt; elements to OpenImmo 1.2.3.
 * <p>
 * The option "ROHDACHBODEN" for the "wohnungtyp" attribute of
 * &lt;wohnung&gt; elements is not available in version 1.2.3.
 * <p>
 * Any occurence of these values is replaced by the "KEINE_ANGABE" value.
 *
 * @param doc OpenImmo document in version 1.2.4
 * @throws JaxenException if xpath evaluation failed
 */
protected void downgradeWohnungElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:wohnung[@wohnungtyp]",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        String value = StringUtils.trimToNull(node.getAttribute("wohnungtyp"));
        if ("ROHDACHBODEN".equalsIgnoreCase(value))
            node.setAttribute("wohnungtyp", "KEINE_ANGABE");
    }
}
 
Example #22
Source File: OpenImmoTransferDocument.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
@Override
public void setDocumentVersion(OpenImmoVersion version) {
    try {
        Document doc = this.getDocument();

        String currentVersion = StringUtils.trimToEmpty(XmlUtils
                .newXPath("/io:openimmo/io:uebertragung/@version", doc)
                .stringValueOf(doc));
        String[] ver = StringUtils.split(currentVersion, "/", 2);

        Element node = (Element) XmlUtils
                .newXPath("/io:openimmo/io:uebertragung", doc)
                .selectSingleNode(doc);
        if (node == null) {
            Element parentNode = (Element) XmlUtils
                    .newXPath("/io:openimmo", doc)
                    .selectSingleNode(doc);
            if (parentNode == null) {
                LOGGER.warn("Can't find an <openimmo> element in the document!");
                return;
            }
            node = doc.createElement("uebertragung");
            parentNode.insertBefore(node, parentNode.getFirstChild());
        }

        String newVersion = version.toReadableVersion();
        if (ver.length > 1) newVersion += "/" + ver[1];
        node.setAttribute("version", newVersion);
    } catch (JaxenException ex) {
        LOGGER.error("Can't evaluate XPath expression!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
    }
}
 
Example #23
Source File: XPathHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static Node selectNode(String expression, Object doc) {
	if (doc == null) return null;
	Object node = null;
	try {
		XPath xpath = new DOMXPath(expression);
		node = xpath.selectSingleNode(doc);
	} catch (JaxenException e) {
		return null;
	}
	return (Node)node;  
}
 
Example #24
Source File: MCRRepeatBinding.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
public void insert(int pos) throws JaxenException {
    if ("build".equals(method)) {
        Element parentElement = getParentElement();
        Element precedingElement = (Element) (getBoundNodes().get(pos - 1));
        int posOfPrecedingInParent = parentElement.indexOf(precedingElement);
        int targetPos = posOfPrecedingInParent + 1;
        String pathToBuild = getElementNameWithPredicates();
        Element newElement = (Element) (new MCRNodeBuilder().buildNode(pathToBuild, null, null));
        parentElement.addContent(targetPos, newElement);
        boundNodes.add(pos, newElement);
        track(MCRAddedElement.added(newElement));
    } else {
        cloneBoundElement(pos - 1);
    }
}
 
Example #25
Source File: ImmoXmlDocument.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
@Override
public ImmoXmlVersion getDocumentVersion() {
    String version;
    try {
        Document doc = this.getDocument();
        version = StringUtils.trimToNull(XmlUtils
                .newXPath("/io:immoxml/io:uebertragung/@version", doc)
                .stringValueOf(doc));
        if (version == null) {
            LOGGER.warn("Can't find version information in the XML document!");
            //System.out.println( "----------------------------" );
            //try
            //{
            //  DocumentUtils.write( doc, System.out );
            //}
            //catch (Exception ex)
            //{
            //  LOGGER.error( "Can't write XML document!" );
            //  LOGGER.error( "> " + ex.getLocalizedMessage(), ex );
            //}
            //System.out.println( "----------------------------" );
            return null;
        }
    } catch (JaxenException ex) {
        LOGGER.error("Can't evaluate XPath expression!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
        return null;
    }

    ImmoXmlVersion v = ImmoXmlVersion.detectFromString(version);
    if (v != null) return v;

    LOGGER.warn("The provided version (" + version + ") is not supported!");
    return null;
}
 
Example #26
Source File: TableStructureHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public void updateNumberOfColumns() throws JaxenException {
    AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:band//a:componentElement" +
            "//b:table//b:column");
    xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports");
    xpathExpression.addNamespace("b", "http://jasperreports.sourceforge.net/jasperreports/components");
    OMElement documentElement = document.getOMDocumentElement();
    List nodeList = xpathExpression.selectNodes(documentElement);
    int noOFColumns = tableReport.getColumns().length;
    if (noOFColumns != nodeList.size()) {
        int additionalColumns = noOFColumns - nodeList.size();
        addColumn(additionalColumns);
    }
}
 
Example #27
Source File: OpenImmo_1_2_2.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Downgrade &lt;grundstueck&gt; elements to OpenImmo 1.2.1.
 * <p>
 * The option "GEWERBEPARK" for the "grundst_typ" attribute of
 * &lt;grundstueck&gt; elements is not available in version 1.2.1.
 * <p>
 * Any occurence of these values is removed.
 *
 * @param doc OpenImmo document in version 1.2.2
 * @throws JaxenException if xpath evaluation failed
 */
protected void downgradeGrundstueckElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:grundstueck[@grundst_typ]",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        String value = StringUtils.trimToNull(node.getAttribute("grundst_typ"));
        if ("GEWERBEPARK".equalsIgnoreCase(value))
            node.removeAttribute("grundst_typ");
    }
}
 
Example #28
Source File: EventBrokerUtils.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static String extractTopicFromMessage(MessageContext mc) throws WSEventException {
    String topic = null;
    if (mc.getTo() != null && mc.getTo().getAddress() != null) {
        String toaddress = mc.getTo().getAddress();
        if (toaddress.contains("/publish/")) {
            Matcher matcher = EventingConstants.TO_ADDRESS_PATTERN.matcher(toaddress);
            if (matcher.matches()) {
                topic = matcher.group(1);
            }
        }
    }

    if ((topic == null) || (topic.trim().length() == 0)) {
        try {
            AXIOMXPath topicXPath = new AXIOMXPath(
                    "s11:Header/ns:" + EventingConstants.TOPIC_HEADER_NAME
                            + " | s12:Header/ns:" + EventingConstants.TOPIC_HEADER_NAME);
            topicXPath.addNamespace("s11", "http://schemas.xmlsoap.org/soap/envelope/");
            topicXPath.addNamespace("s12", "http://www.w3.org/2003/05/soap-envelope");
            topicXPath.addNamespace("ns", EventingConstants.TOPIC_HEADER_NS);

            OMElement topicNode = (OMElement) topicXPath.selectSingleNode(mc.getEnvelope());
            if (topicNode != null) {
                topic = topicNode.getText();
            }
        } catch (JaxenException e) {
            throw new WSEventException("can not process the xpath ", e);
        }
    }
    return topic;
}
 
Example #29
Source File: MCRXEditorTransformerTest.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBasicInputComponents() throws IOException, URISyntaxException, TransformerException, JDOMException,
    SAXException, JaxenException {
    testTransformation("testBasicInputComponents-editor.xml", null, "testBasicInputComponents-transformed1.xml");
    testTransformation("testBasicInputComponents-editor.xml", "testBasicInputComponents-source.xml",
        "testBasicInputComponents-transformed2.xml");
}
 
Example #30
Source File: AbstractJrxmlHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
protected void handleBackgroundColor() throws JaxenException {
    AXIOMXPath xpathExpression = new AXIOMXPath("//a:background//a:band//a:staticText//a:reportElement");
    xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports");
    OMElement documentElement = document.getOMDocumentElement();
    List nodeList = xpathExpression.selectNodes(documentElement);
    OMElement element = (OMElement) nodeList.get(0);
    element.getAttribute(new QName("backcolor")).setAttributeValue(report.getBackgroundColour());
}